Searching \ for '[PIC] Converting A/D into Temperature' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/ios.htm?key=temperature
Search entire site for: 'Converting A/D into Temperature'.

Exact match. Not showing close matches.
PICList Thread
'[PIC] Converting A/D into Temperature'
2000\05\20@014719 by Damon Hopkins

flavicon
face
I've got an A/D circuit on my 16F874.
I have a couple of OP Amps hooked to some resistors a few Pots and a
thermistor so that I get a 5X gain on the voltage. (schematic available
if needed)
I have it giving me 2.5V at room temp. But for the LIFE of me I can't
figure out how to convert the 0-1023 value into a usable temperature.
I have an Excel spreadsheet that will tell me the readout if I type in
the voltage example: 0v=0, 5V=1023, 2.5V=512, 2.813782991V=576

>From my chart that last Voltage should correspond to a reading of 68F
(20C)
Maybe it's late and it's really simple but I can't figure it out.. any
help out there?

                               Damon Hopkins

2000\05\20@045937 by Jacky Joulin

picon face
hello,

can you give me your schematics.

B-Regards.

spam_OUTWeslayTakeThisOuTspamaol.com

2000\05\22@135042 by Eisermann, Phil [Ridg/CO]

flavicon
face
Damon wrote:
> I've got an A/D circuit on my 16F874.
> I have a couple of OP Amps hooked to some resistors a few Pots and a
> thermistor so that I get a 5X gain on the voltage. (schematic available
> if needed)
> I have it giving me 2.5V at room temp. But for the LIFE of me I can't
> figure out how to convert the 0-1023 value into a usable temperature.
> I have an Excel spreadsheet that will tell me the readout if I type in
> the voltage example: 0v=0, 5V=1023, 2.5V=512, 2.813782991V=576
>
> From my chart that last Voltage should correspond to a reading of 68F
> (20C)
> Maybe it's late and it's really simple but I can't figure it out.. any
> help out there?
>
>
       Well, using a thermistor, it's not exactly straightforward. The
reason
is the highly non-linear resistance to temperature characteristic of the
thermistor. I have been working on something similar (in my copious
spare time). This equation is from memory, i'll look it up tonight when
I get home:

       T(Kelvin) = 1/(A + B*ln(R) + C*(ln(R)^3))

This equation is the Steinhart-Hart equation. R is the resistance
of the thermistor. A, B, and C are material constants that you can figure
out by measuring the resistance at three different temperatures. The
constants are all less than 1 for my particular thermistor.

Now you can see the difficulty with this equation in a PIC. While the
fractional values can be taken care of by scaling everything,
calculating the natural log function is a bit more difficult. On top
of that, the temperature (in Kelvin) is actually the inverse.

Of course, I admit I am not the world's greatest PIC programmer. Perhaps
there is an easy way to realize the required mathematical operations
on a PIC.

In my circuit, I placed the thermistor in parallel with a fixed resistor
in an attempt to linearize the resistance a little. Over a certain
range of values, this works fairly well.

A lookup table is one possible solution. You could put a lookup
table for all possible values in external EEPROM. Or you could
place a smaller lookup table in memory, and interpolate between
points.

If anyone has any other ideas, please jump in.

Phil Eisermann
H:(440) 284-3787 (.....mazerKILLspamspam@spam@ix.netcom.com)
O:(440) 329-4680 (peisermaspamKILLspamridgid.com)

2000\05\22@140735 by Don Hyde

flavicon
face
Well, for limited temp ranges, you can fit a polynomial to it and get pretty
decent results -- I've done that for 0-50C.  The problem is that the curve
really is logarithmic, so no polynomial will fit very well, at least not
over any extended temp range.  Hint -- buried in Excel somewhere there is a
polynomial curve-fitting wizard, I just don't remember where.

> {Original Message removed}

2000\05\22@143829 by Scott Dattalo

face
flavicon
face
On Mon, 22 May 2000, Eisermann, Phil [Ridg/CO] wrote:

>         Well, using a thermistor, it's not exactly straightforward. The
> reason
> is the highly non-linear resistance to temperature characteristic of the
> thermistor. I have been working on something similar (in my copious
> spare time). This equation is from memory, i'll look it up tonight when
> I get home:
>
>         T(Kelvin) = 1/(A + B*ln(R) + C*(ln(R)^3))
>
> This equation is the Steinhart-Hart equation. R is the resistance
> of the thermistor. A, B, and C are material constants that you can figure
> out by measuring the resistance at three different temperatures. The
> constants are all less than 1 for my particular thermistor.
>
> Now you can see the difficulty with this equation in a PIC. While the
> fractional values can be taken care of by scaling everything,
> calculating the natural log function is a bit more difficult. On top
> of that, the temperature (in Kelvin) is actually the inverse.


If calculating logarithms is all that's holding you back, then check out:


http://www.dattalo.com/technical/software/pic/piclog.html

and

http://www.dattalo.com/technical/theory/logs.html


Scott

2000\05\22@164321 by steve

flavicon
face
> In my circuit, I placed the thermistor in parallel with a fixed resistor
> in an attempt to linearize the resistance a little. Over a certain
> range of values, this works fairly well.
>
> If anyone has any other ideas, please jump in.

This is one application where Excel is actually useful.
Use it to build a table of thermistor values over the range you want
to test. Then take that value to calculate the voltage you would get
at the A/D input for your circuit topology. Graph the values.

Try a simple voltage divider with a resistor at the top and the
thermistor on the bottom. It works for me.

>From the measured voltage values, have Excel calculate the factors
for a y=mx+c function, generate another column with the result
of that function and plot them on the same graph. Also
calculate the power dissipation for each step and have Excel put the
maximum value somewhere you can see it. Do the same for the error
value.

Now you can fiddle with the value of the series R to get the closest
fit.

If the error is still out of range, plot it. You may see a solution
staring you in the face. Also try extending the temperature range
that you are plotting to give the linear regression a bit more room
to move.

I did this recently and got <0.5 degree error over 0-100C with an
algorithm that was no more than y=mx+c plus a test for values within
two ranges. If they were, I added or subtracted half a degree. The
circuit was just a voltage divider.

Steve.
======================================================
Steve Baldwin                Electronic Product Design
TLA Microsystems Ltd         Microcontroller Specialists
PO Box 15-680, New Lynn      http://www.tla.co.nz
Auckland, New Zealand        ph  +64 9 820-2221
email: .....stevebKILLspamspam.....tla.co.nz      fax +64 9 820-1929
======================================================

2000\05\22@172444 by mike
flavicon
face
On Mon, 22 May 2000 13:46:59 -0400, you wrote:

{Quote hidden}

Use a lookup table - you can compensate for the thermistor
nonlinearity, and the nonlinearity of using a simple resistive divider
in one go. You can generate the table using the equation from the
thermistor databook data with a simple Basic/[insert your favorite
language] program, or probably Excel.

If you need a wide temperature range, use 2 switchable pullups to
improve linearity at the hot end, otherwise select the pullup/pulldown
to get a reasonable voltage swing over the range you're interested in.

More... (looser matching)
- Last day of these posts
- In 2000 , 2001 only
- Today
- New search...