More than one cog with diferent objects
HED GROUP
Posts: 15
{{
Hi to everybody can somebody explain us why if we use more than one cog
and call a enless method in the same program the program continue and
cog 2 and 3 blinks led 16 and 23 with led 18 on.
But if you run the same program using the same method but from a
diferent object the first cog2 run and blink led 16 but the program
stay in that enless method and don't continue with the next instruction.
Is like never return to cog 0 when the cog 2 run it's method.
}}
CON
· _clkmode = xtal1+pll16x
· _xinfreq = 5_000_000
VAR
· LONG· cog2ram[noparse][[/noparse]64]
· LONG· cog3ram[noparse][[/noparse]64]
OBJ
· lcd : "TEST1"
PUB Init
COGINIT(2,LCD.P2,@COG2ram)
COGINIT(3,LCD.P3,@COG3ram)
Init1
PUB Init1
DIRa[noparse][[/noparse]18]~~
REPEAT
·OUTa[noparse][[/noparse]18] := 1
{{===============================================
· COPY ALSO THE FOLLOWING METHODS TO "TEST1" FILE
· ===============================================
}}
··
PUB P2
REPEAT
·DIRa[noparse][[/noparse]16]~~
·!OUTa[noparse][[/noparse]16]
·waitcnt(clkfreq + cnt)
···
PUB P3
REPEAT
·DIRa[noparse][[/noparse]23]~~
·!OUTa[noparse][[/noparse]23]
·waitcnt(clkfreq + cnt)
·
Hi to everybody can somebody explain us why if we use more than one cog
and call a enless method in the same program the program continue and
cog 2 and 3 blinks led 16 and 23 with led 18 on.
But if you run the same program using the same method but from a
diferent object the first cog2 run and blink led 16 but the program
stay in that enless method and don't continue with the next instruction.
Is like never return to cog 0 when the cog 2 run it's method.
}}
CON
· _clkmode = xtal1+pll16x
· _xinfreq = 5_000_000
VAR
· LONG· cog2ram[noparse][[/noparse]64]
· LONG· cog3ram[noparse][[/noparse]64]
OBJ
· lcd : "TEST1"
PUB Init
COGINIT(2,LCD.P2,@COG2ram)
COGINIT(3,LCD.P3,@COG3ram)
Init1
PUB Init1
DIRa[noparse][[/noparse]18]~~
REPEAT
·OUTa[noparse][[/noparse]18] := 1
{{===============================================
· COPY ALSO THE FOLLOWING METHODS TO "TEST1" FILE
· ===============================================
}}
··
PUB P2
REPEAT
·DIRa[noparse][[/noparse]16]~~
·!OUTa[noparse][[/noparse]16]
·waitcnt(clkfreq + cnt)
···
PUB P3
REPEAT
·DIRa[noparse][[/noparse]23]~~
·!OUTa[noparse][[/noparse]23]
·waitcnt(clkfreq + cnt)
·
Comments
So if you move the Init methode to the LCD object (without the init1 call), and call LCD.init in the init1 methode of
the Top object, it shold work.
Andy
The object(s) that you are calling must supply the stack space it intends to use instead of the top level program assigning the stack space; this is a mandate unless the objects are within the top level program.·I have attached a sample program to illustrate a blinking LED on 16, and 23; which is similar to your program. If you wanted to change the program to use coginit instead of cognew, you would be able identify which cog is doing what; however you could also do that with an ID that is sent as the result.
I hope this helps, and feel free to use the sample within your own program.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Respectfully,
Joshua Donelson
www.parallax.com