marzan
Senior Member
Hello. I have been working on a project to remotely adjust the height of agility poles. I now have some prototypes working. The motors that drive them are twin shaft motors. on one side there is a gearbox geared to turn a 10 turn pot which is used as a voltage divider. the other shaft is geared down to give decent torque and turn a threaded rod. As the gearboxes are run from the same motor the voltage divider can be used to check the height setting of the jump. the motor is run from a driver module by 2 pins one that enables/PWM the motor and a direction pin. The wireless module is hooked up through another voltage divider so I need only to use 1 ADC pin rather than 4 pins.
I am using a 4 button remote, but I needed 6 positions. I have written the code so that you press button A for the lower 3 heights, and button B for the 3 higher heights. then you press the buttons again to select the height. So the sequence is:
A,A 100mm
A,B 200mm
A,C 300mm
B,A 400mm
B,B 500mm
B,C 600mm
D returns to the first menu.
Everything works good, but I need to squeeze some more code in to check weather the shaft has jammed but there is not much space left. I am using 08M`s because I have quite a few of them (thanks SABorn) and as I need 40 of them it was a cheap option.
Here is the code:
Can anyone suggest any improvements to save space ?
Thanks in advance
Marz.
I am using a 4 button remote, but I needed 6 positions. I have written the code so that you press button A for the lower 3 heights, and button B for the 3 higher heights. then you press the buttons again to select the height. So the sequence is:
A,A 100mm
A,B 200mm
A,C 300mm
B,A 400mm
B,B 500mm
B,C 600mm
D returns to the first menu.
Everything works good, but I need to squeeze some more code in to check weather the shaft has jammed but there is not much space left. I am using 08M`s because I have quite a few of them (thanks SABorn) and as I need 40 of them it was a cheap option.
Here is the code:
Code:
; PICAXE 08M
;************************************************************
symbol enable = c.2 ;start motor movement and PWM
symbol direction = c.0 ;forward/reverse selection
symbol respot = c.1 ;ADC 1 Trimpot input to check position
symbol signalin = c.4 ;wireless in
symbol heightval = b1 ;which button was pressed
symbol hcheck = b2 ;check position of rotary resistor pot
symbol heightapproach = b4 ;when approching correct position use PWM to slow down motor
main: ;Select bottom or top 3 heights
b0 = 0
heightval = 0
pause 250
do
readadc 4,b0
select case b0
case > 80 goto lowerheight
case > 55 goto upperheight
case > 25 goto upperheight
case > 15 goto main
endselect
loop
lowerheight: ; Select which of the bottom 3 heights
pause 400
b0 = 0
heightval = 0
pause 250
do
readadc 4,b0
select case b0
case > 80 heightval = 245 :goto heightmove
case > 55 heightval = 203 :goto heightmove
case > 25 heightval = 154 :goto heightmove
case > 15 goto main
endselect
loop
upperheight: ; Select which of the top 3 heighs
wait 1pause 400
b0 = 0
heightval = 0
pause 250
do
readadc 4,b0
select case b0
case > 80 heightval = 96 :goto heightmove
case > 55 heightval = 44 :goto heightmove
case > 25 heightval = 10 :goto heightmove
case > 15 goto main
endselect
loop
heightmove: ; Check weather to go up or down
readadc 1,hcheck
if hcheck < heightval then low direction : goto go_up
else high direction : goto go_down
endif
Go_up:
heightapproach = heightval - 4 ; Slow down motors with PWM to prevent overrun
high enable
do
readadc 1, hcheck
loop until hcheck > heightapproach
pwmout C.2, 49, 139
do
readadc 1, hcheck
loop until hcheck >= heightval
pwmout C.2, 0, 0
low enable
goto main
Go_down:
heightapproach = heightval + 8 ; Slow down motors with PWM to prevent overrun
high enable
do
readadc 1, hcheck
loop until hcheck < heightapproach
pwmout C.2, 49, 169
do
readadc 1, hcheck
loop until hcheck <= heightval
pwmout C.2, 0 , 0
low enable
goto main
Thanks in advance
Marz.