'Rudder/Throttle Mixer for 3 Motors
'Kevin Goom, 22 December2007
'PICAXE-14M connections are:
' Leg 1 +5V
' Leg 2 (Serial in) Tie to Ground through 10K resistor (to avoid floating)
' Leg 3 (In4/ADC4) Wiper of 10K pot (mix proportion)
' Leg 4 (In3) From receiver throttle channel
' Leg 5 (In2) Tie to Ground through 10K resistor & switch to +5V
' Leg 6 (In1) From receiver rudder channel
' Leg 7 (In0/ADC0) Wiper of 10K pot (center motor proportion)
' Leg 8 (Out5) Stbd motor LED indicator
' Leg 9 (Out4) Center motor LED indicator
' Leg 10(Out3) Port motor LED indicator
' Leg 11(Out2) Center motor speed control
' Leg 12(Out1) Port motor speed control
' Leg 13(Out0) Stbd motor speed control
' Leg 14 Ground
symbol PW_Thr_null=b0 'Name the null position throttle input pulse width
symbol PW_Rud_null=b1 'Name the null position rudder input pulse width
symbol PW_Thr=w1 'Name the throttle input pulse width
symbol PW_Rud=w2 'Name the rudder input pulse width
symbol Mix_Prop=b6 'Name the mix proportion ADC signal
symbol CM_Prop=b7 'Name the center motor proportion (in reverse)
symbol PW_Port=b8 'Name output pulse to port motor
symbol PW_Stbd=b9 'Name output pulse to stbd motor
symbol PW_Ctr=b10 'Name output pulse to center motor
symbol Temp=b11
initialise:
setint %00000100,%0000100 'Set interrupt when pin2 goes high
let pins=%00111000 'Motor outputs low, indicators high
pause 250 'Wait 1/4 second initially
pulsin 3,1,PW_Thr_Null 'Read zero throttle input pulse width
pulsin 1,1,PW_Rud_Null 'Read center rudder input pulse width
if PW_Thr_Null<135 or PW_Thr_Null>165 then initialise'Go back if no valid throttle null input detected
if PW_Rud_Null<135 or PW_Rud_Null>165 then initialise'Go back if no valid rudder null input detected
readadc 4,Mix_Prop 'Read the mix proportion
readadc 0,CM_Prop 'Read the center motor proportion (for reverse operation)
pulsout 0, PW_Thr_Null 'Send null pulses to each motor
pulsout 1, PW_Thr_Null
pulsout 2, PW_Thr_Null
restart:
pulsin 3,1,PW_Thr 'Read throttle input pulse width
pulsin 1,1,PW_Rud 'Read rudder input pulse width
setfreq m8 'Speed things up for the calculations
if PW_Rud>=PW_Rud_Null then 'Temp = absolute deviation of rudder from null position
Temp=PW_Rud-PW_Rud_Null*Mix_Prop/256 'times the proportion determined by Mix_Prop
else
Temp=PW_Rud_Null-PW_Rud*Mix_Prop/256
endif
if Temp<3 then 'Add a bit of hyteresis
Temp=0
endif
if PW_Thr>=PW_Thr_null then
PW_Ctr=PW_Thr 'Forward
if PW_Rud>=PW_Rud_null then
PW_Port=PW_Thr+Temp max 190 min 110
PW_Stbd=PW_Thr-Temp max 190 min 110
else
PW_Port=PW_Thr-Temp max 190 min 110
PW_Stbd=PW_Thr+Temp max 190 min 110
endif
else 'Reverse
PW_Ctr=PW_Thr_Null-PW_Thr*CM_Prop/256
PW_Ctr=PW_Thr_Null-PW_Ctr 'Set reverse throttle to a proportion based on CM_Prop
if PW_Rud>=PW_Rud_null then
PW_Port=PW_Thr-Temp max 190 min 110
PW_Stbd=PW_Thr+Temp max 190 min 110
else
PW_Port=PW_Thr+Temp max 190 min 110
PW_Stbd=PW_Thr-Temp max 190 min 110
endif
endif
if PW_Port>=PW_Thr_Null then
High 3 'Turn on port motor forward indicator
else
Low 3 'Turn on port motor reverse indicator
endif
if PW_Stbd>=PW_Thr_Null then
High 5 'Turn on stbd motor forward indicator
else
Low 5 'Turn on stbd motor reverse indicator
endif
if PW_Ctr>=PW_Thr_Null then
High 4 'Turn on center motor forward indicator
else
Low 4 'Turn on center motor reverse indicator
endif
setfreq m4 'Slow back down for output of pulses
pulsout 0, PW_Stbd 'Send pulse to stbd motor speed controller
pulsout 1, PW_Port 'Send pulse to port motor speed controller
pulsout 2, PW_Ctr 'Send pulse to center motor speed controller
goto restart
interrupt: 'Allows re-read of ADC values and null positions
setfreq m4
pulsout 0, PW_Thr_Null 'Stop each motor
pulsout 1, PW_Thr_Null
pulsout 2, PW_Thr_Null
pause 15
if pin2=1 then interrupt 'Loop until pin3 goes low again
goto initialise
return