[Top][All Lists]

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

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

From: Bob Paddock
Subject: [avr-gcc-list] Using delay functions with variable F_CPU clock?
Date: Wed, 4 Mar 2009 10:59:48 -0500

Many of the newer AVRs, Tiny88 for example, let you dynamically change
the CPU clock
frequency.  However the AVR-LibC based delays always assume
a fixed frequency based on F_CPU.

I'll always know what frequency I'm at when I call a delay() function.

Is there a way of doing:

 _delay_us( double __us, uint32_t f_cpu )

and still have the compiler generate code that does not
invoke floating point at run time?

I could make a delay function for each clock frequency,
but that seems less than optimal.

Current function for way of example from delay.h:

_delay_us(double __us)
        uint8_t __ticks;
        double __tmp = ((F_CPU) / 3e6) * __us;
        if (__tmp < 1.0)
                __ticks = 1;
        else if (__tmp > 255)
                _delay_ms(__us / 1000.0);
                __ticks = (uint8_t)__tmp;

reply via email to

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