Showing posts with label Arduino. Show all posts
Showing posts with label Arduino. Show all posts

Monday, March 4, 2013

GLCD Automotive Digital Gauge

After years of using aftermarket mechanical gauges in my truck (and repairing them several times) it was time to upgrade.  Not missing an opportunity to make something cool, I decided to go digital using a micro-controller and LCD display instead of analog gauges.

Starting off simple, I wrote a test program and wired up a 16x2 alphanumeric display.  The test program showed values for water temperature, oil pressure, Air/Fuel ratio, and battery voltage.


Thinking that I might want to display more parameters like indicators for 4x4, Low Range, and front & rear lockers, I moved the program to a larger 20x4 LCD.


After acquiring a 128x64 graphic LCD display to play with, I wrote a new test program to take advantage of the flexibility of the graphic display, including adding an intro screen with bitmap images.  The monitored parameters were changed slightly.  Displayed were values for water temperature, oil pressure,and voltages for the primary and secondary batteries.



Unfortunately the graphic LCD uses a LOT of I/O pins, including 5 of the 6 analog pins on the ATMega328, which makes it hard to monitor analog sensors.  One way to get around this would be to re-map the I/O pins to free up analog inputs.  Currently data and command pins are group together, each on their own port.  Remapping the pins would spread them across more than one port and slow performance slightly.
Other options include using a second uC to gather the data from the various sensors and pipe the information to the display via the serial UART, or use a analog multiplexing IC.  Depending on the performance penalty, the path of least resistance would appear to be remapping the I/Os.  More experimenting is in order!

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.