'****************************************************************************
'* Décodeur proportionnel-digital RFIN *
'* pour radiocommande 5 voies et 8 ToR *
'* PICAXE 14M2 *
'* G.TREELS 02/2014 *
'****************************************************************************
#picaxe 14M2
Setfreq m32
Symbol RX=C.3
Symbol Sens=C.4
Symbol VersTor=C.2 'Vers les ToR,deuxième 14M2 et ULN
Symbol LedSecu=C.1
Symbol Buzz=C.0
pwmout pwmdiv64, B.4, 124, 0 'init PWM, à 0
Do
ReadAdc B.5,b20
If b20>51 Then 'ADC secu I moteur
Exit 'R source=1 ohm, un ampère max
End If
Setfreq m4
RFin RX, b0,b1,b2,b3,b4,b5,b6,b7 'b5 ,6 et 7, pour du ToR, si on veut
Setfreq m32
'juste b5, ici
'Les quatres voies
w4=b0*44/10 'mise échelle, 0à 255 donne 640 à 1760
w4=w4+640 'pour 800 à 2200µs, avec pulses à 1.25µs (32 mhz)
w5=b1*44/10
w5=w5+640 'id
w6=b2*44/10
w6=w6+640 'id
w7=b3*44/10
w7=w7+640 'id
'Commande moteur, PWM ET relais av ar
w8=b4 'par cohérence pour la suite ...
Select Case w8
Case 126 To 130
w8=0 'manche au neutre
Case >130
w8=b4-130 'mise à l'échelle, pour 0 à 625 (pwm), avec 131 à 255 (b4)
w8=w8*5
Low Sens 'avant
Else
w9=5*w8 'le même à l'envers, pour 625 à 0, avec 0 à 125
w8=625-w9
High Sens 'arriere
End Select
'Les commandes
Pulsout B.0,w4 'Voie1
Pulsout B.1,w5 'Voie2
Pulsout B.2,w6 'Voie3
Pulsout B.3,w7 'Voie4
PWMDUTY B.4,w8 'Voie5 Mot
Serout VersTor, N38400_32,(b5) 'Vers le déco tor
Pause 10
Loop
'Je_meure:
pwmout B.4, Off
Low B.4 'Au cas oû le pwm finirait sur un état haut (?)
Serout VersTor, N38400_32,(0)) 'Eteint tous les tor (énergie)
Pause 500
Do
High LedSecu
Pause 100 'Cligno Sécu mot.
Low LedSecu
Pause 200
Loop