Tuesday, February 26, 2013

Logic Analyzer Decoding PPM and TTL Serial

In my spare time I have been teaching myself to program microcontrollers, specifically Atmel ATMega328s & ATTiny85s using the Arduino IDE.  It has been fun learning what can be done with a few lines of code and a handful of $3 ICs.  As a result, it has become necessary to better understand how devices communicate and one of the best ways to do so is with a logic analyzer.  I recently purchased a Saleae Logic 8-channel logic analyzer and went to work testing anything I had lying around.

First up was my Futaba 4 channel RC transmitter. (See this post about converting a Futaba 4 channel radio to 5 channels.)  For those who are unfamiliar with hobby grade radio control equipment, they typically use pulse-position modulation to encode stick inputs and pass the information to the servos.  The transmitter reads the position of all the inputs and encodes this information as a single pulse train as shown below.


To decode this pulse train you have to understand that RC servos are fed a pulse-width modulated signal at 50 hz. Pulse length represents position and varies from 1ms to 2ms with 1.5ms being the neutral position in most cases.  Looking at the pulse train above you can see the signal is held HIGH and the pulled LOW for a brief period. If you measure the time between the falling edges, you will see that it is about 1.50ms and the pattern repeats 5 times.  This is the position of the 5 channels encoded as a series of pulses.  Pretty cool huh?  It should be noted that Futaba uses inverted logic and other radio systems may use a signal that starts LOW and is driven HIGH.


After looking the transmitter's output, I wired the logic analyzer to the receiver and recorded another sample set.



The job of the receiver is demultiplex the PPM signal into the individual servo signals as shown above.  Channels 1-5 show how a PPM signal is usually decoded.  On the first falling edge of the PPM signal, the output for channel 1 goes HIGH, on the next falling edge of the PPM signal, the output for channel 1 goes LOW and the output for channel 2 goes HIGH and the pattern repeats until all 5 channels are decoded, at which time there is a long pause that tells the receiver to start over at channel 1 on the next falling edge.

This is where things stopped making sense.  My 4 (now 5) channel radio came with a 7 channel receiver.  Looking at the 6th channel, it can be seen that it outputs a pulse that goes LOW at the beginning of the PPM train and then HIGH again at the end.  This isn't useful for driving a servo, so I'm not sure if it was ever meant to serve a function.  Channel 7 mimics Channel 1 and Channel 8 does nothing, which confirms that it is simply a battery input.


Next I wanted to test the actual logic analyzing functions of the software.  I wired a graphic LCD to an Arduino and loaded a sample sketch that reads data from the serial UART and displays it on the screen.



Typing a simple "Hello World" in the serial monitor window, I hit enter, sending the information to the Arduino and the logic analyzer.



I added an 8N1, 9600 baud analyzer to Channel 0 and, as seen above, it decoded my "Hello World" comment also showing the 'n/' newline escape sequence at the end of the string.

So far I'm impressed at how easy this unit has been to operate and hope to put it to use in the future.

No comments:

Post a Comment