triton82354
Member
Not sure how to correct this error in the following code (stack error more nested gosubs than stack allows)......any suggestions
Code:
main: Symbol cycle = b50
Symbol rsteps = b49
Symbol lsteps = b48
Symbol pin1 = 1
Symbol pin2 = 2
do
if pinc.1 = 1 then 'move stepper left
pause 2000
gosub moveleft
endif
if pinc.2 = 1 then 'move stepper right
pause 2000
gosub moveright
endif
if pinc.3 = 1 then 'teach mode left
pause 1000
b0=0
gosub teachleft
endif
if pinc.4 = 1 then 'teach mode right
pause 1000
b0=0
gosub teachright
endif
loop
moveleft:
pause 1000
b1 = b1 + 1 & %00000011
let b0 = b0 + 1
if b0 < 5 then moveleft 'step multiplier for gear ratio
b0=0
return
moveright:
pause 1000
b1 = b1 - 1 & %00000011
let b0 = b0 + 1
if b0 < 5 then moveright 'step multiplier for gear ratio
b0=0
return
teachleft:
do
IF pinc.1 = 1 THEN
b1 = b1 + 1 & %00000011
let b0 = b0 + 1
if b0<5 then teachleft 'step multiplier for gear ratio
lsteps=lsteps+1
ELSEIF pinc.5 = 1 THEN
gosub writeleft
ELSE
pinc.1 = 0
ENDIF
loop
teachright:
do
IF pinc.2 = 1 THEN
b1 = b1 + 1 & %00000011
let b0 = b0 + 1
if b0<5 then teachright 'step multiplier for gear ratio
rsteps=rsteps+1
ELSEIF pinc.5 = 1 THEN
gosub writeright
ELSE
pinc.2 = 0
ENDIF
loop
writeleft:rsteps=2
write cycle,pin1,lsteps,rsteps
cycle= cycle+1
gosub main
writeright:lsteps=0
write cycle,pin1,lsteps,rsteps
cycle= cycle+1
gosub main
cyclestart:'code to be added
Last edited: