Propeller Manual

Table Of Contents
2: Spin Language Reference – WAITCNT
the overhead time consumed by the loop statements: repeat, !outa[0] and waitcnt. The
resulting output looks like Figure 2-4.
Figure 2-4: Synchronized Delay Timing
Using the synchronized delay method, our output signal is always perfectly aligned to the
time base plus a multiple of our interval. This will work as long as the time base (an external
crystal) is accurate and the overhead in the loop does not exceed the time interval itself. Note
that we waited, with
WAITCNT, before the first toggle so that the time between the very first
toggle and the second matches that of all the rest.
Calculating Time
An object can delay a specific amount of time even if the application changes the System
Clock frequency occasionally. To do this, use
WAITCNT combined with an expression that
includes the current System Clock frequency (
CLKFREQ). For example, without you knowing
what the actual clock frequency will be for applications using your object, the following line
can be used to delay the cog for 1 millisecond; as long as the clock frequency is fast enough.
waitcnt(clkfreq / 1000 + cnt) 'delay cog 1 millisecond
For more information, see CLKFREQ on page 63.
Propeller Manual v1.1 · Page 221