Propeller Manual

Table Of Contents
CNT – Spin Language Reference
Page 74 · Propeller Manual v1.1
PUB Toggle | TimeBase, OneMS
dira[0]~~ 'Set P0 to output
OneMS := clkfreq / 1000 'Calculate cycles per 1 millisecond
TimeBase := cnt 'Get current count
repeat 'Loop endlessly
waitcnt(TimeBase += OneMS) ' Wait to start of next millisecond
!outa[0] ' Toggle P0
Here, I/O pin 0 is set to output. Then the local variable OneMS is set equal to the current
System Clock frequency divided by 1000; i.e., the number of System Clock cycles per 1
millisecond of time. Next, the local variable
TimeBase is set to the current System Counter
value. Finally, the last two lines of code repeat endlessly; each time waiting until the start of
the next millisecond and then toggling the state of P0.
For more information, see the
WAITCNT section’s Fixed Delays on page 218 and Synchronized
Delays on page 219.
The CNT register is read-only so in Spin it should not be assigned a value (i.e., should not be
to the left of a := or other assignment operator) and when used in Propeller Assembly it
should only be accessed as a source (s-field) value (i.e.,
mov dest, source).