[Top][All Lists]

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

Re: [avr-libc-dev] delay in microseconds [Was: Adding new device to LibC

From: Joerg Wunsch
Subject: Re: [avr-libc-dev] delay in microseconds [Was: Adding new device to LibC]
Date: Wed, 15 Jan 2003 18:01:25 +0100
User-agent: Mutt/1.2.5i

As E. Weddington wrote:

> Jörg, Ted, do you remember what this todo item was all about?

It is based on a remark from Marek at the end of include/avr/delay.h.

> Especially the tag about the floating point math stuff.

That just means that e. g. 15 µs * 8.0 MHz will be computed at
compile-time if done properly, so no floating-point run-time support
is needed.

> And should these delays be implemented with loops or using the
> processor's timers? Whenever I use delays I always prefer the
> latter.

include/avr/delay.h is all implemented with loops.  It is certainly
only meant for short-time delays with a well-defined tick count (or
now delay time) where you can't (or don't want) to use a hardware
timer for.  "standard count loops" like

volatile int i;

for (i = 0; i < 40000; i++)

don't have any user-guessable tick count.

The use of hardware timers is rather up to the application
implementor.  I can however provide an implementation for dynamically
configurable one-shot timers (i. e., no predefined number of timer
slots, each timer is allocated using malloc()) that should be fairly
portable.  It relies on the application calling a function
timer_tick() per each hardware timer tick, and the argument to the
"timeout()" function (which will start a new one-shot timer) is
measured in hardware timer ticks.  Timers can be cancelled before they
expire, and will execute a callback function upon expiry (which can
e. g. start a new timer if repeatable timers are desired).

I think i've already posted this implementation once here, but got no
response.  I might convert that into a doc/example subdirectory, but
i've already promised to do a doc/example/stdio first. ;-)

J"org Wunsch                                           Unix support engineer
address@hidden        http://www.interface-systems.de/~j/

reply via email to

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