PDA

View Full Version : HELP with cogs



Jon M
09-13-2007, 11: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, 11:36 PM
I'm just guessing but I think you need distinct Stack Space for each Cog.

Regards,
Eric

deSilva
09-14-2007, 02: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, 03: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, 04: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, 04: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, 04: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, 06:46 PM
thanks for all your help guys, another problem solved!!http://forums.parallax.com/images/smilies/tongue.gif

deSilva
09-15-2007, 05: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