PASM: Are cognew 's the cause of this delay?
RonP
Posts: 384
Hello All,
I just finished potatoheads Assembly for Beginners great stuff BTW. Thanks potatohead.
I ran the code below in GEAR, I noticed that P17 was a little behind P16. I originally thought it was due to clock cycles but then remember they are running in 2 cogs so they should be parallel. So now I assume the delay comes from the time it takes cog0's main method to start the second cog. Is this assumption correct?
Trying to better understand my hardware as suggested.
Thanks
Ron
I just finished potatoheads Assembly for Beginners great stuff BTW. Thanks potatohead.
I ran the code below in GEAR, I noticed that P17 was a little behind P16. I originally thought it was due to clock cycles but then remember they are running in 2 cogs so they should be parallel. So now I assume the delay comes from the time it takes cog0's main method to start the second cog. Is this assumption correct?
Trying to better understand my hardware as suggested.
'From Page 340 of the Propeller Manual 'With some small edits, for this purpose! 'Potatoheads Beginner PASM 'Ran in GEAR {{ ____ ____ P16 ___| |____| |_____ ____ ____ P17 ______| |____| |__ }} CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 PUB Main {Lanch cog to toggle P16 endlessly} cognew(@Toggle, 0) 'Launch new cog / cog0 launces 2 cogs then shuts itself down cognew(@Toggle1, 0) 'Launch another new cog DAT '---------[ Toggle P16 ]------------------------------------------------------- org 0 'Begin at Cog RAM addr 0 Toggle mov dira, Pin 'Set Pin to output mov Time, cnt 'Calculate delay time add Time, #$78 'Set initial delay here $f = 15 :loop waitcnt Time, Delay 'Wait xor outa, Pin 'Toggle Pin jmp #:loop 'Loop endlessly Pin long |< 16 'Pin number Delay long 600 'clock cycles to delay Time res 1 '---------[ Toggle P17 ]------------------------------------------------------- org 0 'Begin at Cog RAM addr 0 Toggle1 mov dira, Pin 'Set Pin to output mov Time, cnt 'Calculate delay time add Time, #$f 'Set initial delay here $f = 15 :loop waitcnt Time1, Delay1 'Wait xor outa, Pin1 'Toggle Pin jmp #:loop 'Loop endlessly Pin1 long |< 17 'Pin number Delay1 long 600 'clock cycles to delay Time1 res 1
Thanks
Ron
Comments
COGNEW is still a SPIN instruction, which needs to be decoded. So the execution time makes the delay from one signal to the other. If you want to run both COGs in sync you can for example pass a start-time to both PASM routines and simply use that in a waitcnt you do before you run the existing code. Both COGs will then continue at the same time.
I will consider it my duty to get those signal lined up. We can't have them looking like that, in a parallel environment.
Ron
The parameter startDelay is passed by reference because PAR is limited to 14 bits. Variable startDelay is set to clkfreq+cnt so the cogs will wait a second before starting the toggle loop. There were various references to "Time" in Toggle1's code - I fixed them for you.
I don't know what gear will show you, but my scope shows two perfectly synchronized square waves with 600 cycle delay. I'm glad you could learn something from Potatohead's very nice tutorial.
You are welcome, and thanks for the feedback. It's valuable. I think I'll make some edits to that portion and fold those into the current effort.
Doug