Using Multiple Cogs in PASM
I want to start using multiple cogs in assembly, but i'm not quite sure how to go about that. I've seen a lot of things about using stacks but I'm not really sure what those are used for. Here's what's not working:
CON
_clkmode = xtal1
_xinfreq = 5_000_000
PUB Main
cognew(@test_code, 0)
cognew(@test_code_two,1)
DAT
org 0
test_code
{stuff here}
fit
org 0
test_code_two
{stuff here}
fit
CON
_clkmode = xtal1
_xinfreq = 5_000_000
PUB Main
cognew(@test_code, 0)
cognew(@test_code_two,1)
DAT
org 0
test_code
{stuff here}
fit
org 0
test_code_two
{stuff here}
fit

Comments
The second parameter to cognew will end up in the par(ameter) register ($1F0). The way coginit/cognew works means that only 14 bits of this parameter can be transferred to the cog. In order to cover the 16bit address range only bits 15..2 are used. Anything else will be cut off (your 1 for the second cog will appear as 0).
here's the code:
CON
_clkmode = xtal1
_xinfreq = 5_000_000
PUB Main
cognew(@test_code, 0)
cognew(@test_code, 1)
DAT
org 0
test_code
mov dira,#256 {pin 8}
mov outa,#256
fit
org 0
test_code_two
add dira,pin9
add outa,pin9
pin9 long 512 {pin 9}
fit
As for the code, excution doesn't stop unless you tell it to. IOW after setting the relevant pin to high the cog keeps executing whatever is in memory which may have unwanted side effects (remember that a cog memory is always loaded full size regardless of actual program size). To stop execution simply add a loop or other wait command, e.g.
I note you are not using test_code_two.
Also be aware that cognew loads 512 longs into your cog no matter how long you think your program is.
So when you cognew test_code_one it also loads the following test_code_two longs. Of course the first cog then runs both codes and then runs whatever junk follows in memory.
Probably not what you want.
Put a jmp to self at the end of your test codes or have each jmp back to their start locations at the end.
CON _clkmode = xtal1 _xinfreq = 5_000_000 PUB Main coginit(0,@test_code,0) coginit(1,@test_code_two,0) DAT org 0 test_code add dira,#256 {pin 8} xor outa,#256 waitpeq $,#0 fit org 0 test_code_two add dira,pin9 add outa,pin9 waitpeq $,#0 pin9 long 512 {pin 9} fitokay, that pretty much made it work. it's written like this now:
CON _clkmode = xtal1 _xinfreq = 5_000_000 PUB Main cognew(@test_code,0) cognew(@test_code_two,0) DAT org 0 test_code add dira,#256 {pin 8} xor outa,#256 waitpeq $,#0 fit org 0 test_code_two add dira,pin9 add outa,pin9 waitpeq $,#0 pin9 long 512 {pin 9} fitHere is my code and I can not get the intended results. All eight LEDs should be on.
pub main cognew(@IOtest1,0) cognew(@IOtest2,0) dat org 0 IOtest1 mov dira, pin loop1 mov outa,out1 jmp #loop1 IOtest2 mov dira, pin loop2 mov outa,out2 jmp #loop2 pin long 000000_11111111_00000000_00000000 out1 long 000000_11000011_00000000_00000000 out2 long 000000_00111100_00000000_00000000 FITpub main cognew(@IOtest1,0) cognew(@IOtest2,0) DAT org 0 IOtest1 mov dira, :pin :loop1 mov outa, :out1 jmp #:loop1 :pin long %00000000_11111111_00000000_00000000 :out1 long %00000000_11000011_00000000_00000000 fit DAT org 0 IOtest2 mov dira, :pin :loop2 mov outa, :out2 jmp #:loop2 :pin long %00000000_11111111_00000000_00000000 :out2 long %00000000_00111100_00000000_00000000 fitIn your example IOtest2 is assembled for cog location 3 but loaded at 0 which more often than not goes wrong.I very much appreciate your help.
Turbosupra, I have been away from the prop for a while and I'm re-learning the program.
I agree that objects are a great way to build a program.
Thanks again for your help.
Best regards.