PDA

View Full Version : HELP with cogs



Jon M
09-13-2007, 10:25 PM
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[500]
· word e_count
· byte cl
· byte sen

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

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

Many thanks

Jon

Eric
09-13-2007, 10:36 PM
I'm just guessing but I think you need distinct Stack Space for each Cog.

Regards,
Eric

deSilva
09-14-2007, 01:16 AM
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 M
09-14-2007, 02:49 AM
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 Baker
09-14-2007, 03:24 AM
Use local variables instead of global ones, then each cog will have it's own set of variables.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker (mailto:pbaker@parallax.com)
Propeller Applications Engineer
[/url][url=http://www.parallax.com] (http://www.parallax.com)
Parallax, Inc. (http://www.parallax.com)

Jon M
09-14-2007, 03:33 AM
Hi Paul,

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

thanks

Martin Hebel
09-14-2007, 03:47 AM
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 (http://www.siu.edu/~isat/est)

Jon M
09-14-2007, 05:46 PM
thanks for all your help guys, another problem solved!!http://forums.parallax.com/images/smilies/tongue.gif

deSilva
09-15-2007, 04:29 AM
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