Help needed with stepper motor code

i plan to build a robotic arm which is moved using a stepper motor and a pot is used to give its posotion, it will use a 08m and the speed and set position will be sent by serial, the 08m will then turn the motor towards the setposition at the speed sent when it gets closer to the set position the 08m will slow the motor down twice, stop at the set position and send a message saying its there. The code below is just a test code for controling the motor speed and direction and is on a 28x1. The pins for the stepper might look odd but im only using 2 pins to control the stepper with a uln2003 being used to control the stepper, iv tested this and it works fine.

The problem im having is that if i turn the pot below the set position it all works fine as i turn it towards the set positon the motor slows twice and changes direction when it passes the set position, but this is where things go wrong, if i start to turn the pot up from the set position the motor turns slowly which is correct, as i continue to turn the pot up the motor the speeds up which is correct again but if i keep turning the pot up it slows down again instead of speeding up again, also there is no torque when turning unlike when turning the other way,

iv been trying to work out whats wrong for days and cant and when i simulate the code with the pic editor it seems to work fine.

any help or suggestions would be great

 

 

symbol speed = b4 ' store speed in b4
symbol setposition = w0 ' store set position in w0
symbol position = w1 ' store position in w1
symbol downstep = b5
symbol upstep = b6
let setposition = 500 ' make set position 500


main:
let speed = 1 ' start speed is 1
readadc10 2,position ' read 100k pot as position
if position > setposition then ' if pot is higher than 500 step back
goto stepdown
endif
if position < setposition then ' if pot is lower than 500 step up
goto stepup
endif
goto main


stepdown:
w5=setposition+100 ' position for slow speed 1
w6=setposition+50 ' position for slow speed 2
for downstep = 1 to 4 ' set 4 steps
lookup downstep, (0,%00000001,%00000011,%00000010,%0000000),pins ' steps for motor
readadc10 2,position ' read pot position
if position< w5 then ' slow speed if at position 1
speed = 10
endif
if position < w6 then ' slow speed if at position 2
speed = 100
endif
if position = setposition then ' goto respond if at position
goto respond
endif
if position < setposition then ' step up if gone past position
goto stepup
endif
pause speed ' set speed for next step
next downstep ' loop


stepup:
w7=setposition-100 ' position for slow speed 1
w8=setposition-50 ' position for slow speed 2
for upstep = 1 to 4 ' set 4 steps
lookup upstep, (0,%00000010,%00000011,%00000001,%00000000),pins ' steps for motor
readadc10 2,position ' read pot position
if position > w7 then ' slow speed if at position 1
speed = 10
endif
if position > w8 then ' slow speed if at position 2
speed = 100
endif
if position = setposition then ' goto respond if at position
goto respond
endif
if position > setposition then ' step down if gone past position
goto stepdown
endif
pause speed ' set speed for next step
next upstep ' loop


respond:
goto main


https://www.youtube.com/watch?v=tCzrLOnbvyw

fixed
fixed it

What was wrong?
I hadnt had a chance to look over the code yet. What was the problem?

fixed

just had to add the goto command at the end of the two sub directories, so simple and it gave me so many head aches over the past few days

 

stepdown:
w5=setposition+100 ’ position for slow speed 1
w6=setposition+50 ’ position for slow speed 2
for downstep = 1 to 4 ’ set 4 steps
lookup downstep, (0,%00000001,%00000011,%00000010,%0000000),pins ’ steps for motor
readadc10 2,position ’ read pot position
if position< w5 then ’ slow speed if at position 1
speed = 10
endif
if position < w6 then ’ slow speed if at position 2
speed = 100
endif
if position = setposition then ’ goto respond if at position
goto respond
endif
if position < setposition then ’ step up if gone past position
goto stepup
endif
pause speed ’ set speed for next step
next downstep ’ loop

goto stepdown