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

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
Figure 4-1 shows the output of our previous example, the fixed delay example. Notice how
the I/O pin P0 toggles roughly every 10 milliseconds, but not exactly? In fact, there’s a
cumulative error that makes successive state changes further and further out-of-sync in
relation to our start time, 0 ms. The delay is 10 ms in length, but the error occurs because that
delay doesn’t compensate for the length of the rest of the loop. The
WAITCNT
the 10 ms delay that
Using
error. The following example assumes we’re using a 5 MHz external crystal.
CON
PUB Toggle | Time
This code first retrieves the value of the System Counter,
loop where it waits for the System Counter to reach
pin P0 and repeats the loop again. The statement
statement; it adds the value of
executes the
Counter’s value only once, at the start of the example; that is our base time. Then we wait for
the System Counter to equal that original base time plus 50,000 and perform the actions in the
loop. Each successive iteration through the loop, we wait for the System Counter to equal
another multiple of 50,000 from the base time. This method automatically compensates for
Page 324 · Propeller Manual v1.0
_clkfreq = xtal1
_xinfreq = 5_000_000
Time := cnt
repeat
waitcnt(Time += 50_000)
!outa[0]
WAITCNT
statements each take a little time to execute, and all that extra time is in addition to
WAITCNT
– Spin Language Reference
a slightly different way, for a synchronized delay, will eliminate this timing
WAITCNT
command using that result. Notice that we retrieved the System
specified.
Figure 4-1: Fixed Delay Timing
Time
to 50,000, stores that result back into
'Set for slow crystal
'Use 5 MHz accurate crystal
'Get current system counter value
'Wait for 10 ms
'Toggle pin 0
Time += 50_000
Time
Time := cnt
+ 50,000, toggles the state of I/O
is actually an assignment
repeat, !outa[0]
, then starts the
Time
and then
repeat
and

Related parts for 122-32000