Driving a PICAXE 08M from the PWM output of a RC receiver

axeman22

Member
for a while I have been pondering how to take a spare channel on my RC receiver (Futaba for my Helicopter in this case) and use that spare channel to somehow send signals or binary ON/OFF messages to an onboard PICAXE which I could subsequently do something with. Like, enable NAV lights when greater than 25% throttle.. when greater than 35% then turn on Strobe light also - etc. - When less than 25% enable onboard glow plug!?

The output of a Servo channel is Pulse Width Modulation as far as I know (wiki) and the PICAXE has plenty of high resolution ADC inputs which will, at a given point in time, take a voltage sample and then give that a number to represent it's value - the higher the voltage, the higher the number - simple.

The PWM signal is too messy to try and sample with the ADC(wiki) inputs of the PICAXE direct. So all I did is put a capacitor across it, with a resistor accross the capacitor in turn. The resistor is doing it's best to dischange the capacitor whilst the PWM signal is coming in as charge accross the capacitor - the more the PWM's duty cycle(the more your transmitter stick is raised), the more effective charge gets into the capacitor therefore the higher the PICAXE ADC reads -comes sample time. You can then make programmatic decisions based upon the sampled level you get. I used a Cap which was much bigger than I needed(all I had lying around!).. you can experiment with the values of the Cap and resistor in the sample circuit. The challenge there is the have a value which is still responsive enough but there is no wavering to the ADC when it is sampling it - have a play, you'll see what I mean.

Take a look at the linked Video below on Youtube, or the higher resolution on direct from my blog (better).

Youtube : http://www.youtube.com/watch?v=r91yWyIxI6U

My Blog Host : http://vk3jap.net/media/PICAXE%208M%20SERVO%20PWM.mp4

imagine what you can do... just another cool use of a PICAXE Microcontroller..

- My blog : http://vk3jap.net/blog
 

westaust55

Moderator
Consider the PULSIN command.
It is triggered by rising or falling edge (you specifiy) and measures the pulse duration in 10usec increments.
"Analog" RC servos for example work on a 20 msec interval and the typically pulse range might be something like 600 us to 2500 usec giving values from the PULSIN command in a range like 60 to 250.

You can use that sort of range to detect vaying states/levels for required actions.

Other will likely give you further suggestions as well.
 
Last edited:

Wrenow

Senior Member
Westy is spot on. R/C io actually more of a pulse=width encoding schem than the PWM you are thinking of. There are several good discussions on the web (some done on this forum) about the structure of the signal. You are better off reading the signal with pulsin and then doing whatever you wish with it. People have done mixers, model warship fire control assistants, etc. using this methodology. Personally, I like usint the little Picaxe 3 servo controller board fpor this type of application, as the filtering is built in, it is very compact, and you can read the transmitter signals through the servo outputs, using them as inputs.

Cheers,

Wreno
 

axeman22

Member
Consider the PULSIN command.
It is triggered by rising or falling edge (you specifiy) and measures the pulse duration in 10usec increments.
"Analog" RC servos for example work on a 20msec interval and the typically pulse range might be something like 600us to 2500usec giving values from the PULSIN comamnd in a range like 60 to 250.

You can use that sort of range to detect vaying states/levels for required actions.

Other will likely give you further suggestions as well.
never thought of that.. thanks! - appreciate the ideas, if anyone else has more I'm keen to hear them..
 
".... giving values from the PULSIN comamnd in a range like 60 to 250." That is, generally correct but I found that with some receivers I get 100 to 210 (at 4MHz). To know the values from my receiver I simply used debug after pulsin and adjusted accordingly.
I have used PULSIN with an 8M to trigger an On-Board glow plug driver. Also I used the same approach to turn on the landing light.
 

goom

Senior Member
I did design a RC/Picaxe based system for switching lights on and off on a model helicopter. With my first version, there was some random switching probably due to the electrically noisy environment in the 'copter. I solved that by ignoring pulse widths out of normal range, and only taking action on receipt of 4 consecutive consitent pulses.

Code:
'Radio control 2 channel switch using PICAXE-08 or 08M
'Cycles ChA-on ChB-on ChB-off ChA-off each time RC input changes from hi to lo or vice versa
'Either channel can operate in latched or unlatched operation.
'Change the values of ThresholdA and ThresholdB as desired to change the switching points.   
'PICAXE-08 connections are:
' Leg 1                   +5V
' Leg 2 (Serial in)       Tie to Ground through 10K resistor
' Leg 3 (In4/Out4)          NC
' Leg 4 (In3)               NC
' Leg 5 (In2/Out2)        Pulse input from radio receiver
' Leg 6 (In1/Out1)        Channel B output
' Leg 7 (Out0/Serial Out) Channel A output (must disconnect the programming cable when running program)
' Leg 8                   Ground
symbol OutA=0    'Name channel A output pin (leg7)
symbol OutB=1    'Name channel B output pin (leg6)
symbol Pulse_Width=w0   'Name measured input pulse width
symbol Prev_Pulse_Width=w1  'Name previous measured input pulse width 
symbol Status=b4   'Name cycle status (0 to 3)
symbol Pulse_In=2   'Name pulse input pin (leg5)
let dirs=%00000011   'Set pins 0 & 1 to outputs, rest to inputs
low OutA    'Set channel A output low initially
low OutB    'Set channel B output low initially
Status=0                                'Set status 0 initially
Restart:
Pause 500      'Wait for 1/2 second initially
   pulsin Pulse_In,1,Pulse_Width   'Measure and store input pulse
   if Pulse_Width<50 or Pulse_Width>250 then Restart 'Go back if no valid pulse detected
   
Start:
   Prev_Pulse_Width=Pulse_Width
   pulsin Pulse_In,1,Pulse_Width   'Measure and store input pulse
   if Pulse_Width<50 or Pulse_Width>250 then Restart 'Go back if no valid pulse detected
   
   if Pulse_Width>150 and Prev_Pulse_Width<150 then Increment
   if Pulse_Width<150 and Prev_Pulse_Width>150 then Increment
   goto start
   
Increment:   
 Status=Status+1  'Increment Status after a low/high or high/low pulse change
 if Status<4 then Cycle 'Recycle to status 0 if status gets to 4
    Status=0
 Cycle:
 lookup Status,(%00000000,%00000001,%00000011,%00000001),b5
 let pins=b5     'Turn on/off outputs A & B according to status
goto start
 
Top