Cogs not running simultaneously
DavidZemon
Posts: 2,973
Hello all. I'm just getting started with the propeller. I'm playing around with some code right now, just familiarizing myself with the language. In my first attempt at parallel processing, I failed. The program runs, but it's running in series, not parallel. The cognew() function calls the toggle method, but the next line of code doesn't run until the first LED has flashed 5 times. Anyone see where I'm going wrong?
Here's an object, Toggle:
And here's the Top-Level file:
Here's an object, Toggle:
PUB toggle (pin, delayCnt, repetition) | x
x := clkfreq/100
dira[pin]~~
if repetition == 0
repeat
!outa[pin]
waitcnt(x*delayCnt + cnt)
else
repeat repetition*2
!outa[pin]
waitcnt(x*delayCnt + cnt)
outa[pin] := 1
And here's the Top-Level file:
{{ learning.spin File to practice my Spin }}
CON
_clkmode = xtal1
_xinfreq = 20_000_000
OBJ
pst : "Parallax Serial Terminal"
tog : "toggle"
Var
long Stack1[8]
PUB Main
cognew(tog.toggle(15, 50, 5), @Stack1) 'Have cog1 begin flashing a power LED
tog.toggle(14, 10, 10)
pst.start(9_600) 'Start serial terminal
tog.toggle(14, 10, 10)
pst.str(string("Hello world!"))

Comments
I added an example (using different pins and clock setup). Note this is not suited for multiple start calls as they would all use the same stack.
Also... this thing is awesome