avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [avr-gcc-list] Using delay functions with variable F_CPU clock?


From: Weddington, Eric
Subject: RE: [avr-gcc-list] Using delay functions with variable F_CPU clock?
Date: Wed, 4 Mar 2009 15:03:35 -0700

 

> -----Original Message-----
> From: 
> address@hidden 
> [mailto:address@hidden
> org] On Behalf Of David Kelly
> Sent: Wednesday, March 04, 2009 2:59 PM
> To: David VanHorn
> Cc: AVR-GCC
> Subject: Re: [avr-gcc-list] Using delay functions with 
> variable F_CPU clock?
> 
> On Wed, Mar 04, 2009 at 04:37:22PM -0500, David VanHorn wrote:
> > >
> > > F_CPU is always evaluated upon each invocation, so if you ever
> > > change it within one compilation unit, the next 
> invocation of one of
> > > these macros will reflect this.
> > >
> > That's compile-time, he's looking for execution-time changes in
> > processor speed.
> > He didn't explicitly say so, but I think he's using xdiv to 
> scale the
> > CPU clock.
> 
> But doesn't say clock is infinitely variable. Most likely 
> there are two
> frequencies he's running but this is expandable:
> 
>       if( frequency == LOW_KHZ ) {
> #define SAVED_F_CPU F_CPU
> #undef F_CPU
> #define F_CPU LOW_KHZ
>               _delay_us(us);
> #undef F_CPU
> #define F_CPU SAVED_F_CPU
> #undef SAVED_F_CPU
>       } else {
>               do_delay(us);
>       }

Sure that's possible. But the if statement is going to add some extra cycles 
that needs to be accounted for in the delay (unless the delay is so long that 
it's in the noise).




reply via email to

[Prev in Thread] Current Thread [Next in Thread]