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

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
Spin Code (Syntax 1)
To run a Spin method in another cog, the
parameters, and a pointer to some stack space. For example:
VAR
PUB Main | X
PUB Square(XAddr)
This example shows two methods,
endlessly, then
cog, takes the value of
million cycles before it does it again. More explanation follows, but the result is that
out as 2, and the second cog, running
finally to 0 (it overflowed 32 bits), all independent of the first cog which may be checking the
value of
The
new cog, with
Square(@X)
address of the
space reserved for the new cog. When a cog is started to run Spin code, it needs some stack
space where it can store temporary data such as call stacks, parameters and intermediate
expression results. This example only requires 6 longs of stack space for proper operation
(see the “Stack Length” object in the Propeller Library for more information).
After the
method and the second is starting to run the
Page 190 · Propeller Manual v1.0
long SqStack[6]
X := 2
cognew(Square(@X), @SqStack) 'Launch square cog
<check X here>
'Square the value at XAddr
repeat
Main
long[XAddr] *= long[XAddr] ' Square value, store back
waitcnt(2_000_000 + cnt)
X
COGNEW
method declares a local variable,
or performing some other task.
, is the Spin method to run and its required parameter; in this case we pass it the
– Spin Language Reference
X
COGNEW
Main
variable. The second parameter of
command is executed, two cogs are running; the first is still running the
can monitor the results in the
, to run the
XAddr
, squares it and stores the result back into
Square
Main
Square
and
method in a separate cog.
X
'Stack space for Square cog
'Initialize X
'Loop here and check X
'Repeat the following endlessly
' Wait 2 million cycles
, that is set to 2 in its first line. Then
Square
, iteratively sets
COGNEW
Square
.
X
COGNEW
command needs the method name, its
Main
method. Despite the fact that they are
variable.
starts another cog that runs
,
@SqStack
X
to 4, 16, 256, 65536 and then
Square
COGNEW
, is the address of stack
XAddr
, being run by another
’s first parameter,
, then waits for 2
Main
X
starts a
Square
starts
Main

Related parts for 122-32000