Sunday, May 15, 2016

invested in a microcontroller board - part 3


The more I play with the 4x20 dot matrix LCD display the more I like it. It is a nice size that offer good legibility and can display quite a lot of crucial information. It would serve well as a multi-function display that can be configured for many different purposes, including data logging. It would make a nice instrument without causing distraction for nighttime driving. It has great viewing angles and the font size is just perfect.

I receive the sets of oil pressure and oil temperature gauges from China. They are very cheap and the total came to under $30 for both sets shipped.

two gauge sets for under $30 shipped - I figured if I don't like the gauge quality I can always use the senders

I actually rather like these two gauges for their minimalist look. Only I do not want to create a ghetto of gauges in Isolde's interior.

oil pressure sender (left) and oil temperature sender (right); note they skimmed on the ground connection to shave off a penny each

Today I decided to play with the oil temperature sender that came with the cheap Chinese made oil temperature gauge. I set out to characterize it over a temperature span. It is a NTC thermistor. I didn't want to spend a lot of time in the exercise. I just want to get enough data points to form a lookup table, or create a transfer function that is close enough for the purpose. To properly characterize a NTC thermistor takes more than what I know how.

Steinhart Hart equation for thermistor

I mainly want to get a rough equation so I can proceed with programming the Uno's analog input port to sample the NTC oil temperature sensor. I decided against using a lookup table as I would need to have a great number of accurate points to make it worthwhile. I just went with a simple linear equation. Within the temperature span of interest, there is probably errors of +/- 20 F. I am sure most analog consumer grade oil temperature gauge is hardly better than that.


With this simple exercise I came up with a transfer function of T = (4.386 - V) * 150/2.54. T is temperature in Fahrenheit. V is the voltage seen by the ADC. 4.386 is the y-intercept, and 150/2.54 is the negative slope of the straight line curve. It is good enough for the purpose of developing the program.

My programming skill is very poor and rusty. Having the LCD display really facilitate debugging and checking the syntax and proper use of data types in the code easy. I could display the raw ADC number to check against the reported temperature.

My preliminary idea of the information to be displayed on the LCD are oil pressure, oil temperature, ambient temperature, and the voltage of the starting battery in Isolde. All these are easily implemented with simple external passive components and with just the Arduino Uno and the LCD display. To add the ability for multi-function display where there can be multiple pages, I can add two simple switch buttons for navigation. Since uploading new code is so easy I can always update the code for special purpose features like data logger only when the needs arise. I do not want a highly configurable instrument because of safety considerations. I want the display to provide the crucial information without any need to set it or change it, and this arrangement should just fit the bill.

here is my initial mockup - though the ambient temperature is real

by late afternoon I got the oil temperature function working and accurate enough for now

At this point the total power consumption is about 110mA, with 100mA being used by the LED backlight. I plan to just leave the backlight on all the time whenever the engine is running to keep things simple.

Both the oil temperature and pressure sensors are simply wired as voltage dividers for the analog converter inputs to the uC. Same with the starting battery voltage sensing which would just be a voltage divider scaled from the 12V battery power to less than 5V safe input voltage for the Atmega uC.

Right now I started coding the oil pressure sensing and the starting battery voltage sensing. One thing about wiring up the starting battery voltage sensing. It is not a good idea to wire it up on the solderless breadboard. In the case the voltage divider connection is accidentally disconnected on the ground side, the uC can be instantly damaged from overvoltage unless there is an external clamping diode. Hence I would only make the real final wiring with secure soldered connections.

As I did a rough characterization of the oil pressure sender I was in for a surprise. It is a potentiometer moved by a diaphragm. The surprise is the resistance is very low - in the order of tens of ohms. It is about 1 ohm per PSI. With it so low, making a voltage divider itself would either be consuming too much power, or not provide enough signal for the 10-bit analog to digital converter to measure accurate enough.

Let say for 80 PSI which gives 80 ohm. Forming a voltage divider with a 1k resister will give 5 * 80 / 1080 V. This is only 0.37V. The 10-bit ADC resolution is just shy of 5mV per step. This works out to be slightly shy of 1 PSI per LSD of the ADC. In the other words, I would only be using the 80 bottom steps of the 1023 steps of the ADC. When used with a 1k resistor to form a voltage divider the current consumption of the dump network would be about 5mA wasted. If I pick a 500 ohm resistor, I would get about 2 LSB per PSI at the expense of 10mA wasted.

A bit more calculation to determine the right resistors for the two voltage dividers I got the scale factors worked out for the oil pressure sender as well as the starting battery voltage. I coded the two additional analog inputs. Wired in the two voltage dividers. Since I don't yet really have a 12V power from the real battery I temporarily wired it to the 5V Vcc of the Arduino Uno supply. All these took about 1 hour and the program is functional. The results passed quick sanity check as the reported values are as calculated.

I used an 80 ohm resistor to stand in for the oil pressure sender, so the display should report about 80 PSI of oil pressure if I have the coding correct. Also the voltage report for the starting battery should be about 5.07V that I measured with a DMM.

all 4 parameters reported on the display are real; the update rate is once a second

The final current consumption is 117mA with the additional 5mA due to the voltage divider for the oil pressure sensor. Here is a photo of the display in total darkness. It is very legible and not distracting. The actual color is more of a pleasant yellowish green.

the tiny red LEDs on the Arduino Uno board is much brighter than the display (that I deliberately set it very low)

While the program is quite usable, there are a lot of room for improvement. To name a few: the enabling of the built-in watch dog timer to recover when the uC crashes from interference, interrupt driven UI, interrupt-based fault detection of the engine and drivetrain system, and the list can go on.

No comments:

Post a Comment