RC Receiver Interface
There are numerous RC Receiver interfacing techniques published on the web. My quadcopter design is using only one processor for all its computation. For this reason, I spent extra time designing the interfaces to be as efficient as possible. Even though RC Receiver interfaces aren’t super complicated, they can cause real-time scheduling issues because of the number of interrupts and the time spent inside these interrupt routines.
Typical RC Receivers output the channel values in a given sequence of pulse width modulated (PWM) signals. The transmitters and receivers I have tested are Spektrum made. All Spektrum models seem to have the same design style. After a small bit of testing, I found that the several channels of signals are output in the same order everytime and have a small time separation. Since the standard for RC PWM is 50Hz, each pulse comes every 20 milliseconds. The top 5 lines of the picture above show an example output of a 5 channel Spektrum made receiver.
In a microcontroller, the most accurate way to measure incoming pulses is to use an input capture with a timer. Measurement occurs when a free running timer value is latched into a register when an event occurs. Obviously, a higher frequency timer yields a more precise pulse measuring system. Since most microcontrollers only have a few input capture pins, some special circuitry must be used to measure several pulses. Since the Spektrum systems do not overlap their output pulses, a simple OR gate structure can be used to combine all the signals into one signal.
Since my quadcopter will be using the Spektrum DX5e and AR500, I’m using a quad 2-input OR gate IC (MC14071BCP), to create this combined signal. As shown in the timing diagram at the top, there are still 2 voltage transistions per pulse. This results in 10 interrupts for this design style. For synchronization purposes, there is always a time between the last pulse and the beginning of the first pulse that is longer than the longest possible pulse. To capture the values sent by the transmitter, the software is setup for an interrupt to occur on every transition of the signal. All of the interrupts, except the last one, have a very small amount of time to process. The last interrupt copies out the five pulse width values and triggers an availability flag so that the rest of the software can have access to it.
An interesting thing that I noticed while testing is that Spektrum has a constant delay of 60 microseconds between each pulse. To make the system even more efficient, turning off the falling edge interrupts for the first four pulses then back on for the last interrupt results in 4 less interrupts. For the first 4 pulse width values, 60 microseconds would just be subtracted off.
For my system, this OR gate structure serves another purpose. The AR500 receiver runs on 5 volts, however, the microcontroller (LPC1768) runs on 3.3 volts. Of course there are many ways for converting one to another but the MC14071BCP IC has a wide voltage range and is tolerant to 5 volt inputs when running at 3.3 volts. Without extra circuitry, it will convert the five 5 volt signals from the AR500 into one 3.3 volt signal that represents all five channels.
In conclusion, I’ve found that using a simple OR gate IC is very efficient for pin usage, timer utilization, voltage translation, and interrupt time efficiency.
Update:
I implemented this RC receiver interface on the LPC1768 connected to a AR500. My results are accurate to about 60-70ns. This leads me to believe that the AR500 is running on the typical ATmega8 (or 168 or 328) microcontroller running at 16MHz (1/16MHz = 62.5 ns).
Update:
Due to popular request, here is the code I used on the LPC1768 (right-click download, then change the “.pdf” extension to “.zip”):