calvinsykes
Member
The circuits/diagrams i posted in this thread a while back have now been fabricated and I'm experiencing a strange problem whereby the PICAXE (a 14m) seems to 'hang' whenever it executes a servo command.
The problem was not observed when the circuit was on a breadboard, and the code has not changed since then. Also, when I wire separate sections of code, eg. a small routine that just moves the servo left-right-left-right etc. works fine. So the problem is only present when running my full program:
This 'hangs' as soon as it reaches the servo command in the startup section. If that line is commented out, the program operates correctly until it receives a command from the remote control to turn left or right, at which point it hangs again. But this, for example:
works fine. Until I copy it into the main program, when it then causes hangs. I'm guessing there's some incompatability that I am introducing, but I'll be buggered if i can work out what it is
The problem was not observed when the circuit was on a breadboard, and the code has not changed since then. Also, when I wire separate sections of code, eg. a small routine that just moves the servo left-right-left-right etc. works fine. So the problem is only present when running my full program:
Code:
init: 'more symbols
symbol servo_state_pending = b0 'variables again; how I'll determine what needs doing, quickly
symbol servo_state_current = b1'
symbol thrust_state_pending = b2'
symbol thrust_state_current = b3'
symbol lift_state_pending = b4'
symbol lift_state_current = b5'
symbol servo_pin = 1 'pin number for servo
symbol servo_middle_pos = 150 'rotation amounts for three servo positions
symbol servo_left_pos = 140'
symbol servo_right_pos = 160'
symbol rfrx_pin = 0 'pin number for incoming serial data from rf receiver
symbol baudrate = T2400_4 'rf link/serial data rate
symbol fwd_pin = 4 'pin numbers for power FETs to switch motors on and off
symbol bkwd_pin = 3'
symbol lift_pin = 2'
symbol rxled_pin = 5 'pin number for flashy light
startup: 'set some stuff up
servo_state_current = "M" 'servo should be in middle...
thrust_state_current = "O" '...thrust should be off...
lift_state_current = "O" '...and so should lift
high rxled_pin '"I've turned on!" again
pause 1000
low rxled_pin
servo servo_pin, servo_middle_pos 'actually move servo incase someone has fiddled while it was off
pause 100
listen: 'wait for transmission from controller
serin rfrx_pin, baudrate, ("data"), servo_state_pending,thrust_state_pending, lift_state_pending 'read requests from transmitter into these variables
high rxled_pin 'show something is happening
goto receive
receive: 'so what now?
if servo_state_pending != servo_state_current then 'requested servo position different from current
gosub srvo 'go and do it
endif
if thrust_state_pending != thrust_state_current then 'requested thrust different form current
gosub thrust 'go and do it
endif
if lift_state_pending != lift_state_current then 'requested lift different from current
gosub lift 'go and do it
endif
low rxled_pin 'receive done so turn light off...
goto listen 'and do it again
srvo: 'move servo around
if servo_state_pending = "L" then 'want to move to left
servo servo_pin, servo_left_pos
pause 100 'give servo a chance to move
elseif servo_state_pending = "R" then
servo servo_pin, servo_right_pos 'want to move to right
pause 100 'give servo a chance to move
elseif servo_state_pending = "M" then 'want to move to middle
servo servo_pin, servo_middle_pos
pause 100 'give servo a chance to move
endif
let servo_state_current = servo_state_pending 'update servo state memory
return 'go back to where we came from
thrust: 'alter thrust fan configuration
if thrust_state_pending = "F" then 'want to go forwards
low bkwd_pin
high fwd_pin
elseif thrust_state_pending = "R" then 'want to go backwards
low fwd_pin
high bkwd_pin
elseif thrust_state_pending = "O" then 'All stop, Cap'n
low fwd_pin
low bkwd_pin
endif
let thrust_state_current = thrust_state_pending 'update thrust state memory
return 'go back to where we came from
lift: 'alter lift fan configuration
if lift_state_pending = "I" then 'want to turn it on
high lift_pin
elseif lift_state_pending = "O" then 'want to turn it off
low lift_pin
endif
let lift_state_current = lift_state_pending 'update lift state memory
return 'go back to where we came from
Code:
main: serin 0, T2400_4, ("data"), b0
if b0 = "L" then
servo 1, 120
pause 100
else if b0 = "R" then
servo 1, 180
else
servo 1, 150
endif
Last edited: