[<<][staapl][>>][..]
Tue Nov 11 16:13:00 CET 2008

busy loop timing

I'd like to create a busy wait macro that's relatively accurate, using
nested for loops.  Got it:

\ This is optimized for fosc from 8 -> 48.  The inner loop compensates
\ for the oscillator period.  Using a convenient period of 50us, this
\ gives 33 iterations at 8Mhz and 200 iterations at 48Mhz.  The macro
\ is exposed, but it is most accurate for +- 50 us.

macro
: usec
    fosc 4000000 / *  \ instructions per us
    3 /               \ instructions per loop
    for next ;
forth

: 50usec 50 usec ;




[Reply][About]
[<<][staapl][>>][..]