archerbrad700
10-19-2011, 09:24 PM
I have been troubleshooting this code for some time now but to now avail. I hate to bother the forum with this but I'm at a standstill.
The code scans 4 push-buttons and starts a new method on a specified cog hen the conditions are met. The code works only when I comment out any of the cognew, coginit, and cogstop commands. The code works if I do everything in the same cog but I as soon as I try a new cog the loop will spit out a weird symbol and stop working altogether.
PUB Main
{{Senses pins XPlus, XMinus, YPlus, YMinus logic state to control
outputs on pins XDir, XStep, YDir, YStep}}
Debug.Start(9600)
waitcnt(clkfreq/8 + cnt)
Debug.Str(String("Program is running..."))
Debug.NewLine
XCount := 50 'Set XCount variable to 50
YCount := 50 'Set YCount variable to 50
dira[XDir..XStep]~~ 'Set stepper control pins as inputs
dira[YDir..YStep]~~ 'Set stepper control pins as inputs
dira[0..3]~~ '-----Set test LED pins as inputs
dira[25..27]~~
!outa[0..3] '-----Test the LED outputs by cycling once at one Hz
!outa[25..27]
waitcnt(clkfreq/2 + cnt)
!outa[0..3]
!outa[25..27]
'End of initialization
repeat 'Loop scans input pins for current state
if (ina[XPlus] == 1) and (ina[XMinus] <> 1) and (XCount < XMAX) 'If button is depressed, without the other button being pressed and XCount is not at its max value, activate the corresponding method
'cogstop(1)
debug.str(String("Step X CW"))
debug.newline 'Corresponding method started in a new cog
'coginit(1, motorStep(CW, XStep), @Stack1)
'cognew(motorStep(CW, XStep), @Stack1)
XCount++
Debug.Dec(XCount)
Debug.NewLine
'waitcnt(clkfreq/5 + cnt)
elseif (ina[XMinus] == 1) and (ina[XPlus] <> 1) and (XCount > XMIN)
'cogstop(1)
debug.str(String("Step X CCW"))
debug.newline
'coginit(1, motorStep(CCW, XStep), @Stack1)
'cognew(motorStep(CCW, XStep), @Stack1)
XCount--
Debug.Dec(XCount)
Debug.NewLine
'waitcnt(clkfreq/5 + cnt)
if (ina[YPlus] == 1) and (ina[YMinus] <> 1) and (YCount < YMAX)
'cogstop(2)
debug.str(String("Step Y CW"))
debug.newline
'coginit(2, motorStep(CW, YStep), @Stack2)
'cognew(motorStep(CW, YStep), @Stack2)
YCount++
Debug.Dec(YCount)
Debug.NewLine
'waitcnt(clkfreq/5 + cnt)
elseif (ina[YMinus] == 1) and (ina[YPlus] <> 1) and (YCount > YMIN)
'cogstop(2)
debug.str(String("Step Y CCW"))
debug.newline
'coginit(2, motorStep(CCW, YStep), @Stack2)
'cognew(motorStep(CCW, YStep), @Stack2)
YCount--
Debug.Dec(YCount)
Debug.NewLine
'waitcnt(clkfreq/5 + cnt)
I have tried every way I could think of to start the "motorStep" method on another cog but I just can't get it to work. Thanks in advance for your help
The code scans 4 push-buttons and starts a new method on a specified cog hen the conditions are met. The code works only when I comment out any of the cognew, coginit, and cogstop commands. The code works if I do everything in the same cog but I as soon as I try a new cog the loop will spit out a weird symbol and stop working altogether.
PUB Main
{{Senses pins XPlus, XMinus, YPlus, YMinus logic state to control
outputs on pins XDir, XStep, YDir, YStep}}
Debug.Start(9600)
waitcnt(clkfreq/8 + cnt)
Debug.Str(String("Program is running..."))
Debug.NewLine
XCount := 50 'Set XCount variable to 50
YCount := 50 'Set YCount variable to 50
dira[XDir..XStep]~~ 'Set stepper control pins as inputs
dira[YDir..YStep]~~ 'Set stepper control pins as inputs
dira[0..3]~~ '-----Set test LED pins as inputs
dira[25..27]~~
!outa[0..3] '-----Test the LED outputs by cycling once at one Hz
!outa[25..27]
waitcnt(clkfreq/2 + cnt)
!outa[0..3]
!outa[25..27]
'End of initialization
repeat 'Loop scans input pins for current state
if (ina[XPlus] == 1) and (ina[XMinus] <> 1) and (XCount < XMAX) 'If button is depressed, without the other button being pressed and XCount is not at its max value, activate the corresponding method
'cogstop(1)
debug.str(String("Step X CW"))
debug.newline 'Corresponding method started in a new cog
'coginit(1, motorStep(CW, XStep), @Stack1)
'cognew(motorStep(CW, XStep), @Stack1)
XCount++
Debug.Dec(XCount)
Debug.NewLine
'waitcnt(clkfreq/5 + cnt)
elseif (ina[XMinus] == 1) and (ina[XPlus] <> 1) and (XCount > XMIN)
'cogstop(1)
debug.str(String("Step X CCW"))
debug.newline
'coginit(1, motorStep(CCW, XStep), @Stack1)
'cognew(motorStep(CCW, XStep), @Stack1)
XCount--
Debug.Dec(XCount)
Debug.NewLine
'waitcnt(clkfreq/5 + cnt)
if (ina[YPlus] == 1) and (ina[YMinus] <> 1) and (YCount < YMAX)
'cogstop(2)
debug.str(String("Step Y CW"))
debug.newline
'coginit(2, motorStep(CW, YStep), @Stack2)
'cognew(motorStep(CW, YStep), @Stack2)
YCount++
Debug.Dec(YCount)
Debug.NewLine
'waitcnt(clkfreq/5 + cnt)
elseif (ina[YMinus] == 1) and (ina[YPlus] <> 1) and (YCount > YMIN)
'cogstop(2)
debug.str(String("Step Y CCW"))
debug.newline
'coginit(2, motorStep(CCW, YStep), @Stack2)
'cognew(motorStep(CCW, YStep), @Stack2)
YCount--
Debug.Dec(YCount)
Debug.NewLine
'waitcnt(clkfreq/5 + cnt)
I have tried every way I could think of to start the "motorStep" method on another cog but I just can't get it to work. Thanks in advance for your help