Help designing a thermistor circuit

AI Thread Summary
The discussion focuses on designing a thermistor circuit for temperature measurement using an 8-bit ADC with a 2.55V reference. Key challenges include calculating the resistance for a potential divider and effectively using linear approximation for temperature readings based on two known resistance values at specific temperatures. Participants suggest creating a calibration look-up table due to the non-linear behavior of thermistors and discuss the importance of considering thermistor tolerance in the design. Alternative methods, such as using an op-amp for signal conditioning and ensuring accurate voltage references, are also explored. The conversation emphasizes the need for empirical error calculation and the potential for improved accuracy through careful circuit design.
rusty009
Messages
68
Reaction score
0
I want to design a thermistor circuit to be sampled by a microcontroller using an 8 bit ADC, with a voltage reference of 2.55V, I know the following

T (ºC) R(ohms)
25 2815
40 1200

I am going to use a potential divider then use a linear approximation to measure the temperature. I have two problems, firstly I don't know how to calculate the resistance needed for the potential divider, and secondly how do I calculate from the linear approximation, should I make a line between the two points given ? Thanks in advance !
 
Engineering news on Phys.org
rusty009 said:
I want to design a thermistor circuit to be sampled by a microcontroller using an 8 bit ADC, with a voltage reference of 2.55V, I know the following

T (ºC) R(ohms)
25 2815
40 1200

I am going to use a potential divider then use a linear approximation to measure the temperature. I have two problems, firstly I don't know how to calculate the resistance needed for the potential divider, and secondly how do I calculate from the linear approximation, should I make a line between the two points given ? Thanks in advance !

I'm impressed by this entry at wikipedia.org:

http://en.wikipedia.org/wiki/Thermistor

Looks like a linear approximation won't be very accurate for you. Probably best to make a calibration look-up table, based on those equations, and on some measurements by you. Do they have a calibration curve in the datasheet for your thremistor?
 
Hey, I looked at that entry in wikipedia but the linear approximation did not seem to work for me, I have done,

gradient k=(2815-1200)/(25-40)=107.67

but k*25 does not equal 2815, am I making a stupid mistake here? I need to use a linear approximation, how would I go about calculating the resistance value for the potential divider ?
 
rusty009 said:
Hey, I looked at that entry in wikipedia but the linear approximation did not seem to work for me, I have done,

gradient k=(2815-1200)/(25-40)=107.67

but k*25 does not equal 2815, am I making a stupid mistake here? I need to use a linear approximation, how would I go about calculating the resistance value for the potential divider ?

Well, first you would plot the resistance versus temperature graph -- are you only intersted in temps between 25C and 40C? What is the temperature range you want to cover? Also, what is the *tolerance* of the thermistor over the temperature range you want? If it is +/-10% from unit to unit, you will need to include that in your design (so the reading does not top out or bottom out due to manufacturing variations in the thermistors).

The job of your circuit will be to translate something about the thermistor resistance in that target resistance range, into the voltages 0-2.55V. You will most likely use an opamp to do this, probably running between +/-5V or +/-12V with appropriate output clamping. You could also maybe use a more expensive single-supply CMOS opamp, running just between 0V and 5V.

Is the thermistor resistance dependent on the current you pass through it, or is it just dependent on temperature. If there is a "best" current, make that current with an opamp, and buffer the voltage across the thermistor with another opamp. Then process that buffered voltage with an offset subtractor and a scaling stage, to get you to what you want into your ADC.

If there is a wide tolerance on the thermistors, you can consider doing a calibration step as part of bringing up the circuit, either in the analog circuitry ouside, or in the uC after the ADC.

Show us what you come up with.
 
Hey, thanks for the reply. I am only interested in temperatures between 25 and 40 degrees. Is there a way to do it without an op-amp as I only have a microcontroller with an 8 bit ADC. I have just plotted the linear approximation in matlab, I have uploaded the file.

edit: the thermistor is only dependent of the temperature.
 

Attachments

  • line.jpg
    line.jpg
    8.8 KB · Views: 607
What do you mean you only have an ADC? Does it already include the sample-and-hold circuit that feeds into most ADCs? Or is it on the uC itself?

To do the offset, you will need to have a negative supply available. Do you have that?

If you don't need full 8-bit resolution, you can just bias it with a resistor that gives you 2.55V when the thermistor is max resistance, and do the offset in your uC.

I have to bail for tonight. Hopefully somebody else can pick this up with you if you still have questions.
 
The ADC includes a sample-and-hold circuit and I do have a negative supply available.

If you don't need full 8-bit resolution, you can just bias it with a resistor that gives you 2.55V when the thermistor is max resistance, and do the offset in your uC.

I don't understand what you mean by this...
 
Do you have the part number of the thermistor?
 
no, all the info I was given is listed above.
 
  • #10
For a my old design I've to retrieve the temperature from a NTC thermistor using a PIC microcontroller.
I've solved it by sampling the NTC characteristics in several point (10 interval from 0 to 150 °C) and after that I've calculated the linear approximation coefficient for every interval.
To obtain the measured temperature then I've just to measure the thermistor voltage and then find the right sub-interval, after that by using the linear interpolation formula (with the right coefficient) I'm was able to retrieve the estimated temperature. Overall error was less than 1%.

Hope it help

Regards
Grinch
 
  • #11
Grinch,
thanks a lot, your response has helped me. I have the linear coefficient for my desired interval, but how did you calculate the resistance to be connected to the thermistor ? Also, how did you calculate the error in the estimation? Thanks.
 
  • #12
rusty009

I couldn't find any data sheet even close to the values you posted and only 2 points cannot define a curve so this solution is purely a guess. As Berkeman said, thermistors are not very linear and your linear approximation will not be very accurate. I did quick attempt at a simple network to linearize it a little.

To the +5V supply connect the thermistor and a 5.1 k resistor in parallel. To the other side of the thermistor and 5.1 k resistor connect a 430 ohm resistor to ground. Connect the input of the A/D converter to the junction between the two resistors and the thermistor. Program the microcomputer to divide the A/D output (0 to 255) by 3.825 to get temperature.
 
  • #13
Thermistors follow an exponential curve fairly closely. You can use the 40ºC (T=313K) data to find To in this equation:

<br /> \ \ \ R =2815\Omega \cdot e^{T_o \cdot (\frac{1}{T}-\frac{1}{298K})}<br /> [/itex]<br /> <br /> (T is absolute temperature here)<br /> <br /> Or, equivalently, you could do a linear interpolation of ln(R) vs. 1/T<sub>absolute</sub>
 
  • #14
I had a similar design task a couple years ago: 8 bit AtoD, thermistor input measuring water temperature. There was insufficient resolution over the required temperature range at one end.

I'm getting a little flustered, becaue I though I recalled using a bridge with a thermistor in one leg... In anycase, I was able to restore sufficient linearity, that the accuracy out of the ADC was obtained.
 
Last edited:
  • #15
A simple voltage divider may be enough to restore required linearity and resolution as both this

V = V_{bias} \frac{R_{therm}}{R + R_{therm}}
and this
V = V_{bias} \frac{R}{R + R_{therm}}

are themselves nonlinear in R_{therm} .
 
Last edited:
  • #16
skeptic2 said:
rusty009

I couldn't find any data sheet even close to the values you posted and only 2 points cannot define a curve so this solution is purely a guess. As Berkeman said, thermistors are not very linear and your linear approximation will not be very accurate. I did quick attempt at a simple network to linearize it a little.

To the +5V supply connect the thermistor and a 5.1 k resistor in parallel. To the other side of the thermistor and 5.1 k resistor connect a 430 ohm resistor to ground. Connect the input of the A/D converter to the junction between the two resistors and the thermistor. Program the microcomputer to divide the A/D output (0 to 255) by 3.825 to get temperature.

Thanks A LOT for this, but where does the number 3.825 come from ?
 
  • #17
rusty, you never did say how much temperature error is allowed in your output.
 
  • #18
I have been asked to calculate the error after I have built it. How would I go about calculating this ?
 
  • #19
I took the formula for resistance vs. temperature for thermistors, adjusted it to fit your points and calculated the resistor values to give a fairly well centered curve. Since the A/D presumably reads 2.55 V as 255, I multiplied the voltage by 100 at each temperature and divided by that temperature. Then I took the average of the quotients or 3.825 in an attempt to minimize error. This was not a rigorous solution and there are likely better ones.
 
  • #20
rusty009 said:
I have been asked to calculate the error after I have built it. How would I go about calculating this ?

You require the tolerance of the thermistor to do this, for one. But you say you don't have a part number.

Is this a one-off -- only one made? In this case you can arrive at error emperically by comparing it to another thermometer in the same bath.
 
  • #21
Ok, please look at the image below to see what I have made, please tell me if its completely wrong, the maximum resistance I can get is at 25 degrees which is 2815 ohms. I have an input of 5 V so a resistor of 2740 Ohms will take away 2.45 volts leaving 2.55 for the maximum input of the ADC.
 

Attachments

  • circuit.jpg
    circuit.jpg
    3.9 KB · Views: 518
  • #22
just realize that if you're using the +5VDC power supply, this will never be accurate, and you'll have to factor power supply variation and noise into your error calculation.

if you want something accurate, you'll need to use a voltage reference.
 
  • #23
rusty009 said:
Ok, please look at the image below to see what I have made, please tell me if its completely wrong, the maximum resistance I can get is at 25 degrees which is 2815 ohms. I have an input of 5 V so a resistor of 2740 Ohms will take away 2.45 volts leaving 2.55 for the maximum input of the ADC.

I think that's the circuit you need, if you swap the thermistor and resistor and take the reading off the resistor.(?) I thought you were going to follow sceptic's schematic, so I didn't have to work it out.

But your values are a little too idealized. Your part may be good to 5% at 25C. If your part is 5% high or low, you are going to overflow your ADC.

Do you know some calculus? It would help, in this case. sceptic's idea of a reistor in parallel with the thermistor might go for improving linearity--but it takes some calculus to find out--or a spreadsheet, or whatever mathpackage you might have.

How many of these devices are going to be made? It makes a big difference in the advice you get.
 
Last edited:
  • #24
rusty009 said:
Grinch,
thanks a lot, your response has helped me. I have the linear coefficient for my desired interval, but how did you calculate the resistance to be connected to the thermistor ? Also, how did you calculate the error in the estimation? Thanks.

Dear Rusty,
all you've to do is make a subinterval division of your operating temperature range, in my case 10 iunterval was fine to reach a maximum error less than 1 %.
My setup was a simply 5 V reference with a 1% resistor in series with the thermistor then the intermediate point between the first resistor and the thermistor was connected directly to the PIC ADC channel input.
When the temperature change also the thermistor resistance will change and with the readed voltage you are able to retrieve the estimated temperature. Let me some time to retrieve the original file and I'll give you full example.

Bye
Grinch
 
  • #25
Proton Soup said:
just realize that if you're using the +5VDC power supply, this will never be accurate, and you'll have to factor power supply variation and noise into your error calculation.

if you want something accurate, you'll need to use a voltage reference.

Thanks for all your replies, first of all this what I have been asked to do,

The temperature region of interest is between 25ºC and 40ºC, with resistance of 2815 and 1200 ohms respectively.
The thermistor will be sampled by a microcontroller using an 8 bit ADC, with a voltage reference of 2.55V (Maximum voltage input).
Using a potential divider, calculate the resistance required to drive the thermistor which will have one terminal grounded. Draft an algorithm or C source fragment which will convert the ADC value in an 8 bit register into the measured temperature using a linear approximation.

so proton soup your right about the voltage reference but I am not sure how to make this. Also you say that it will never be accurate, how do you know this ?
 
  • #26
Proton Soup said:
just realize that if you're using the +5VDC power supply, this will never be accurate, and you'll have to factor power supply variation and noise into your error calculation.

if you want something accurate, you'll need to use a voltage reference.

Actually, Proton, the DACs on these micros are purposely designed for simplified referencing. Using Vcc as both the internal ADC reference and your input reference means that it cancels-out in many input architectures such as rusty's. You just have to pay attention to Vcc noise.
 
Last edited:
  • #27
So this is a toy design, that will never be made, and no body cares if it really works well or not, right?

Your thermistor resistance is

R_T = R_o e^{B(1/T - 1/T_o)}

R_T is the thermistor resistance

R_o = 2815 \ \ \ \ B = 6211 \ \ \ \ T_o = 323

T is in units of degrees Kelvin.
The input temperature range is 323.15 to 338.15 Kelvin.

Thermistors might have R_T good to 4% from the idealized curve.

The curve is concave up, with 12% error from linear at the midpoint resistance. (This is conservative for an exponential curve to staight line comparison.)

V = V_o \frac{R}{R+R_T} \ \ \ \ V_o = 5 volts.

V is also the ADC count. R should be chosen to be 30.1K 1% so the upper counts don't overflow the ADC due to input tolerances.

This curve is concave down, with 8% error in V at it's midpoint. Good to fair. This helps cancel the 12% thermistor nonlinearity.

You're only utilizing ADC counts 142 to 242. Assume 1% count error.

Overall percent error is about \sqrt{1^2 + 4^2 + 4^2 + 1^2} = 5.8 % That's 5.8% of 15 degrees of span.

Overall that's about 0.9 C error. Bleh.

To get any better, the bias resistor, R should be about 20K, but that means referencing the thermistor not to ground but 1.2V, or so, below.
 
Last edited:
  • #28
Could you have meant

V = Vo * Rt/(R + Rt), Vo = 5 V
R = 3.01 K and
B =5302?
 
Last edited:
  • #30
Phrak said:
Actually, Proton, the DACs on these micros are purposely designed for simplified referencing. Using Vcc as both the internal ADC reference and your input reference means that it cancels-out in many input architectures such as rusty's. You just have to pay attention to Vcc noise.

well if that's the case, a voltage ref would make it worse
 
  • #31
Using that formula: 1/T = 1/To + (1/B)*ln(R/Ro) I get B = ln(R/Ro)/(1/T - 1/To).
Substituting values, and using 298 and 313 instead of 298.15 and 313.15, I get B = 5301.947. Using 298.15 and 313.15, B = 5307.158.
 
  • #32
That looks like the right equation, rusty.

But i should have said T_o = 298.15+25 in the definition of T_o. It was a typo.

I derived B using T_o = 298.15+25 \ \ \ \ R_o = 2815

The temperatures are in Kelvin. 25C = (298.15+25)K

323.15K should be the reference, not 0C nor 298.15K. This is just a property of an exponential fit to two data points. There's nothing magical about any particular temperature. You are free to choose any temperature/resistance reference pairs. When B=6211 the curve passes through the given data points.

If you plug T=298.15+40 into the equation I put up, you will get R=1200.0 ohms.
 
Last edited:
  • #33
hey guys, I think I'm sticking with my above circuit as my next task is to use the B parameter equation, so Phrak, I will use your equation for that question. But for the linear approximation, how do i calculate the error with just two points?
 
  • #34
Once you calculate B correctly
* you can find the value of the thermistor at various temperatures
* you can calculate the voltage that will be seen by the A/D.
* Take the A/D reading and find a way to calculate the temperature from it.
* Calculate the temperature from the A/D value for each temperature.
* % error = Abs(T - Tcalc)/T * 100
* You may be interested in both average error and maximum error.
 
  • #35
If I were you rusty, I would do it the same way you came up with that straight line plot.

You really want to know the error in V, the voltage feeding the ADC.

You have V as a function of R, and R as a function of T. Plot V as a function of T. Then compare it to a straight line with 25C and 40C at the endpoints.

Do you have MATLAB or something? If not, do it in excel (so I've heard).
 
  • #36
skeptic2 said:
Using that formula: 1/T = 1/To + (1/B)*ln(R/Ro) I get B = ln(R/Ro)/(1/T - 1/To).
Substituting values, and using 298 and 313 instead of 298.15 and 313.15, I get B = 5301.947. Using 298.15 and 313.15, B = 5307.158.

skeptic, if you calculated your B correctly, and plug 298 into T, you get 2815 ohms. But it should be 2815 ohms at 25C. See how it goes? It's just curve fitting though two data points.
 
  • #37
rusty009 said:
Hey Phrak, when I calculate B i get 4043.92, I use this equation,
http://upload.wikimedia.org/math/8/d/6/8d649a9ef06d12e8bf4f65e7d32cad0d.png

I think its because we use different K values, I used 298.15K for 25 degrees and 318.15 for 45 degrees, have I made a mistake? I am also not sure how you got the 30.1k value?

Isn't the 2nd temperature value supposed to be 40 C = 313.15 K?

EDIT:

I get B = 5302 K (agrees with Phrak) using 298 & 313 K
and I get B = 5307 K using 298.15 & 313.15 K:
http://www.google.com/#hl=en&q=ln(1200/2815)+/+(+(1/313.15)-(1/298.15)+)&fp=0k_STq_SEOg
 
Last edited:
  • #38
"skeptic, if you calculated your B correctly, and plug 298 into T, you get 2815 ohms. But it should be 2815 ohms at 25C. See how it goes? It's just curve fitting though two data points."

Good point Phrak, does the scale used make a difference in the values one gets for the curve? If so, which scale is best? Let's find out.

B = ln(R/Ro)/(1/T - 1/To)
For R = 1200 & T = 40 and
Ro = 2815 & To = 25
B = 56.84271

For R = 1200 & T = 313.15 and
Ro = 2815 & To = 298.15
B = 5307.158

For Celsius we get:
Temp...25...30...35...40
Res...2815...1927...1470...1200

For Kelvin we get:
Temp...298...303...308...313
Res...2815...2099...1580...1200

Apparently the scale does make a difference but which is correct? The curves intersect at 2815 and 1200. If we extend the range a little...

For Celsius we get:
Temp...-5....0...5...10...15...20
Res...0.0033...undefined...25079259...85245...12817...4970

For Kelvin we get:
Temp...268...273...278...283...288...293
Res...20623...14355...10124...7228...5221...3814

...we can see which is probably the correct curve.
 
  • #39
skeptic, T is the absolute temperature in these equations, so use Kelvins.

(Note the problem with division-by-zero that would occur at 0 C, if Celsius were used.)
 
  • #40
Redbelly98 said:
skeptic, T is the absolute temperature in these equations, so use Kelvins.

(Note the problem with division-by-zero that would occur at 0 C, if Celsius were used.)

The temp values under Kelvin are Kelvin degrees. I was trying to demonstrate that if Celsius were used as Phrak suggested in post #36, you would get a division by zero error at 0 C. Is this not clear?
 
  • #41
rusty009 said:
I think its because we use different K values, I used 298.15K for 25 degrees and 318.15 for 45 degrees, have I made a mistake? I am also not sure how you got the 30.1k value?
I missed this question earlier.

That was a mistake. I should have written 3.01K not 30.1K.

You want 3.01K because you don't want to overflow your ADC, but you want it as small as possible to get the best engineering linear output. Assume your thermistor is good to 5% of the manufacturer's given reististance of 2815 ohms. It could be as large as 2955.8. Given V_out = 2.55 volts, solve for the value of the series resistor.

You should get 2840 ohms. You need a 2868 ohm 1% resistor to get at least 2840 ohms. 3.01K is the most common 1% resistor greater than 2.84K ohms.

If the thermistor is really a 10% part, 3.01K wasn't conservative enough.
 
  • #42
Redbelly98 said:
Isn't the 2nd temperature value supposed to be 40 C = 313.15 K?

EDIT:

I get B = 5302 K (agrees with Phrak) using 298 & 313 K
and I get B = 5307 K using 298.15 & 313.15 K:
http://www.google.com/#hl=en&q=ln(1200/2815)+/+(+(1/313.15)-(1/298.15)+)&fp=0k_STq_SEOg

40C = 238.15K. I use a B of 6211 at a reference temperature of 25C.

If you use a different reference temperature you get a different B. But whatever reference you use, the curve it still has to pass through the two data points.
 
  • #43
Phrak said:
If I were you rusty, I would do it the same way you came up with that straight line plot.

You really want to know the error in V, the voltage feeding the ADC.

You have V as a function of R, and R as a function of T. Plot V as a function of T. Then compare it to a straight line with 25C and 40C at the endpoints.

Do you have MATLAB or something? If not, do it in excel (so I've heard).

I understand what your saying here, but then I will be using another linear approximation which again carries an error ?
 
  • #44
skeptic2 said:
does the scale used make a difference in the values one gets for the curve? If so, which scale is best? Let's find out.

Nicely done. This business of rescaling and offets comes up all the time. I wonder if there's some general study of it?

You're holding my feet to the fire--which is a good thing. I made a mild 'engineering assumption' based upon the magnitude of the error values that were inherent in rusty's design. I assumed I could get the same curve (or very close) by using a reference temperature other than 0C--namely 25C.

To resolve this, we need to use a reference at 0C. But we don't know the resistance at zero C, so now there are two simultaneous equations to solve.

Using R_T = R_o \cdot exp[ B_o(1/T - 1/T_o) ] where R_o and B_o are unknowns,

R_{T_1} = R_o \cdot exp[ B_o(1/T_1 - 1/298.15) ]

R_{T_2} = R_o \cdot exp[ B_o(1/T_2 - 1/298.15) ]

T_1 = 323.15 , R_{T_1}=2815

T_2 = 338.15 , R_{T_2}=1200

Solve for B_o and R_o

How does this curve compare my curve,

R_T = 2815 \cdot exp[ 6211(1/T - 1/323.15) ] , where B_{25} = 6211 and R_{25} = 2815 ?
 
  • #45
Redbelly98 said:
skeptic, T is the absolute temperature in these equations, so use Kelvins.

(Note the problem with division-by-zero that would occur at 0 C, if Celsius were used.)

skeptic2 said:
The temp values under Kelvin are Kelvin degrees. I was trying to demonstrate that if Celsius were used as Phrak suggested in post #36, you would get a division by zero error at 0 C. Is this not clear?

Sorry skeptic, I was skim-reading much of your post and missed your point. My apologies.

Phrak said:
40C = 238.15K. I use a B of 6211 at a reference temperature of 25C.
Umm, but:

40 C = (40 + 273.15) K = 313.15 K

238.15 K would correspond to (238.15-273.15)C = -35C

If you use a different reference temperature you get a different B. But whatever reference you use, the curve it still has to pass through the two data points.

Agreed that the curve does need to pass through the two data points. But it seems that B does not change, even when the reference values Ro and To change:

For example, the equations

R = 1200Ω * exp[5302K * (1/T - 1/313K)] <-- reference at 313K or 40C
and
R = 2815Ω * exp[5302K * (1/T - 1/298K)] <-- reference at 298K or 25C

both agree with the 2 known data points

2815Ω at 25C = 298K
1200Ω at 40C = 313K

In either case, B is the same.
 
  • #46
Redbelly98 said:
40 C = (40 + 273.15) K = 313.15 K

: oh cr*p :blushing:
 
  • #47
Phrak said:
: oh cr*p :blushing:

LOL, happens to everybody. :smile:
 
  • #48
Redbelly, using your more better 273.15K = 0C, I calculated the error incurred for various bias resistors. But PF doesn't accept MathCad files, so I can't attach it.

The results are pretty impressive. A 3.01K will deviate ~ -3.75% from a straight line passing through the end points at 25C and 40C. The optimal bias resistor is 1.45K with ~ +/-0.3% error, but the voltage across the thermistor is above the 0 to 2.55 volt ADC range.
Windows won't display a MathCad 7 plot correctly. Oh well.
 
Last edited:
  • #49
Phrak said:
Redbelly, using your more better 273.15K = 0C, I calculated the error incurred for various bias resistors. But PF doesn't accept MathCad files, so I can't attach it.

The results are pretty impressive. A 3.01K will deviate ~ -3.75% from a straight line passing through the end points at 25C and 40C. The optimal bias resistor is 1.45K with ~ +/-0.3% error, but the voltage across the thermistor is above the 0 to 2.55 volt ADC range.
Windows won't display a MathCad 7 plot correctly. Oh well.

How did you calculate the error ?
 
  • #50
rusty009 said:
How did you calculate the error ?

I graphed it. But that's not the total error. Everything that can deviate from ideal can be a source or error. It's the end of the day for me. See the post I made with a square root in it.
 
Last edited:
Back
Top