HELP with cogs
Jon M
Posts: 22
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
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
Regards,
Eric
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
Propeller Applications Engineer
Parallax, Inc.
sorry to be really thick, but how do I setup local variables can you give me a simple example
thanks
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
Post Edited (deSilva) : 9/14/2007 9:43:25 PM GMT