Shop OBEX P1 Docs P2 Docs Learn Events
Up and running but have som small problems — Parallax Forums

Up and running but have som small problems

port513port513 Posts: 50
edited 2008-09-07 05:58 in Propeller 1
Trying to launch 2 cogs at the same time but only one will execute the code.

PUB Main
· coginit(1, heart.Run(17), @stack)
· coginit(2, heart.Run(4), @stack2

If I run this only cog 1 will execute it's code and if i comment out coginit(1... it will execute the code in cog 2.

Why?


/Henrik

Comments

  • Paul BakerPaul Baker Posts: 6,351
    edited 2008-09-06 08:53
    Your code is·executed·on cog 1, once you coginit(1,... you are telling this cog to reload itself with heart.Run(17).

    In general it's best to use cognew instead of coginit. It make the code more portable and prevents mistakes of overwriting cogs unintentionally. There are few instances where there's a true need for coginit.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • port513port513 Posts: 50
    edited 2008-09-06 09:45
    VAR 
      long stack[noparse][[/noparse]5], stack2[noparse][[/noparse]5] 
    OBJ 
      heart : "Heartbeat" 
    PUB Main 
      cognew(heart.Run(17), @stack) 
      cognew(heart.Run(0), @stack2)
    

    This code still only execute one or the other cog, and I really don't understand why?

    What I'm trying to do is to understand multiple cog use.


    /Henke
  • port513port513 Posts: 50
    edited 2008-09-06 10:25
    I solved this
    It seems that I always need a method in my main program that execute the objects code to get this working,
    I added this method
    PUB Run_Heart(pin)
      heart.run(pin)
    

    After that I can execute heart.run(pin) in any cog

    Isn't this pretty weird? Do I really need to create a method to launch a method?



    /Henke
  • Mike GreenMike Green Posts: 23,101
    edited 2008-09-06 14:53
    It's not weird at all. The 1st argument to COGNEW (or the 2nd argument to COGINIT) can not be a routine in another object (like heart.run). This is not documented in the current Propeller Manual. Your stacks may also be too small. I think you'll need at least 8-10 longs in the stack array.
  • port513port513 Posts: 50
    edited 2008-09-06 18:58
    It's still weird to me but now when I know I can live with it! [noparse];)[/noparse]


    /Henke
  • Paul BakerPaul Baker Posts: 6,351
    edited 2008-09-06 20:26
    The concept of how to handle the cogs will seem foriegn at first, but you'll find a point where it just clicks in your mind and it will become second nature to you.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • port513port513 Posts: 50
    edited 2008-09-07 05:58
    Paul Baker (Parallax) said...
    The concept of how to handle the cogs will seem foriegn at first, but you'll find a point where it just clicks in your mind and it will become second nature to you.

    As with everything else [noparse];)[/noparse]

    For the moment there is much play with my STDD to learn how everyting is done. I have a pretty weird project for my work there I must have 2 Propellers communicating over ETHERNET.


    /Henke
Sign In or Register to comment.