[Top][All Lists]
[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: |
David Kelly |
Subject: |
Re: [avr-gcc-list] Using delay functions with variable F_CPU clock? |
Date: |
Wed, 4 Mar 2009 15:59:13 -0600 |
User-agent: |
Mutt/1.4.2.3i |
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);
}
--
David Kelly N4HHE, address@hidden
========================================================================
Whom computers would destroy, they must first drive mad.