Multicore problem. processes do not run parallel
ErgoBot
Posts: 4
Hello,
I want to have the two methods BlinkLEDright and BlinkLEDleft run parallel.
Unfortunatly they run in a sequence instead. First BlinkLEDleft starts, then BlinkLEDright follows once the first one has ended.
Can you please explain to me why this happens? how can I make them run parallel? Thank you very much!
VAR
long stack[100]
OBJ
blinkl: "BlinkLEDleft"
blinkr: "BlinkLEDright"
PUB komplett
coginit(2, blinkl.BlinkLEDleft, @stack[00])
coginit(3, blinkr.BlinkLEDright, @stack[50])
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
PUB BlinkLEDright
dira[0] := %11
waitcnt(clkfreq * 2 + cnt)
repeat 5
outa[0] := 1
waitcnt(clkfreq / 3 + cnt)
outa[0] := 0
waitcnt(clkfreq / 3 + cnt)
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
PUB BlinkLEDleft
dira[1] := %11
waitcnt(clkfreq * 2 + cnt)
repeat 5
outa[1] := 1
waitcnt(clkfreq / 3 + cnt)
outa[1] := 0
waitcnt(clkfreq / 3 + cnt)
I want to have the two methods BlinkLEDright and BlinkLEDleft run parallel.
Unfortunatly they run in a sequence instead. First BlinkLEDleft starts, then BlinkLEDright follows once the first one has ended.
Can you please explain to me why this happens? how can I make them run parallel? Thank you very much!
VAR
long stack[100]
OBJ
blinkl: "BlinkLEDleft"
blinkr: "BlinkLEDright"
PUB komplett
coginit(2, blinkl.BlinkLEDleft, @stack[00])
coginit(3, blinkr.BlinkLEDright, @stack[50])
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
PUB BlinkLEDright
dira[0] := %11
waitcnt(clkfreq * 2 + cnt)
repeat 5
outa[0] := 1
waitcnt(clkfreq / 3 + cnt)
outa[0] := 0
waitcnt(clkfreq / 3 + cnt)
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
PUB BlinkLEDleft
dira[1] := %11
waitcnt(clkfreq * 2 + cnt)
repeat 5
outa[1] := 1
waitcnt(clkfreq / 3 + cnt)
outa[1] := 0
waitcnt(clkfreq / 3 + cnt)
Comments
What you should do is either start two wrapper methods in the parent object to call the child methods in the context of a new cog or you move the cognew/coginit into the child objects (there is usually no need for the parent to deal with that, especially stack size & Co).
Also, code is best posted within [noparse] [/noparse] tags.
There's no need for an external file as you've shown; you can use an embedded method and even give it flexible parameters. I've done that, but matched the behavior of your original program.