Shop OBEX P1 Docs P2 Docs Learn Events
More than one cog with diferent objects — Parallax Forums

More than one cog with diferent objects

HED GROUPHED GROUP Posts: 15
edited 2009-03-05 19:23 in Propeller 1
{{
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

  • kuronekokuroneko Posts: 3,623
    edited 2009-03-04 01:48
    Explicit use of coginit() is discouraged. You should use cognew() instead. So can you please make that change and see if it resolves your problem? It looks like using the same method but from a diferent object changes the cog assignments in a way which makes it interfere with you hardcoded indexes.
  • AribaAriba Posts: 2,690
    edited 2009-03-04 06:29
    The cogs must be started in the same object, that contains the methods which you will start.
    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
  • JDJD Posts: 570
    edited 2009-03-05 19:23
    HED Group,

    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
Sign In or Register to comment.