Help designing a thermistor circuit

In summary, you want to design a thermistor circuit to be sampled by a microcontroller using an 8 bit ADC with a voltage reference of 2.55V. You have the following information about the thermistor:T (ºC) R(ohms)25 281540 1200You plan on using a potential divider and linear approximation to measure the temperature, but you have two problems. Firstly, you don't know how to calculate the resistance needed for the potential divider. Secondly, you don't know how to calculate the temperature from the linear approximation. You have consulted Wikipedia and have found that a linear approximation may not be accurate enough for your needs. You are considering using a calibration look
  • #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.
 
Engineering news on Phys.org
  • #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 [tex]V[/tex], 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 [tex]R_T = R_o \cdot exp[ B_o(1/T - 1/T_o) ] [/tex] where [tex]R_o[/tex] and [tex]B_o[/tex] are unknowns,

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

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

[tex]T_1 = 323.15 [/tex] , [tex]R_{T_1}=2815[/tex]

[tex]T_2 = 338.15 [/tex] , [tex]R_{T_2}=1200[/tex]

Solve for [tex]B_o[/tex] and [tex]R_o[/tex]

How does this curve compare my curve,

[tex]R_T = 2815 \cdot exp[ 6211(1/T - 1/323.15) ] [/tex] , where [tex]B_{25} = 6211[/tex] and [tex]R_{25} = 2815[/tex] ?
 
  • #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:
  • #51
I've been very curious about how the nonlinearity of resistor biasing could go toward canceling the thermistor nonlinearity. Check-out these curves.

(hope this works this time)
 

Attachments

  • Thermistor.xls
    67 KB · Views: 235
  • #52
Phrak said:
I've been very curious about how the nonlinearity of resistor biasing could go toward canceling the thermistor nonlinearity. Check-out these curves.

Nice!
 
  • #53
If instead of using one 1% percent resistor you used two 5% resistors the error could be reduced as shown. The circuit with two resistors has a 2.2k resistor connected to +5V. The other side of that resistor is connected to the parallel combination of the thermistor and a 8.2k resistor. Even at the extremes of the 5% rating the error is still less than with one 1% resistor. The disadvantage of this method is that the temperature range is covered with fewer levels of the ADC, 82 steps instead of 99.
 

Attachments

  • Error Comparison.xls
    16 KB · Views: 238
  • #54
skeptic2 said:
If instead of using one 1% percent resistor you used two 5% resistors the error could be reduced as shown. The circuit with two resistors has a 2.2k resistor connected to +5V. The other side of that resistor is connected to the parallel combination of the thermistor and a 8.2k resistor. Even at the extremes of the 5% rating the error is still less than with one 1% resistor. The disadvantage of this method is that the temperature range is covered with fewer levels of the ADC, 82 steps instead of 99.

You're error curve looks very nice. I'm suprised that adding the parallel resistor helped rather than hindered. I'll paste it into MathCad and see if I get the same. I'm still skeptical, as you might have guessed.

The step count reduction is a miniscual increase in step error comparatively.

Using 5% parts adds error of their own. So does a 1%, of course. But I'll use your valued and see what happens. Do you think you could calculate the resistor divider error? Independent errors are like independent probabilities.
 
Last edited:
  • #55
By the way, Skeptic. Sorry if I caused you any confusion after I mistook the value of zero Kelvin.

Here's what I get for your input circuit. And good job! I would have never guessed. Did you do all your calculations in Excel??

I think our error values differ slightly from using different values of B.
 

Attachments

  • Skeptics Thermistor Circuit.xls
    55.5 KB · Views: 212
  • #56
Yes I used Excel. I have MathCad but I find Excel easier to use although MathCad certainly has more capabilities and the graphs look better.

The parallel resistor works because it limits higher resistances more than lower resistances. Thus at low temperatures as the thermistor resistance rises exponentially, the parallel resistor tends to straighten the curve a little.

The precision of the measurements can be improved by taking multiple measurements and averaging. If the voltage is between two steps of the ADC, averaging will interpolate between the two steps. For this reason a little noise is a good thing.

Another thing that improves the performance slightly is that when multiple components are combined and contribute individually to the tolerance of the output, because of the Central Limit Theorem, the tolerance at the output generally is less than the tolerance of the individual components. For instance if two 100 ohm resistors with 5% tolerance are paralleled, the 50 ohm resultant value has a tolerance of 3.5%. (5% / sqrt(2)) This is because the error of one resistor tends to compensate for the error of the other. When the components have different values or different tolerances or contribute different amounts to the output tolerance, the output tolerance is more difficult to calculate.
 
  • #57
I've shyed away from Excel because of the formula presentation in the earlier versions. I don't know if it's changed any. Unfamiliarity has something to do with it too.

I've played around with resistor values, and your values seem to be the near optimum trade-off between ADC resolution error and input nonlinearity error.

I looked over Wikipedia's Central Limit Theorem. It's hard to see if any of the contents pertains to combination of errors. Would you know how to calculated the combined error of two resistors in parallel of variable values?
 
  • #58
I was working at Motorola at the time they introduced six sigma around 1984 and discovered this effect trying to characterize circuits in terms of sigma. This is really the same thing as doing sensitivity analysis and finding that some components contribute a lot more to the output tolerance than others. When I mentioned it to my brother-in-law who has a PhD in statistics, his reaction was to the effect of, "isn't that obvious?" I never did pursue it further.
 
  • #59
skeptic2 said:
I was working at Motorola at the time they introduced six sigma around 1984 and discovered this effect trying to characterize circuits in terms of sigma. This is really the same thing as doing sensitivity analysis and finding that some components contribute a lot more to the output tolerance than others. When I mentioned it to my brother-in-law who has a PhD in statistics, his reaction was to the effect of, "isn't that obvious?" I never did pursue it further.

I work for a high tech company manufacturing certain test instruments. We set our specs based on 3 sigma criteria. Just about once a month I have to put on my statistian's hat to crunch all the variances and means across 3 different variables. Who knew statistics would be so helpful, I only wished I stayed awake in class.
 
  • #60
skeptic2 said:
...For instance if two 100 ohm resistors with 5% tolerance are paralleled, the 50 ohm resultant value has a tolerance of 3.5%. (5% / sqrt(2)) This is because the error of one resistor tends to compensate for the error of the other. When the components have different values or different tolerances or contribute different amounts to the output tolerance, the output tolerance is more difficult to calculate.

I did a little preliminary work in MS Word combining sources of independent error to obtain total error for sum, product, reciprocals, and parallel resistors too. It's not as turn-key as I was hoping--at least not yet.

For the two equal resistors in parallel, I obtained your value-- 3.5% for 5% parts.

In general, where epsilon is relative error (percent error/100), and

[tex]R_{parallel}= \frac{R_1 R_2}{R_1 + R_2}[/tex]

[tex]\epsilon_{parallel} = R_{parallel}\sqrt{ \frac{\epsilon_{1}{}^2}{R_{1}{}^2} + \frac{\epsilon_{2}{}^2}{R_{2}{}^2} [/tex]


Taking exponents of temperature could be more difficult.

Maybe I should start a thread on this topic, what to you think?
 
Last edited:
  • #61
rusty009 said:
How did you calculate the error ?

The error in the circuit has about four contributing factors:

The tolerance of the bias resistor, or bias circuit
The error of resistance with respect to temperature of the thermistor itself
The curve fitting error you are asking about
The step resolution error of the ADC

The curve fitting error may be reduced by chosing a different curve other than a straight line approximation to fit it to, and/or preforming a regressive analysis (least-squares fit).

The ADC error is usually quoted by the manufacture as 1/2 step over the span. I'd use an error value of one step to be practical.

The tolerances of the input circuity will tell us the error in the voltage actually applied to the ADC. This involves doing a little math--

We need to find the variation of the voltage as a function of temperature and bias resistor.

Given
[tex]V = F(R_b,T) \ ,[/tex]
then
[tex]\delta V = \frac {\partial F(R_b,T)}{\partial T}\delta T +\frac {\partial F(R_b,T)}{\partial R_b} \delta R_b\ .[/tex]

[itex]\delta V, \ \delta R_b, [/itex] and [itex]\delta T [/itex] represent absolute error. We need relative error (And we need to represent relative error as vectors.)

[tex]\hat{ \epsilon}_{V} = \delta V / V[/tex]

[tex]\hat{ \epsilon}_{R} = \delta R_b / R_b[/tex]

[tex]\hat{ \epsilon}_{T} = \delta T / T[/tex]

I could have written [itex]\delta T[/itex] and [itex]\delta R_b[/itex] as vectors, but the form of the equation may already be somewhat unfamilar to begin with.

We are assuming that the errors of the independent variables are independent. The error in the resistor is independent of the error in the thermistor. Abit, [itex]\hat{ \epsilon}_{R} [/itex] and [itex]\hat{ \epsilon}_{T} [/itex] would add like perpendicular vectors. [itex]\hat{\epsilon_{V}}[/itex] , on the other hand is some combination of these vectors, and points-off in a direction within the plane spanned by these two other vectors.

The norm (magnitude) of the vector [itex] \hat{\epsilon_{V}}[/itex] is the relative error in voltage to the ADC input. In general, the form of the result will involve a square root.

[tex]\epsilon_{V} = C \sqrt{ A \epsilon_{R_b}\ ^{2} + B\epsilon_{T}\ ^{2} }[/tex]

where A, B and C are constants to be determined by applying the above procedure.
 
Last edited:

Similar threads

  • Electrical Engineering
Replies
22
Views
3K
Replies
8
Views
1K
Replies
55
Views
3K
Replies
2
Views
309
  • Electrical Engineering
Replies
32
Views
2K
  • Electrical Engineering
Replies
22
Views
2K
  • Electrical Engineering
Replies
20
Views
447
  • Engineering and Comp Sci Homework Help
Replies
34
Views
2K
  • Electrical Engineering
Replies
23
Views
3K
  • Electrical Engineering
Replies
11
Views
1K
Back
Top