Propeller Manual

Table Of Contents
WAITPEQ – Spin Language Reference
WAITPEQ
Command: Pause a cog’s execution until I/O pin(s) match designated state(s).
((PUB PRI))
WAITPEQ (State, Mask, Port )
State is the logic state(s) to compare the pin(s) against. It is a 32-bit value that
indicates the high or low states of up to 32 I/O pins. State is compared against either
(
INA & Mask), or (INB & Mask), depending on Port.
Mask is the desired pin(s) to monitor. Mask is a 32-bit value that contains high (1)
bits for every I/O pin that should be monitored; low (0) bits indicate pins that should
be ignored. Mask is bitwised-ANDed with the 32-bit port’s input states and the
resulting value is compared against the entire State value.
Port is a 1-bit value indicating the I/O port to monitor; 0 = Port A, 1 = Port B. Only
Port A exists on current (P8X32A) Propeller chips.
Explanation
WAITPEQ, “Wait for Pin(s) to Equal,” is one of four wait commands (WAITCNT, WAITPEQ,
WAITPNE, and WAITVID) used to pause execution of a cog until a condition is met. WAITPEQ
pauses the cog until the value of Port’s I/O pin states, bitwised-ANDed with Mask, matches
that of State.
When executed,
WAITPEQ activates special “wait” hardware in the cog that prevents the
System Clock from causing further code execution within the cog until the moment the
designated pin, or group of pins, equals the indicated state(s). The wait hardware checks the
I/O pins every System Clock cycle and the cog’s power consumption is reduced by
approximately 7/8
ths
during this time.
Using WAITPEQ
WAITPEQ is a great way to synchronize code to external events. For example:
waitpeq(%0100, %1100, 0) 'Wait for P3 & P2 to be low & high
outa[0] := 1 'Set P0 high
The above code pauses the cog until I/O pin 3 is low and I/O pin 2 is high, then sets I/O pin 0
high.
Page 222 · Propeller Manual v1.1