Propeller Manual

Table Of Contents
WAITCNT – Spin Language Reference
Page 218 · Propeller Manual v1.1
WAITCNT
Command: Pause a cog’s execution temporarily.
((PUB PRI))
WAITCNT ( Value )
Value is the desired 32-bit System Counter value to wait for.
Explanation
WAITCNT, “Wait for System Counter,” is one of four wait commands (T WAITCNT, WAITPEQ,
WAITPNE, and WAITVID) used to pause execution of a cog until a condition is met. WAITCNTT
pauses the cog until the global System Counter equals Value.
When executed,
WAITCNT activates special “wait” hardware in the cog that prevents the
System Clock from causing further code execution within the cog until the moment the
System Counter equals Value. The wait hardware checks the System Counter every System
Clock cycle and the cog’s power consumption is reduced by approximately 7/8 during this
time. In normal applications,
T
ths
WAITCNT may be used strategically to reduce power
consumption anywhere in the program where time is wasted waiting for low-bandwidth
events.
There are two types of delays
WAITCNT can be used for: fixed delays and synchronized delays.
Both are explained below.
Fixed Delays
Fixed delays are those that are all unrelated to one specific point in time and only serve the
purpose of pausing execution for a fixed amount of time. A fixed delay, for example, may be
used to wait for 10 milliseconds after an event occurs, before proceeding with another action.
For example:
CON
_clkfreq = xtal1 'Set for slow crystal
_xinfreq = 5_000_000 'Use 5 MHz accurate crystal
repeat
!outa[0] 'Toggle pin 0
waitcnt(50_000 + cnt) 'Wait for 10 ms