Calculating NTC temperature

WBahn

Joined Mar 31, 2012
29,979
Not too comfortable. But if I get the formula(s) and where to find the starting numbers, I'd like to try. :)
One reference for the Steinhard-Hart equation gives:

\(
\frac{1}{T} = A\;+\;B\ln(R)\;+\;C\ln^2(R)\;+\;D\ln^3(R)
\)

Now, I hate this equation because the units aren't consistent, specifically, you can't take the logarithm of anything with units. We could normalize this away pretty easily by simply dividing each of the R's by Ro=1Ω, but my understanding is that if you normalize the equation around the center of your range of interest (or at least something that is close to your range), then you will tend to get something that is a better fit over that range.

\(
\frac{1}{T}\;=\;A\;+\;B\ln \left(\frac{R}{R_0}\right)\;+\;C\ln^2\left(\frac{R}{R_0}\right)\;+\;D\ln^3\left(\frac{R}{R_0}\right)
\)

So, pick four temperatures, T_0 through T_3, and measure the resistances, R_0 through R_3, at those temperatures. Chose T_0 to be the one you are normalizing to. You then have the following four equations:

\(
\frac{1}{T_0}\;=\;A\;+\;B\ln \left( \frac{R_0}{R_0} \right) \;+\;C\ln^2 \left( \frac{R_0}{R_0} \right) \;+\;D\ln^3 \left( \frac{R_0}{R_0} \right)
\;
\frac{1}{T_1}\;=\;A\;+\;B\ln \left( \frac{R_1}{R_0} \right) \;+\;C\ln^2 \left( \frac{R_1}{R_0} \right) \;+\;D\ln^3 \left( \frac{R_1}{R_0} \right)
\;
\frac{1}{T_2}\;=\;A\;+\;B\ln \left( \frac{R_2}{R_0} \right) \;+\;C\ln^2 \left( \frac{R_2}{R_0} \right) \;+\;D\ln^3 \left( \frac{R_2}{R_0} \right)
\;
\frac{1}{T_3}\;=\;A\;+\;B\ln \left( \frac{R_3}{R_0} \right) \;+\;C\ln^2 \left( \frac{R_3}{R_0} \right) \;+\;D\ln^3 \left( \frac{R_3}{R_0} \right)
\)

Now, note that by choosing this normalization, you get 'A' for free since Ro/Ro=1 and ln(1)=0. So A = 1/To.


\(
\frac{1}{T_0}\;=\;A
\;
\frac{1}{T_1}\;-\;\frac{1}{T_0}\;=\;B\ln \left( \frac{R_1}{R_0} \right) \;+\;C\ln^2 \left( \frac{R_1}{R_0} \right) \;+\;D\ln^3 \left( \frac{R_1}{R_0} \right)
\;
\frac{1}{T_2}\;-\;\frac{1}{T_0}\;=\;B\ln \left( \frac{R_2}{R_0} \right) \;+\;C\ln^2 \left( \frac{R_2}{R_0} \right) \;+\;D\ln^3 \left( \frac{R_2}{R_0} \right)
\;
\frac{1}{T_3}\;-\;\frac{1}{T_0}\;=\;B\ln \left( \frac{R_3}{R_0} \right) \;+\;C\ln^2 \left( \frac{R_3}{R_0} \right) \;+\;D\ln^3 \left( \frac{R_3}{R_0} \right)
\)

Everything above, except the B, C, and D, are just numbers that you can calculate so that you have three equations of the form:

\(
b_1B\;+\;c_1C\;+\;d_1D=a_1
\;
b_2B\;+\;c_2C\;+\;d_3D=a_2
\;
b_3B\;+\;c_3C\;+\;d_2D=a_3
\)

which are three linear equations in B, C, and D.
 

Thread Starter

nerdegutta

Joined Dec 15, 2009
2,684
Before we jump in we have to look at the details and do some analysis.

What is your temperature range of interest? I will assume -20 to +55C for now.
What is your target resolution? I will assume 0.5C is good enough.

Are you building one unit or planning on multiple?
If you are planning to manufacture and market a number of units I would aim for no calibration requirement. Hence I would choose at minimum a 1% component.
If you are just building one unit for the fun of it then you can plan on calibrating the single unit. Do you have an accurate thermometer handy? Analog or digital?

We can use the manufacturer's data sheet to do some initial analysis.
Do you have Matlab? Otherwise we will have to resort to Excel spreadsheet.
-20 - +55 is just fine.
0.5 is also fine.
I'm building one or two, and maybe integrate it in some other ideas/projects I have.
I got one thermometer at hand, but I'm not sure how accurate it is. I've been using it for years, in my living room, so I think it's OK.
Digital.
I don't have Matlab, but I got Openoffice Spreadsheet.
So, pick four temperatures, T_0 through T_3, and measure the resistances, R_0 through R_3, at those temperatures. Chose T_0 to be the one you are normalizing to. You then have the following four equations:
For temperature resistance, the tables in the datasheet would be OK?
 

WBahn

Joined Mar 31, 2012
29,979
For temperature resistance, the tables in the datasheet would be OK?
You can do that if you want, but you are then stuck with calculating the temperaure based on the assumption that YOUR thermistor matches the ideal thermistor and you know you are only within 10% and that this equates to about ±2.5°C of uncertainty (a 5°C window). In an earlier post you gave the impression that the fact that the two thermometers didn't real equally was troublesome and you indicated that you wanted more like ±0.5°C (and it still seems an open question whether the thermometer you are comparing it to performs within those limits).

If you want this level of performance, you are going to need to calibrate YOUR thermistor and, if you change thermistors, you are going to have to recalibrate for the new one.
 

WBahn

Joined Mar 31, 2012
29,979
-20 - +55 is just fine.
0.5 is also fine.
It's not a question of what is "just fine", it is a question of what is needed. If you say that -20°C to +55°C is "just fine" when, in actuality, you really only need 10°C to +40°C (or whatever), then you are potentially eliminating options that could have given you better performance over the range that really counts or making the solution more difficult and/or more expensive than it needs to be. The same thing with the accuracy spec. If you want 0.5°C when 2°C would actually be acceptable, you are buying trouble you could have avoided.
 

Thread Starter

nerdegutta

Joined Dec 15, 2009
2,684
It's not a question of what is "just fine", it is a question of what is needed. If you say that -20°C to +55°C is "just fine" when, in actuality, you really only need 10°C to +40°C (or whatever), then you are potentially eliminating options that could have given you better performance over the range that really counts or making the solution more difficult and/or more expensive than it needs to be. The same thing with the accuracy spec. If you want 0.5°C when 2°C would actually be acceptable, you are buying trouble you could have avoided.
OK. I'll be more specific.

One application I was thinking of having in my boat, so temperature range would be something in the range of -5°C to +40°C.

The other application will need to measure temperature from -30°C to +10°C. It will be used during the winter.

For accuracy, I want it to be +/- 0.5°C.
 

Thread Starter

nerdegutta

Joined Dec 15, 2009
2,684
OK, so...

Chose T_0 to be the one you are normalizing to.
T_0 = 25°C
T_1 = 15°C
T_2 = -5°C
T_3 = 40°C

From the datasheet I'll find:
25°C = 10000Ω

Which get's us this:

R_0 = 10000
R_1 = 15618
R_2 = 41505
R_3 = 5372

Formula:
\(
\frac{1}{T_1}\;-\;\frac{1}{T_0}\;=\;B\ln \left( \frac{R_1}{R_0} \right) \;+\;C\ln^2 \left( \frac{R_1}{R_0} \right) \;+\;D\ln^3 \left( \frac{R_1}{R_0} \right)
\)

With inserted numbers:

\(
\frac{1}{15}\;-\;\frac{1}{25}\;=\;B\ln \left( \frac{15618}{10000} \right) \;+\;C\ln^2 \left( \frac{15618}{10000} \right) \;+\;D\ln^3 \left( \frac{15618}{10000} \right)
\)

... and so on ...

Would this be correct?
 

MrChips

Joined Oct 2, 2009
30,716
I fully agree with WBahn. You can save yourself a lot of trouble if you choose specs to suit the situation.

For a boat, +/- 1C is probably sufficient.
For this, let us set the specs at -10 to +40C +/- 1C
This is a range of 50C with 2% resolution, i.e. 6 bits of data, just to put things into perspective.

Next, I will do some numerical analysis using the manufacturer's data provided.
I will show the data from -55 to +55C even though we only need from -10 to +40C (so that I don't have to repeat the table for the other application).

-55.0 878900
-50.0 617590
-45.0 439340
-40.0 316180
-35.0 230060
-30.0 169150
-25.0 125550
-20.0 94143
-15.0 71172
-10.0 54308
-5.0 41505
0.0 32014
5.0 25011
10.0 19691
15.0 15618
20.0 12474
25.0 10000
30.0 8080
35.0 6569
40.0 5372
45.0 4424
50.0 3661
55.0 3039


Next, I will show what the data looks like graphically using R, log(R) and 1/R vs temperature. Keep in mind that later we have to switch the axes so that temperature becomes the y-axis.

Following that we will put the thermistor into two different circuits and show the results.
 

MrChips

Joined Oct 2, 2009
30,716









Three relationships shown:

  1. R vs temp
  2. 1/R vs temp
  3. log(R) vs temp
Graph 3 shows that log(R) vs temp is almost a straight line.
Over a limited temperature range a simple straight line gives a very good fit.
(sorry, I forgot to change the y-axis labels)
 

MrChips

Joined Oct 2, 2009
30,716
Funny! no, I have no cats, but usually my wife comes and pushes all my buttons.

Yes, I'm using Matlab because that's easier for me. I will be doing the curve fitting later and Matlab makes it really easy.

I have two more graphs to come but maybe later today, way past your bedtime.
 

WBahn

Joined Mar 31, 2012
29,979
OK, so...
With inserted numbers:

\(
\frac{1}{15}\;-\;\frac{1}{25}\;=\;B\ln \left( \frac{15618}{10000} \right) \;+\;C\ln^2 \left( \frac{15618}{10000} \right) \;+\;D\ln^3 \left( \frac{15618}{10000} \right)
\)

... and so on ...

Would this be correct?
Except for the part where you have to use an absolute temperature scale (i.e. Kelvins). So the T you need to use is obtained by adding 273.15K to your Celsius value.

I've see a few places where the ln² term is usually small enough to be neglected. If you are normallizing to something within your temperature range, it is very possible that the ln³ will be small enough over the range to be neglected.
 

Thread Starter

nerdegutta

Joined Dec 15, 2009
2,684
I have two more graphs to come but maybe later today, way past your bedtime.
:)
Which is 21:30, and lights out at 22:00.


Except for the part where you have to use an absolute temperature scale (i.e. Kelvins). So the T you need to use is obtained by adding 273.15K to your Celsius value.

I've see a few places where the ln² term is usually small enough to be neglected. If you are normallizing to something within your temperature range, it is very possible that the ln³ will be small enough over the range to be neglected.
Small - Like this value

Rich (BB code):
temperature=1 / (0.001129148 + (0.000234125 * temperature) + (0.0000000876741 * temperature * temperature * temperature));
 

WBahn

Joined Mar 31, 2012
29,979
Small - Like this value

Rich (BB code):
temperature=1 / (0.001129148 + (0.000234125 * temperature) + (0.0000000876741 * temperature * temperature * temperature));
Shouldn't one/some of those "temperature"s be resistance?

Notice that the term you highlight is multiplying (tempurature)³. There is no square term, probably because it was small enough to be neglected entirely.
 

MrChips

Joined Oct 2, 2009
30,716
Let's put the thermistor into your voltage divider circuit as shown:



Assuming the fullscale reading of the 10-bit ADC is 1023 with 5V input, the relationship between temperature and ADC counts is as shown:





But what we really want is the inverse, i.e. ADC counts on the x-axis and temperature on the y-axis as follows:




You can see that the curve is reasonably straight from about 200 to 600 counts, around -5 to 32C.

Here we can estimate the slope as 37C/400 = 0.1C per count. Hence we have sufficient resolution. A straight line fit will probably work well. We can easily calculate the deviation over the chosen temperature range for a straight line fit.

Also, while the curve is straight from -5 to 30C, it is not so good at -30C. For this we can possibly improve it by changing the value of R2.
 
Last edited:

MrChips

Joined Oct 2, 2009
30,716
Here is the fit to a straight line for the temperature range -5 to 40C.




Temp = 0.0943 * ADC_COUNTS - 23

Here are the errors (deviation from the curve):

ADC Counts | Temperature C | Calculated Temp C | Error
199 | -5 | -4.2| 0.8
243 | 0 | -0.1| -0.1
292 | 5 | 4.5| -0.5
345 | 10 | 9.5| -0.5
399 | 15 | 14.6| -0.4
455 | 20 | 19.9| -0.1
511 | 25 | 25.2| 0.2
566 | 30 | 30.4| 0.4
617 | 35 | 35.2| 0.2
665 | 40 | 39.7| -0.3

Except for the -5C point all the points are within 0.5C
 
Last edited:

osx-addict

Joined Feb 9, 2012
122
Dang -- you guys are GOOD at this stuff! Where were you guys when I was using my little Arduino to use an automotive thermistor to monitor transmission fluid temps and trying to find the right conversion logic to make heads or tails of my ADC reading! :D
 

MrChips

Joined Oct 2, 2009
30,716
Notice I didn't start by building any hardware or writing code. I started by analyzing the manufacturer's data supplied and seeing what would result. This is all part of proper systems engineering and doing due diligence.
 

MrChips

Joined Oct 2, 2009
30,716
Now suppose you didn't want to use floating point arithmetic or you wanted to write the code in assembler. How would you calculate

temp = 0.0943 * ADC_COUNTS - 23

You can scale 0.0943 by multiplying with 65536 = 6180

The equation becomes:

temp = 6180 * (ADC_COUNTS)/ 65536 - 23

Thus multiply ADC_COUNTS by 6180 using 32-bit precision and select the upper 16 bits of the result, then subtract 23.

To adjust the equation in order to calibrate for gain and offset shifts, all you have to trim are the two values 6180 and 23.
 
Last edited:
Top