Searching \ for '[PIC] Linearizing a Thermistor and Measuring Resis' in subject line. ()
Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/devices.htm?key=pic
Search entire site for: 'Linearizing a Thermistor and Measuring Resis'.

Exact match. Not showing close matches.
'[PIC] Linearizing a Thermistor and Measuring Resis'
2007\07\25@203251 by

Just got done catching up on the E.E. thread and as such I've decided this
is more appropriate to PIC, as it doesn't concern exhaust emissions or the
ecology of the environment.

We've used the TCN75/DS75 style chips for temperature measurement for a
long time, but we want to measure remotely--meaning put the sensor on the
device, not just on a board inside the same box as the device--so we are
going to use a thermistor this time.

Enter AN685, which talks about the Steinhart-Hart Thermistor equation, and
why your average PIC probably has better things to do with its time than
calculate it.  Then the app note suggests how you can get an approximation
of linear behavior by pairing it with a resistor of equal value around the
temperature of interest.  If  you can tolerate an error around +/- 1 degree
C and a limited range around +/- 25C, this greatly simplifies
things.    There are two graphs, one showing the resistor in series with
the device, the other in parallel.  The graphs show how the error is
distributed around the area of interest.  The two graphs are mirror images
of each other.  That means that your choice of configuration doesn't affect
the performance; it just means you can pick the configuration that suits

The series-resistor setup is amenable to a voltage divider, while it is
suggested that the parallel arrangement is going to be used inside feedback
loops.

There's a third configuration, and, since it uses more parts, it follows
that it is a superior method.  (Oops, the time spent on OT is catching up
with me).   This configuration uses "discharge a capacitor, then charge it
up while watching the timer" (a.k.a., "integrator") method.   It includes a
reference resistance that allows you to cancel out many of the
circuit  variables.  In the course of setting this up to try, I realized,
"Hey, we're still just measuring the resistance of a thermistor and
resistor".  So, I'm expecting the performance to be the same as the other
methods.

What I'm wondering is if there is any advantage to this method over the one
using a divider and A/D.   As the app note shows a PIC12C509 doing the
work, I suspect "don't need an A/D" is the prominent feature here.   But
integrator  vs. the A/D, and the fact that charging a capacitor is
inherently logarithmic and perhaps could counteract some of the "scale
compression"  the thermistor gives at one extreme or the other.

Either way is probably adequate for our application but I like to know what
I'm dealing with before I go ahead, especially because new ideas or uses
can come up later.   But it doesn't get much simpler than reading the A/D,
especially if it's on the chip already.

* * *

Here's an interesting footnote, as it didn't fit into the story.  I have a
series resistor/divider/ A/D setup running here, and I found it is immune
to supply voltage variations when the supply is also used as the reference
voltage to the A/D.  Makes sense when you think about it, though the
impulse has always been to stick a voltage reference on there.

Barry

> Enter AN685, which talks about the Steinhart-Hart Thermistor equation,
> and why your average PIC probably has better things to do with its time
> than calculate it

"probably" is very subjective. The pdf says -

"Wide industry acceptance makes it the most useful equation for precise
thermistor computation"

But if you're interested in only the approximation provided by the other
methods, why not just use a look-up table ? Characterise for yourself
the thermistor resistance vs temperature in a water bath or use the
manufacturer's data with the Steinhart-Hart equation

> "There's a third configuration, and, since it uses more parts, it follows
> that it is a superior method [snip] So, I'm expecting the performance to
> be the same as the other methods"

Has to be one or the other !

If you want to experiment with the integration method you might want
to have a look at the Scenix virtual peripherals page

http://www.sxlist.com/techref/ubicom/virtperf.htm

or this, for an F84 (or any micro without ADC)

http://home.clear.net.nz/pages/joecolquitt/0pots.html

for a thermistor, in combination with one of the linearising methods

Barry Gershenfeld wrote:
> Just got done catching up on the E.E. thread and as such I've decided this
> is more appropriate to PIC, as it doesn't concern exhaust emissions or the
> ecology of the environment.

Thank goodness!

> Enter AN685, which talks about the Steinhart-Hart Thermistor equation, and
> why your average PIC probably has better things to do with its time than
> calculate it.  Then the app note suggests how you can get an approximation
> of linear behavior by pairing it with a resistor of equal value around the
> temperature of interest.

Hi Barry,

I use thermistors almost exclusively when measuring temperature locally
with a PIC. I use a resistor in series(usually 1%) and as you say, using
the same power supply as the PIC makes it all ratiometric so you don't
need to be concerned about the exact power supply voltage, although you
do want it to be fairly clean. I make a lookup table with voltages for
every increment of temperature the manufacturer supplies in their spec
sheet, usually every 5 degrees C. I create the lookup table with a
spreadsheet so it's fairly easy to change configurations and thermistors
and resistor values. Then I interpolate between the table values to
arrive at the temperature. I have always done it the slow and stupid
way, starting at one end of the table and working through it comparing
until the difference flips polarity. Then I interpolate linearly. It's
certainly not perfect but less than a degree off. If I needed closer
tracking I would create a lookup table with finer resolution rather than
put a fancier interpolation algorithm in the PIC.

If I am doing DPSS laser thermostat control I usually need .02 to .05
degree resolution so then I use the raw thermistor values (quite often
amplified first). But I still use lookup + interpolation for the human
setting and viewing of values.

So I heartily support your decision to look into thermistors. After you
use them once, you'll wonder why it took you so long to try them :)

Cheerful regards,

Bob
I designed the M700 and M750 "cow thermometers" at http://www.gla-ag.com .
We used a 20 bit LTC ADC driving a PIC over SPI. The ADC has an internal
reference, though not super precise. However, as others have pointed out,
the ADC is ratiometric, so as long as the sample varies with the
reference, errors cancel. I use a 0.1% resistor between the reference
output of the chip and the top of the thermistor (with the bottom of the
thermistor going to ground). I used the resistance tables supplied by the
thermistor manufacturer. I put them in a spreadsheet and calculated what
the ADC output would be at each temperature they specified. I then did a
lookup table in the PIC with linear interpolation between the two points
where the ADC value landed. Accuracy is better than 0.1degree C or
0.1degree F in the temperature range of interest (90 to 110 degrees F).

Harold

--
FCC Rules Updated Daily at http://www.hallikainen.com - Advertising
opportunities available!
What PIC and LTC ADC did you use, Harold?

----- Original Message -----
From: "Harold Hallikainen" <haroldhallikainen.org>
To: "Microcontroller discussion list - Public." <piclistmit.edu>
Sent: Wednesday, July 25, 2007 11:42 PM
Subject: Re: [PIC] Linearizing a Thermistor and Measuring Resistance

{Quote hidden}

> --
I actually started with a Maxim ADC/DAC/RTC, but deliveries got
unreliable, so I moved to the LTC2420 and the PIC18LF2520.

Harold

> What PIC and LTC ADC did you use, Harold?
>
> {Original Message removed}

>-----Original Message-----
>From: piclist-bouncesmit.edu [piclist-bouncesmit.edu]
>On Behalf Of Bob Blick
>Sent: 26 July 2007 03:00
>To: Microcontroller discussion list - Public.
>Subject: Re: [PIC] Linearizing a Thermistor and Measuring Resistance
>
>

>Then I interpolate between the table values to arrive at the
>temperature. I have always done it the slow and stupid way,
>starting at one end of the table and working through it
>comparing until the difference flips polarity. Then I
>interpolate linearly. It's certainly not perfect but less than
>a degree off. If I needed closer tracking I would create a
>lookup table with finer resolution rather than put a fancier
>interpolation algorithm in the PIC.

I don't think fancy interpolation algorithms would ever be worthwhile for thermistor measurement to be honest. It would significantly increase execution time on a PIC, and the extra code space could be used for a bigger table in the first place.   The only thing I do differently is to scale the table in equal ADC steps (rather than equal temperature steps), which means you can get the two values required for interpolation with no table search at all which speeds things up.  It does however mean you generaly need more table entries to maintain accuracy at either end of the table where it gets more non-linear, but program space is rarely an issue for me.

Note that most cheap thermistors have a fairly loose tolerance (5-10%) so using the manufacturers Steinhart or Beta figures to create a lookup table will get you no better accuracy than this.  Absolute accuracy is often less important and repeatability and resolution of course.

Regards

Mike

=======================================================================
This e-mail is intended for the person it is addressed to only. The
information contained in it may be confidential and/or protected by
law. If you are not the intended recipient of this message, you must
not make any use of this information, or copy or show it to any
received this e-mail, and return the original to us. Any use,
forwarding, printing or copying of this message is strictly prohibited.
No part of this message can be considered a request for goods or
services.
=======================================================================

Thank you, Harold.  I'm looking to do something similar.  I will review the
components.

----- Original Message -----
From: "Harold Hallikainen" <haroldhallikainen.org>
To: "Microcontroller discussion list - Public." <piclistmit.edu>
Sent: Thursday, July 26, 2007 12:18 PM
Subject: Re: [PIC] Linearizing a Thermistor and Measuring Resistance

{Quote hidden}

> >> lookup table in the PIC with linear interpolation
> between the two points

> >> where the ADC value landed. Accuracy is better
> than 0.1degree C or
> >> 0.1degree F in the temperature range of interest
> (90 to 110 degrees F).

Hi Harold,

If all the needed range for accuracy was between 90
and 110, why not use an opamp and the internal 10 bit
ADC? You can feed the unamplified signal to another
channel, so you get rough temperature, and the amped
channel with 1000 points gets you better than .05
degree resolution.

Opamp and a few good resistors will cost you a lot
less than a 20 bit ADC.

Cheerful regards,

Bob

> I don't think fancy interpolation algorithms would ever be worthwhile for thermistor measurement to be honest. It would significantly increase execution time on a PIC, and the extra code space could be used for a bigger table in the first place.   The only thing I do differently is to scale the table in equal ADC steps (rather than equal temperature steps), which means you can get the two values required for interpolation with no table search at all which speeds things up.  It does however mean you generaly need more table entries to maintain accuracy at either end of the table where it gets more non-linear, but program space is rarely an issue for me.
>

I did it in VB a while back for a battery monitor, it was a bit of a
PITA, and I think you're right on all points.

{Quote hidden}

I like to minimize parts count. Each of those other parts would contribute
error. Dunno if it was the optimum design, but I like the way it turned
out. A 20 bit sigma delta ADC is not too expensive.

Harold
(The ideal design has zero parts)

--
FCC Rules Updated Daily at http://www.hallikainen.com - Advertising
opportunities available!
Response to Jinx, and review of some responses

[Jinx]

>But if you're interested in only the approximation provided by the other
>methods, why not just use a look-up table ?

I expect I will.  Outside the linearized range, at least.

> > "There's a third configuration, and, since it uses more parts, it follows
> > that it is a superior method [snip] So, I'm expecting the performance to
> > be the same as the other methods"
>
>Has to be one or the other !

It looks like there is no difference.  I was asking if I had missed something.

>for a thermistor, in combination with one of the linearising methods

I think you're saying the A/D is the way to go.  I don't think my questions
were clear.

[Harold]
[ likes lookup tables with interpolation.  Also used an A/D without a
second thought so I take that as a vote for the A/D ]
[ he also had trouble getting parts from Maxim...how unusual ]

[Mike ... uses tables done by ADC steps for speed ]

[Bob Blick ...  keeps the PIClist tradition by suggesting an alternate
circuit.  Harold reviews it ... "too many parts" ]

So it looks like the A/D is the way to go when you have one.  Maybe I can
switch in other resistors to extend the range.  The application really just
needs to know whether to switch on the fans or the heater, but reporting
the temperature has some showoff value.

Thanks for the help.

Barry

--- Barry Gershenfeld <barry_gzmicro.com> wrote:

> [Bob Blick ...  keeps the PIClist tradition by
> suggesting an alternate
> circuit.  Harold reviews it ... "too many parts" ]

Hi Barry,

I'm not suggesting it in your case - you'll get plenty
of resolution with the internal 10 bit converter of
any PIC, one resistor and a thermistor.

Cheerful regards,

Bob
OK....so that makes me want to ask...since I've been contemplating this....look up tables in 16F parts.  Been doing some experimenting, and I think you have to modify the PCL to do it on these parts (done it with 18F but its built in there) but it seems like it always makes the code jump to wierd areas and never works correctly.

Anyone have a piece of code they might be willing to share?  This is...for a thermister lookup in a sense....hitting certain temps I need to add an offset to a counter value.  I dont need each value of the A/D, just jumps in increments of anywhere from 25 to 10 depending on the value.  But I suppose I would need each value there, and then load an offset based on the A/D value being looked up in the table.

Harold Hallikainen <haroldhallikainen.org> wrote:
I designed the M700 and M750 "cow thermometers" at http://www.gla-ag.com .
We used a 20 bit LTC ADC driving a PIC over SPI. The ADC has an internal
reference, though not super precise. However, as others have pointed out,
the ADC is ratiometric, so as long as the sample varies with the
reference, errors cancel. I use a 0.1% resistor between the reference
output of the chip and the top of the thermistor (with the bottom of the
thermistor going to ground). I used the resistance tables supplied by the
thermistor manufacturer. I put them in a spreadsheet and calculated what
the ADC output would be at each temperature they specified. I then did a
lookup table in the PIC with linear interpolation between the two points
where the ADC value landed. Accuracy is better than 0.1degree C or
0.1degree F in the temperature range of interest (90 to 110 degrees F).

Harold

--
FCC Rules Updated Daily at http://www.hallikainen.com - Advertising
opportunities available!
> Anyone have a piece of code they might be willing to share

Some pretty good hints here

http://www.piclist.com/techref/microchip/tables.htm

I've got project routines for Flash reads on a 16F877 with 3
really huge tables but I'd need to tidy them up (ie add more
comments, maybe labels too) before posting

A taster - the tables are cross-referenced. A number input to the
PIC from a PC actually refers to a bit in memory, not a whole
14-bit byte, which explains the "0:13". The input number is /14
to find the byte and remainder is the bit in the next byte. That part
is fairly simple, the whole thing is more complicated, as a randomiser
is also included for generating look-ups. It's a gambling application

;================================================
;================================================

;increment target address if division result > 0:13

btfss  res_eq0       ;check non-zero flag. If set then result > 0

incfsz addl,w        ;base + offset + 1
goto   \$+3

;------- entry point for random routine

bank2

bank0
bank2

bank3
bsf    eecon1,eepgd
bsf    eecon1,rd
nop
nop
nop
nop
bank2
movf   eedata,w
bank0
movwf  lo
bank2
movf   eedath,w
bank0
movwf  hi
return

>So it looks like the A/D is the way to go when you have one.
>Maybe I can switch in other resistors to extend the range.
>The application really just needs to know whether to switch
>on the fans or the heater, but reporting the temperature
>has some showoff value.

If you need higher accuracy than the ADC provides by using the supply
voltage as its reference, you could always home in on the point of interest
in the thermistor curve, by using external reference on the PIC, and having
a three resistor divider off the supply to drop the Vref+ and raise the
Vref- closer to the operating point of interest. This could give you better
than twice the resolution at the operating point.

>>So it looks like the A/D is the way to go when you have one.
>>Maybe I can switch in other resistors to extend the range.
>>The application really just needs to know whether to switch
>>on the fans or the heater, but reporting the temperature
>>has some showoff value.
>
> If you need higher accuracy than the ADC provides by using the supply
> voltage as its reference, you could always home in on the point of
> interest
> in the thermistor curve, by using external reference on the PIC, and
> having
> a three resistor divider off the supply to drop the Vref+ and raise the
> Vref- closer to the operating point of interest. This could give you
> better
> than twice the resolution at the operating point.
>

I agree, but am concerned about the error introduced by resistor
tolerances and tempco.

Harold

--
FCC Rules Updated Daily at http://www.hallikainen.com - Advertising
opportunities available!

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