PDA

View Full Version : am i doing "cogstop" correctly?



mikea
04-06-2012, 01:42 PM
im not sure if im referencing the cogstop correctly. when i press the pushbutton it stops the green led. im guessing that it is stopping the cog that contains the command "cogstop" instead of the red led , the one im trying to reference.what am i doing wrong?



{Object_Title_and_Purpose}

CON
_clkmode = xtal1 + pll16x 'Standard clock mode * crystal frequency = 80 MHz
_xinfreq = 5_000_000
VAR
long stack[100]
pub main
dira[8]~~
dira[2]~
cognew (led,@stack)

repeat
!outa[8] 'flash green led
waitcnt(clkfreq/2+cnt)
if ina[2]==0 'if button is pushed stop red led
cogstop (led)


pub led
dira[9]~~
repeat
!outa[9] 'flash red led
waitcnt(clkfreq/2+cnt)

average joe
04-06-2012, 02:09 PM
{Object_Title_and_Purpose}

CON
_clkmode = xtal1 + pll16x 'Standard clock mode * crystal frequency = 80 MHz
_xinfreq = 5_000_000
VAR
long stack[100], c
pub main
dira[8]~~
dira[2]~
c:= cognew (led,@stack)

repeat
!outa[8] 'flash green led
waitcnt(clkfreq/2+cnt)
if ina[2]==0 'if button is pushed stop red led
cogstop (c)


pub led
dira[9]~~
repeat
!outa[9] 'flash red led
waitcnt(clkfreq/2+cnt)

That should fix it. Making c = to the cog called allows you sotp the cog with cogstop(c). Hope this helps!

Heater.
04-06-2012, 02:12 PM
cogstop works on cog specified by it's cogid so passing it the "led" function as it's parameter is not right.
Where does one get a cogs ID from? Well cognew returns the cog ID of the cog it started. So use something like

redCogId = cognew (led, @stack);

then use

cogstop(redCogId);

Check the manual for details of how this all works.

mikea
04-06-2012, 02:28 PM
it works! thank you