Shop OBEX P1 Docs P2 Docs Learn Events
HELP with cogs — Parallax Forums

HELP with cogs

Jon MJon M Posts: 22
edited 2007-09-14 21:29 in Propeller 1
Hi Guys, firstly thanks for your help with my last thread, I've moved on a bit but stuck again...

I'm trying to use 1 method by 2 cogs.· If I only start the 1st cog, by commenting out the 2nd, all is fine and routine performs as it is supposed to.· If I try to start both cogs the 1st one stops working as it should although the cog is starting successfully I think.

The first_len and second_len is provided by the master object that calls startcogs.

VAR
· long stack[noparse][[/noparse]500]
· word e_count
· byte cl
· byte sen

PUB startcogs(first_len,second_len)
· cognew (main(1,first_len),@stack[noparse][[/noparse]0]
· cognew (main(2,second_len),@stack[noparse][[/noparse]250]

PUB main(num,length)
· dira[noparse][[/noparse]7..17] ~
· dira[noparse][[/noparse]18..25] ~~
· outa[noparse][[/noparse]18..25] ~
· if num==1
··· cl:=20
··· sen:=12
··· outa[noparse][[/noparse]24]~~················································· ' visually shows 1st cog has started
· if num==2
··· cl:=21
··· sen:=13
··· outa[noparse][[/noparse]25]~~················································· ' visually shows 2nd cog has started
· repeat
···· repeat until ina[noparse][[/noparse]sen]==0································· ' wait here for sensor to be covered
·····e_count~
···· repeat while e_count<length
······ if ina[noparse][[/noparse]14]==0
········e_count++
······· repeat until ina[noparse][[/noparse]14]==1
·····outa[noparse][[/noparse]cl]~~
···· e_count~
···· repeat while e_count<128
······ if ina[noparse][[/noparse]14]==0
······· e_count++
······· repeat while ina[noparse][[/noparse]14]==1
·····outa[noparse][[/noparse]cl]~
···· repeat until ina[noparse][[/noparse]sen]==1

Many thanks

Jon

Comments

  • EricEric Posts: 11
    edited 2007-09-13 15:36
    I'm just guessing but I think you need distinct Stack Space for each Cog.

    Regards,
    Eric
  • deSilvadeSilva Posts: 2,967
    edited 2007-09-13 18:16
    The stack is fine, but the rest of the variables are dubiously double used. Jon, do you assume that the VAR section will be doubled by a NEWCOG call? It will be not, of course!
  • Jon MJon M Posts: 22
    edited 2007-09-13 19:49
    Hi desilva,

    Oops, I assumed that the variables would be 'copied' into each cog.·If this isn't possible how can I use·the same method in 2 cogs?· both cogs do exactly the same job but use a different sensor I/P and different O/P as set by num. The·e_count·is purely a counter from an·encoder I/P.
  • Paul BakerPaul Baker Posts: 6,351
    edited 2007-09-13 20:24
    Use local variables instead of global ones, then each cog will have it's own set of variables.

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

    Parallax, Inc.
  • Jon MJon M Posts: 22
    edited 2007-09-13 20:33
    Hi Paul,

    sorry to be really thick, but how do I setup local variables can you give me a simple example

    thanks
  • Martin HebelMartin Hebel Posts: 1,239
    edited 2007-09-13 20:47
    Pub test | x, y, x

    x, y and z will be local only to the method and will require stack space to hold them.· They are long in size.

    -Martin

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    StampPlot - GUI and Plotting Software
    Southern Illinois University Carbondale, Electronic Systems Technologies
  • Jon MJon M Posts: 22
    edited 2007-09-14 10:46
    thanks for all your help guys, another problem solved!!tongue.gif
  • deSilvadeSilva Posts: 2,967
    edited 2007-09-14 21:29
    Paul Baker (Parallax) said...
    Use local variables instead of global ones, then each cog will have it's own set of variables.
    Paul was a little bit sloppy. The ROUTINE will have its own set of variables, which has nothing to do with COGs. The notion that variables "somehow" go into COGs seems to be quite common and should not be assisted...

    Post Edited (deSilva) : 9/14/2007 9:43:25 PM GMT
Sign In or Register to comment.