Shop OBEX P1 Docs P2 Docs Learn Events
am i doing "cogstop" correctly? — Parallax Forums

am i doing "cogstop" correctly?

mikeamikea Posts: 283
edited 2012-04-06 06:28 in Propeller 1
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)
  

Comments

  • average joeaverage joe Posts: 795
    edited 2012-04-06 06:09
    {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.Heater. Posts: 21,230
    edited 2012-04-06 06:12
    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.
  • mikeamikea Posts: 283
    edited 2012-04-06 06:28
    it works! thank you
Sign In or Register to comment.