Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

display Temp reading on LCD

Status
Not open for further replies.

hhhsssmmm

New Member
hello

I have a PIC18F4220 running @ 20MHz and using C18 compiler.

I have a 20x2 LCD module connected to my PIC and i can successfully display my characters & strings etc out on to the LCD. The LCD is configured for 8bit mode operation....no nibbling!

I now have a temperature sensor module connected to an ADC input on the PIC and wish to display the current temperature reading out on the LCD screen. However, my problem and confusion in displaying the temperature on the LCD is based on how to prepare the software algorithm for displaying. The area of my obstcale and confusion is as follows...

1) "My ADC input (temperature reading) is saved in a 16bit int variable (10bit ADC). The LCD is sent byte size information from the PIC to display the relavent data. So how to transfer the tempurature saved in 16bit ADC variable out on to the LCD?"

2) "Also how to convert the 16bit ADC value (temperature reading) into the relavent scaled tempurature output for LCD display? The temperature reading can be anything such as... '23.4' or '18.0' degrees celcius etc"

Can anyone please suggest an algorithm and if possible show me some web link where such examples have been carried out before?

thank you
Haseeb
 
Is the output of the temperature sensor linear with temperature? If not, then you will need to know exactly what the relationship is. Also you will need to know the output value for (at least) 2 known temperatures.

Once you have that, you can determine (or read from the temperature sensor's data sheet) the mathematical relationship between what is being measured (the temperature in this case) and the value seen by the PIC's ADC. Then you use the PIC code to convert the ADC measurement back to the temperature value. After that it is a fairly basic step to convert the integer/floating point value into a string of decimal digits which can be sent to the LCD.

Susan
 
Aussie Susan has a good point. If the sensor is linear you can create an algebraic equation to convert from AD reading to temperature. If it is non linear you are looking at more complex math.

What portion of the 16 bit AD value are you using? Do you need the full range of 65,535 units of discrimination? I doubt it. If resolution is reasonable a table read might be a rasonable idea. If the sensor is non linear review Microchip AN942 on Piecewise Linear Interpolation. I'm using that method on an altimeter than has 16 bit input. The pressure-altitude relationship is logarimithic.

Translating from a 16 bit number to display digits is straightforward. Take the AD number and subtract 10,000 until the result is negative. Add back the last 10,000 subtracted. The number you were able to subtract, before going negative, is the number of 10,000's to display. Repeat the process with 1000's, then 100's, then 10's to fill out your display digits.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top