Shop OBEX P1 Docs P2 Docs Learn Events
Can't pass global variable after cognew command — Parallax Forums

Can't pass global variable after cognew command

lardomlardom Posts: 1,659
edited 2013-01-28 21:58 in Propeller 1
My challenge is to control two steppers with IR distance detection. I designed it so that the top object initializes three cogs, one for each of the two steppers and an IR control. The idea is that the main method in the IR control (which includes two extra methods for global variables 'A' and 'B') copies the value from from the IR detector and passes it to the two global variables, 'A' and 'B'.
The left stepper then calls method 'A' and the right stepper calls method 'B' to get the corresponding value/s. The problem is that once I issue a cognew command to the IR control object I can no longer get those global values. I'm debugging with the PST using 'copy' and 'paste'. I'm stumped.
{ works with cognew command to pst }
CON
  _xinfreq = 5_000_000                      
  _clkmode = xtal1 + pll16x  
OBJ
     ir : "IrDetectorV6"
     pst : "Parallax Serial Terminal"   
VAR
  byte cogT
  long  indexA, indexB, A_Side, B_Side, stack[20]
{PUB Start : success
    Stop
    success := cogT := cognew(Main_Sensor, @stack) + 1 
PUB Stop
    If cogT 
      cogstop(cogT~ - 1)              }

PUB  Main_Sensor | dist         ' : result
      pst.StartRxTx(31, 30, 0, 115_200)      
      ir.init(26, 27, 25)
      repeat       
        dist := ir.distance
        A_Side := B_Side := dist
    '    waitcnt(clkfreq/100 + cnt)
        pst.Str(string(pst#PX, 11))
        pst.Dec(dist)
   '     waitcnt(clkfreq/3 + cnt)
  '      Foward_a 
PUB Foward_a : result          'left wheel   
    result := A_Side
    pst.Str(string(pst#PX, 11))
  '  dist := ir.Distance
    pst.Dec(result)
  '  pst.Str(string("/100", pst#CE))    
    waitcnt(clkfreq/3 + cnt)
PUB Foward_b : result          'right wheel   
    result := B_Side

Comments

  • Dave HeinDave Hein Posts: 6,347
    edited 2013-01-28 10:27
    I'm guessing that your stack is too small, but it's impossible to tell without seeing the rest of the code.
  • lardomlardom Posts: 1,659
    edited 2013-01-28 21:58
    @Dave Hein, You were right! I should be embarrassed. I actually did try increasing the stack size... except that I also made a number of other modifications and did not retest the stack after tinkering with it. I won't make that mistake again. Thank you.
Sign In or Register to comment.