'Radio control servo slowdown using PICAXE-08M 'Kevin Goom, 17 October 2005 'Updated for new Picaxe S/W (changed loop to loop1, restart to restart1) ' ' 'PICAXE-08M connections are: ' Leg 1 +5V ' Leg 2 (Serial in) Tie to Ground through 10K resistor ' Leg 3 (In4/Out4) Wiper of 10K potentiometer connected to +5V & ground ' Leg 4 (In3) Pulse input from radio receiver ' Leg 5 (In2/Out2) Pulse output to servo ' Leg 6 (In1/Out1) Mode indicator output '1/2 second flash = no valid signal 'Steady on = pass-through (no servo slowdown) 'Flicker = servo slowdown mode ' Leg 7 (Out0/Serial Out) NC ' Leg 8 Ground symbol Delay=b8 'Name the delay factor symbol PWin=w0 'Name the input pulse length symbol PWout=b2 'Name the output pulse length symbol PWinPrev=b3 'Name the length of the prior input pulse length symbol PWinErr=b6 'difference between input &output pulse lengths symbol skip=b4 'counter for skipping "Delay" times restart1: Skip=0 high 1 servo 2,135 'Center the servo initially and on input pulse loss Pause 500 'Wait 1/2 second initially toggle 1 readadc 4,Delay 'Read the voltage from the delay potentiometer pulsin 3,1,PWin 'Measure the input pulse width initially if PWin<75 or PWin>225 then restart1 'Go back if no valid input detected high 1 low 2 'Stop the servo command if valid input detected PWinPrev=PWin 'Initially set the prior pulse width to current pulse width if Delay<5 then StraightThru 'If delay pot set near zero skip slowdown Delay=Delay/21 'Set 0 (1.5s stop-to-stop) to 12 (20s stop-to-stop) PWout=PWin 'Set output pulse to input pulse initially loop1: toggle 1 PWinPrev=PWin 'Reset the prior pulse width pulsin 3,1,PWin 'Measure the input pulse if PWin<75 or PWin>225 then restart1 'Go back if no valid input detected PwinErr=PWin-PWOut if PWinErr<2 or PWinErr>254 then StayPut 'Add 2 units of hysteresis if PWoutPWin then MoveDown MoveDown: 'Routine to decrease the output pulse width if skip>=Delay then Skip1 'Loop to delay change to Delay x 20ms Skip=Skip+1 goto Skip2 Skip1: Skip=0 PWout=PWout-1 Skip2: pulsout 2,PWout 'Send the output pulse to the servo goto loop1 'Return to re-measure the input pulse MoveUp: 'Routine to increase the output pulse width if skip>=Delay then Skip3 'Loop to delay change to Delay x 20ms Skip=Skip+1 goto Skip4 Skip3: Skip=0 PWout=PWout+1 Skip4: pulsout 2,PWout 'Send the output pulse to the servo goto loop1 'Return to re-measure the input pulse StayPut: 'Routine to send the same output pulse pulsout 2,PWout goto loop1 'Return to re-measure the input pulse StraightThru: pulsin 3,1,PWin if PWin<75 or PWin>225 then restart1 'Go back if no valid input detected PwinErr=PWin-PWinPrev if PWinErr<2 or PWinErr>254 then Stay 'Add 2 units of hysteresis pulsout 2,PWin PWinPrev=PWin goto StraightThru: 'Return to re-measure the input pulse Stay: pulsout 2,PWinPrev 'Set output pulse to input pulse goto StraightThru: 'Return to re-measure the input pulse