Shop OBEX P1 Docs P2 Docs Learn Events
Multiple Cogs, Single PUB — Parallax Forums

Multiple Cogs, Single PUB

oliver_man_77oliver_man_77 Posts: 7
edited 2008-10-22 23:27 in Propeller 1
Is it possible to have multiple cogs run the same PUB or do I need to creat a seprate PUB for each cog? I am wanting to run a proscess with two inputs and 5 outputs. it is possible in my situation to have the proscess start on a product before it completeles the proscess on a previous product. I was thinking of having a new cog control the proscess for each new product that enters.

Comments

  • RaymanRayman Posts: 14,593
    edited 2008-10-22 12:46
    The answer is "yes", if I understand the question correctly... In SPIN, you can use COGNEW several times on the same PUB proceedure. But, you must give each COG it's own STACK space...
  • oliver_man_77oliver_man_77 Posts: 7
    edited 2008-10-22 14:22
    Correct, I am write a single PUB and have it run simultaneously in multiple cogs. I just have to figure out how long my stacks need to be. I'm just trying to cheat and not have to write a bunch of code.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-10-22 17:04
    This brings up another point, which hasn't been addressed yet. If the PUB procedure uses VAR and/or DAT variables, each instance that's COGNEWed will share a single copy. This is because there's no way for the compiler to know, at compile time, how many new cogs are being spawned. If this is a problem, you will need to include the PUB procedure in a separate object and declare that object in your top-level program as an array big enough to accommodate all instances. In this case, only the DAT variables will be shared, and the compiler will allocate a separate set of VAR variables for each instance.

    -Phil

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    'Just a few PropSTICK Kit bare PCBs left!
  • oliver_man_77oliver_man_77 Posts: 7
    edited 2008-10-22 23:27
    I would say you have pretty much got this going for me. I have it running pretty much the way I want now just clean up the code and test it for any glitches. I'm thinking a really good scope should work. My encoder signal will be coming in around the neighborhood of 500KHz. I can't really afford to miss to many pulses and I'm hoping that switching between cogs doesn't effect anything. Thanks alot for helping to get me rolling.
Sign In or Register to comment.