122-32000 Parallax Inc, 122-32000 Datasheet - Page 323

MANUAL PROPELLER

122-32000

Manufacturer Part Number
122-32000
Description
MANUAL PROPELLER
Manufacturer
Parallax Inc
Datasheets

Specifications of 122-32000

Accessory Type
Manual
Lead Free Status / RoHS Status
Lead free / RoHS Compliant
For Use With/related Products
Propeller Education (PE) Kit
Lead Free Status / Rohs Status
Lead free / RoHS Compliant
This code toggles the state of I/O pin P0 and waits for 50,000 system clock cycles before
repeating the loop again. Remember, the Value parameter must be the desired 32-bit value to
match against the System Clock’s value. Since the System Clock is a global resource that
changes every clock cycle, to delay for a certain number of cycles from “now” we need a
value that is added to the current System Counter value. The
System Counter Register variable; it returns the value of the System Counter at that moment
in time. So our code says to wait for 50,000 cycles plus the current value of the System
Counter; i.e: wait 50,000 cycles from now. Assuming that an external 5 MHz crystal is being
used, 50,000 cycles is about 10 ms (1/100th second) of time.
IMPORTANT: Since
value, care must be taken to ensure that the given value was not already surpassed by the
System Counter. If the System Counter already passed the given value before the wait
hardware activated then the cog will appear to have halted permanently when, in fact, it is
waiting for the counter to exceed 32 bits and wrap around to the given value. Even at 80
MHz, it takes over 53 seconds for the 32-bit System Counter to wrap around!
Related to this, when using
Value expression the same way we did: in the form “
to right, and each intermediate evaluation within an expression takes time to perform. If
were at the start of the expression, the System Counter would be read first then the rest of the
expression would be evaluated, taking an unknown amount of cycles and making our
value quite old by the time the final result is calculated. However, having
value in the
the System Counter and activating the wait hardware. In fact, the interpreter takes 381 cycles
of final overhead when the command is written in the form
means the value of
Synchronized Delays
Synchronized delays are those that are all directly related to one specific point in time, a
“base” time, and serve the purpose of “time-aligning” future events relative to that point. A
synchronized delay, for example, may be used to output or input a signal at a specific
interval, despite the unknown amounts of overhead associated with the code itself. To
understand how this is different than the Fixed Delay example, let’s look at that example’s
timing diagram.
cnt + offset
WAITCNT
.” This is because the Spin interpreter will evaluate this expression from left
offset
expression ensures a fixed amount of overhead (cycles) between reading
WAITCNT
must always be at least 381 to avoid unexpectedly long delays.
WAITCNT
pauses the cog until the System Counter matches the given
in Spin code as shown above, make sure to write the
4: Spin Language Reference –
offset + cnt
waitcnt(offset + cnt)
Propeller Manual v1.0 · Page 323
cnt
in “
50_000 + cnt
” as opposed to
cnt
as the last
” is the
. This
cnt
cnt

Related parts for 122-32000