PDA

View Full Version : Displaying temperature using a -40 to 185F??



jblackann
- 14th January 2008, 21:04
I am trying to display the temperature of a temp probe using an LCD and a PIC16F690. The probe can measure temps from -40F to 185F. The output from the temp probe is from 0.5 to 4.5V, respectively accross the temp span. I am trying to display the temp based on the analog input but I'm having some problems figuring out how to do this. I am using a 10-bit conversion with a 5V reference, so each bit is worth 0.004883 volts.

The equation that I came up with was
((Analog_value - 0.5V)/ (0.004883V))-40 = temp (in F)

The problem is that I can not multiply or divide decimal fractions in a PIC, atleast I don't know how to.

One solution I thought of doing was disregarding the temps below 0 F. I can just display (temp below 0F). I could then take the voltage point where it is above 0 F and then add decimal fraction between 2 points (0.275) and display this number. So from my calculations, an analog value of 1.2109 V will create a digital value of 248. I can state that this is 0F and then add 0.275 * (new digital value X - digital value 248) to create the new values of temp.

I am also allowing the user to have different things happen at different voltages and will need to convert 0 to 185 F into a value that will relate to A to D reading.

I am also low on memory space.

Do anyone have an ideas that might help? Thanks.

skimask
- 14th January 2008, 22:26
((Analog_value - 0.5V)/ (0.004883V))-40 = temp (in F)

won't work...
0-5v output, actually running from .5v to 4.5v, 10bit ADC, -40F to 185F range?

4v total range, 10 bit ADC, lowest value readable from ADC = 102.4, highest value is 921.6, range of 819.2

185+40 = 225 degrees total range thru 4v input offset by 40 degrees F

ADC value - 102 = the .5v offset at the input
ADC value * 225 / 819 = something like .275 degrees per bit

But the result so far is offset by 40, so...
IF result < 40 then
result = 40 - result
sign = negative
else
result = result - 40
sign = positive
endif
DONE....

So run a test case...
Input value from ADC is 921, corresponding to a voltage of 4.5v
921 - 102 = 819
819 * 255 / 819 = 225
The result is larger than 40, so sign is positive and subtract 40 from it,
225 - 40 = 185
sign positive 185
BAM done...

Another case at minimum...
Input value from ADC is 102, corresponding to a voltage of .5v
102 - 102 = 0
0 * 255 / 819 = 0
The result is smaller than 40, so set the sign negative and subtract it from 40.
40 - 0 = 40
sign negative 40
BAM done...


Not only that, but a search on temperature display here at this site would've most likely been a heck of a lot simpler and might actually net you some premade code just for this application....

Darrel Taylor
- 15th January 2008, 08:08
I understand the whole "Teaching a man to fish" thing.
But at the end of the day, the guy's gotta be able to catch a fish. :eek:

To help prevent starvation, I need to toss in a fish here. And maybe a loaf of bread to go with it.<hr>
The Slope Intercept formula for the given data points would be ...

Y = (0.2751 * X) - 68

to do this in PBP with 1 decimal place @ 10-bit resolution ...

ADCIN 1, TempF
TempF = TempF * 2751
TempF = DIV32 1000
TempF = TempF - 680
GOSUB ShowTemp

'...

' --- Display a Signed Word with 1 decimal place ---
ShowTemp:
if TempF.15 = 1 then LCDOUT "-"
TempF = ABS(TempF)
LCDOUT DEC (TempF/10),".",DEC1 (TempF//10)
Return

Bon Appetite,

skimask
- 15th January 2008, 18:45
I understand the whole "Teaching a man to fish" thing.
Bon Appetite,

Hey, you're right.
I missed that 6th line in the 1st post about fractions...
My bad...
-40F to 185F... that temperature 'probe' sounds familiar... like something else I've seen before... might even have a greater range, just not documented... what is it... I can't put my finger on it...
Oh...yes...it's a...(click)....mmmmmmmmmmmmmmmmsssssssssssssss