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

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
3: Propeller Programming Tutorial
Compile and download Blinker2. You should see six LEDs start blinking with different,
independent, rates and periods. Look carefully, after about 8 seconds P20 will stop blinking
and P22 will start. A few seconds later, P18 will stop and P23 will start, then P16 will stop
and P20 will start again, but at a different rate. Eventually, all but P17 and P20 will cease.
Can you figure out why it behaves this way? We’ll explain it below.
The OBJ Block
In the object block we defined an array of Output objects, called
, with six elements. This
LED
is so we can have six simultaneous processes running, each operating independently.
The Main Method
The first line of
,
, sets I/O pins 16 through 23 to outputs. The I/O
Main
dira[16..23]~~
registers,
,
, and
, can use this form to affect multiple contiguous pins. We are
DIRA
OUTA
INA
setting this group of I/O pins to outputs only to prevent confusing results due to the Propeller
Demo Board’s resistors between the I/O pairs in 18 to 23. If a cog is the only one making a
particular pin an output, upon shutting down that pin becomes an input again which allows
the resistor between it and its neighbor to affect the LED on it. We’ll keep this application’s
cog active so results are clear.
The next nine lines,
…, call the Output object’s
method to activate a new cog and
LED[
Start
toggle different I/O pins at different rates. The lines in the form
…,
LED[NextObject].Start
call the
method to get an index value for the array. We’ll explain the
NextObject
NextObject
method in more detail soon, but simply put, it returns the index of the next available Output
object in the
array (i.e. the index of the first idle object) and pauses until one is available.
LED
We only have six Output objects defined for the
array, so the first six calls to
are
LED
Start
going to execute quickly, each one accessing
indexes 0 through 5 and activating a total of
LED
6 additional cogs. The first two have a
parameter of 0, so they will toggle infinitely;
Count
the last four will terminate after the given number of toggles is performed.
The seventh line,
will first call
to get
LED[NextObject].Start(22, 750_000, 200)
NextObject
the index of the next available object, but since all six objects are busy toggling pins,
will wait and won’t return to
until it finds that an object has finished. As it
NextObject
Main
turns out, the object at index 4 (I/O pin 20) finishes its task first and shuts down. The
method then returns the number 4, allowing that object’s
method to
NextObject
Start
execute, which will re-launch another cog to toggle pin 22. A similar process happens with
the eighth line,
; all objects are busy so
LED[NextObject].Start(23, 400_000, 160)
postpones further operation until one becomes available, index 2 in this case.
NextObject
Immediately after the eighth line is executed, the ninth line executes,
LED[0].Start(20,
. This statement is unlike the previous in that it doesn’t call
, but
12_000_000, 0)
NextObject
Propeller Manual v1.0 · Page 125

Related parts for 122-32000