Using Multiple Cogs in PASM
tholberton
Posts: 41
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.
okay, that pretty much made it work. it's written like this now:
Here is my code and I can not get the intended results. All eight LEDs should be on.
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.