frustrated finding steinhart ntc coeffs

Go To Last Post
26 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am using an avr to read the ntc thermistor, but the problem is sort of general electronics... I have tried a couple of online applets where you type in t1 t2 and t3 in C, and r1 r2 and r3 of the thermistor at these temps, and it spits out a,b,c coeffs for the steinhart eqn. Prob is my data gives a negative value for coeff c.... all manufacturers tables have a,b and c positive. Cornerstone sensors has eqns for a,b,c coeffs, and that gave - numbers too, so I thought they had a typo. Guess I'll take the temp data again tomorrow with a diff thermometer.... but this is really GIGO... when I was calculating temp using the bad coeffs, 212 on the 'real' hw thermometer was calcing as 176 from the eqn. Anyone have a favorite way to get the steinhart coeffs for your NTC temp sensor?

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I always relied on what the manufacturer provided and never bothered to try to measure.

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The boss has a 79 MGB and I want to use the factory temp sensor, and I have taken the lo,med and hi temp resistance readings, just want to find an applet that will spit out the a,b,c coeffs all positive. STandby till tomorrow when I retake the data at work...

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hmmm ...

Lucas stuff. Best electrical hardware that ever fell off a car!

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Bob, check my mini tutorial about temperature measurement at the tutorials forum. If you have the DS of the NTC, then it would be quite easy.

Guillem.
"Common sense is the least common of the senses" Anonymous.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
Lucas stuff. Best electrical hardware that ever fell off a car!

Or motorcycle!

Lucas, Prince of Darkness!

Tom Pappano
Tulsa, Oklahoma

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I did the following
in excel make up 6 columns, add/calculate the data

  A,        B,    C,    D,        E,       F
Tmpr (C),  T(K), 1/T, Therm(R), log(R), Log(R)^3

Now do a multivariable regression (array operation over 3 cells), in my case for 201 data points

=LINEST(D3:D204,E3:F204)

Excel generates 3 values, C,B,A from left to right

I got different A and B results to the manufacturer but my errors were almost 0. Unless I got the Steinhart-Hart equation wrong I cant understand why I get a perfect fit to their data with a different co-efficients, and they calculate the data from the equation with different values...

Nonetheless, the method should work

Cheers

Klave

edit) You could add the (Log(R))^2 co-efficient if you wanted to, I left it out

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for that idea Klave. I put my temp/resistance data into a couple of java applets, but they kept spitting out a negative value for the c coeff, and all mfgr data has positive coeffs. I have a call in to Wells Mfg Co to get the data for the particular sensor I was trying to characterise, but will try your excellent excel suggestion. You Canucks from the Great White North all seem pretty smart to us dull old boys down south here. Must have a lot of time to think during the long cold winters?

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Just some stupid question from an electron pusher like me, that is a noob in soft questions: why use Steinhart&Hart equation (with logs?) when a simple LUT and some linear interpolation can give you the same results (with less computational resources)?

Guillem.
"Common sense is the least common of the senses" Anonymous.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

How many line segments do I need to get within 1 deg F? I guess the max error is right between data points? I already have the fp stuff in the rom, so thats not the show stopper. Lets say I have a dozen points in the table. How do I index into it? Do I need to start at the beginning and compare values until I find an x that is between two x[i] and x[i+1] values? So A dozen fp compares has a cost of 12.... still less than two lns and a pow I assume, but there is a point that the search cost equals the direct solve cost.

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I suggest a quadratic fit or cubic spline, both work ok with integers and fill the curve nicely between points, especially at the one end where the rate of change increases.

here's a link for the quadratic
http://www.johndcook.com/quadratic_interpolator_help.html

Quadratics can be badly behaved compared to a spline but the thermistor curves are gentle and smooth and will be interpolate nicely

The linear fit can be done with non equal steps so that you get more steps where the line curvatue is greater. Of course with unequal steps you now have to store both the co-ordinates.

I haven't tried to calculate the amount of flash used in one method over the other but I imagine the linear fit, with more points, is the smallest flash size.

If you already have Fpt going, this process works like a charm:-
1)Model the circuit (resistor and thermistor) in excel over your full temperature range. I go the whole way, calculating ADC value for any temperature reading.
2) do a 6th order polynomial fit to the data in excel (a trendline on a chart is the easiest)
3) Copy the co-efficients of the polynomial
4) Implement the equation directly.

This will give you accuracy better than 0.2degrees C. You will have to calibrate at some temperature. You only store 7 FPt values and it's good for the whole range. You may find a polynomial of lower order is accurate enough.

Cheers

Klave

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I used this article to design a NTC interface:
http://electronicdesign.com/Articles/Index.cfm?AD=1&ArticleID=4868

Very simple, but might not be accurate enough for your application.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Bob: https://www.avrfreaks.net/index.p...

Table is about 12 points (from -40 to 80 in 10 ºC steps), and accuracy is well below 0.5ºC, resolution in 0.1º for the central range. With some oversampling it can be improved to 0.1º from 0º to 80º, depending on your bias resistor. This with linear interpolation.

Adding some calibration and regression, you can achieve 0.1ºC accuracy (0.18ºF), but this is out of that little tutorial.

I had used this technique with about 30 point to 'linearize' a K type TC, with 1ºC (16bit ADC, though)precission from -150ºC to >1200ºC, and 0.1ºC resolution.

Guillem.
"Common sense is the least common of the senses" Anonymous.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

bobgardner wrote:
How do I index into it? Do I need to start at the beginning and compare values until I find an x that is between two x[i] and x[i+1] values? So A dozen fp compares has a cost of 12.... still less than two lns and a pow I assume, but there is a point that the search cost equals the direct solve cost.

Instead of searching through the table, if your points a equidistant, transform (chosen such that each point is 1 unit apart) your input into the index value (char i= x/34 for eg.) then grab y(i) and y(i+1) and do your interpolation then.
No compares then but a transformation, which can be quick if it's just a shift.

Ed

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The Hart-Steinhart equation is what I used for a battery charger application, but I crunched it externally in VB, and generated lookup tables for the AVR. WAY faster, if you can afford the space.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I've done quite a bit of thermistor work, and have never done the whole equation bit.

With a known thermistor and an "area of interest" in the curve, using a bias resistor can pull the area of interest to linear (or close enough). With a bias resistor and many thermistors a fraction of a degree F can be obtained with just straight linear interpolation--the max error at any point on the linear area is less than 1/2 degree F.

We've got one app where we switch bias resistance values to get two linear ranges--it works pretty cool.

I also like the bias resistor 'cause even with the equations the raw curve gets quite flat/steep at the ends and accuracy (the A/D reading) is suspect anyway--you can't get sub-1-degree when 1 A/D count might be multiple degrees.

Let me see if I can hunt out the spreadsheet discussion...

Lee
https://www.avrfreaks.net/index.p...
A fairly thorough discussion of the bias resistor method.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Looks like some of the following is redundant but here goes anyway

Steinhart Hart equation is a mathematical model that was found by fitting a curve to the data.
http://www.itsirl.com/Manuals/ntcstein.pdf

You can roll your own model.

Guillem's interpolation is an excellent tutorial and should be considered for any interpolation, not just temperature. I spent a weekend with it, comparing it to other methods of interpolation and decided that for relatively simple curves it is my first choice for the following reasons
-Easy to debug
-Easy to scale for increased precision
-Although it requires equally spaced co-ordinates, this means you only need to store only half of the co-ordinate pair so less flash (or eeprom) is used.
-curve does not need to be monotonic

I implemented one minor change
Identifying whether the lookup failed above or below, this allowed me to identify hardware failures and maybe even which component.

My temperature range is very wide, a single resistor did not cover the range on its own and it loses accuracy at one end or the other. I used two resistors. To select the high temperature range the IO port is set to output and a 1 is written to the port. To select low temperature range the port is set to high impedance input.

                       VCC
                        |
                       .-.
                       | |100K
                       | |
             10K       '-'
             ___        |
  IO port  -|___|--o----+
                   |    |
                   |    |
      ADC  <-------'   .-.
                       | |
                       | |33K Thermistor
                       '-'
                        |
                       GND
(created by AACircuit v1.28.6 beta 04/19/05 www.tech-chat.de)

This means I have 2 curves to fit. Now suddenly the amount of data increases so a quadratic fit, which needs fewer data points, may be more attractive. As it turns out, the curve was too ugly for a quadratic to fit with much fewer data points so I looked at
-uneven steps - less points but needs co-ordinate pairs
-Spline - better than quadratic, precision is harder to calculate but excel does all the work
-6th order polynomial - good if you have floating point, I never did try integers - will proably be OK

I always simulate the method in excel to evaluate the errors that I get, using the ADC precision and component tolerance too - no suprises that way. Be especially careful of steep curves, the error is always above or below depending on curve but the 1 lsb quantization offset may be in the same direction, this makes it worse. I hand trim these co-ordinates by 1 or more lsb's to reduce errors

BTW, the best way to evaluate a polynomial uses the old trick of not repeating the same calculation by Horner's scheme http://en.wikipedia.org/wiki/Horner_scheme

Klave

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

My temperature range is very wide, a single resistor did not cover the range on its own and it loses accuracy at one end or the other. I used two resistors. To select the high temperature range the IO port is set to output and a 1 is written to the port. To select low temperature range the port is set to high impedance input.

There is discussion on that in my link above. It [two bias values] worked quite well for me in an app--the primary bias gave me a linear curve over the range needed for fine control in the app. The secondary bias value gave me a coarse range (for overtemp--precision not needed) at the high end that was close enough to linear (no more than a couple degrees off) that I could just use linear.

In many apps, it isn't the absolute temperature reading that is important, but rather the change from a desired value or range. As long as you aren't at the flat/steep ends of the curve it works pretty well in practice.

Now, Bob is in the instrument game so he may need "real" readings.

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

We started out selling Boost/EGT combo gauges with a thermocouple for EGT. Obviously, I dont need an 1800 deg F thermocouple to read water, oil and intake air temp, some I'm adding Read NTC to the repetoire. Expanding the product line (plug: mcnallyelectronics.com)

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Guillem Planisi wrote:
Adding some calibration and regression, you can achieve 0.1ºC accuracy (0.18ºF), but this is out of that little tutorial.

How do you calibrate with your tutorial method? Do you recreate all the calculations inside the controller, or do you read the values manually, recalculate in your PC and then program the new ADC values in the uC?

Felipe Maimon

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I had a calibration tool, that plugs three different known values to the input, I measure the ADC values obtained, and then I applied a regression curve calculated from two points (at 25 and 75% of the measuring range). If this regression curve fits for the third value (at 50%) within a certain margin (0.1ºC), then it passes the test, I save the regression values calculated into the EEPROM, and the calibration is finished.

This worked very well, but it only accounts for the load resistor (thus you would need two sets for two different load resistors) and any ADC and VAcc deviation. This way, I could assure about 0.5% precission in the central range, that is 0.3% gave to me by the NTC manufacturer, plus 0.2% due nonlinearities and other variables. After about 500 tests performed on the whole range, we find that it is better than 0.1% due nonlinearities and other variables, and that regular manufacturer is about 0.2%.

But I'm talking from top of my head, and I didn't work for this company for many months now. The calibration process is a subject of another possible extensive and advanced tutorial, that will include real temperature calibration, that is how one can achieve <0.1ºC precission along a good temperature range (with >10 bits ADC, though).

Guillem.
"Common sense is the least common of the senses" Anonymous.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Bob, see ILX Lightwave's application note Thermistor Calibartion and Steinhart-Hart Equation available in PDF from this link.

Also, you can download STEIN3.EXE from ILX Lightwave's website which will do a least-squares-fit for 4 or more data points. See this link.

Don

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

bobgardner wrote:
I am using an avr to read the ntc thermistor, but the problem is sort of general electronics... I have tried a couple of online applets where you type in t1 t2 and t3 in C, and r1 r2 and r3 of the thermistor at these temps, and it spits out a,b,c coeffs for the steinhart eqn. Prob is my data gives a negative value for coeff c....
Bob, just re-read your post and noticed that you're entering the temperature in Centigrade. The Steinhart-Hart equation is for temperature in Kelvin. Are the applets you're using converting from Centigrade to Kelvin?

Don

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm using a 3x3 solver that wants a1x + b1y + c1z = d1, a2x + b2y + c2z = d2, and a3x + b3y + c3z = d3. I use 1/Tk1,2,3 for the d1,2,3 on the right hand side, I use 1.0 for the a1,2,3, lnr1,2,3 for the bs, lnr1,2,3^3 for the cs, and hit the solve button. It spits out x,y and z which I guess are the Steinhart coeffs for that sensor. Now here is the part that might take some EE intuition: I'm computing the resistance of the sensor like this: I have a 220 ohm R from 5V to the sensor, other end of sensor to gnd. So I read the V between the 220 and the sensor, calc the I=(5-V)/220, then calc Rntc=V/I, which I use in the Steinhart eqn to get 1/Tk. Problem: if the sensor is cool and about 5K, the V is real close to 5V... might be losing sensitivity... only have 5mv per step on the a/d. Seems like if I use a 1 or 2k sense resistor, I lose even more res on the a/d. So what value of sense R should I use?

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Lee Theusch has posted a nice applet to calculate the resistor value. Anyway, the ballpark figure that I use is the sensor resistance at the temperature in the center of the range that you want to measure with bigger accuracy. So, if you want to measure, let's say 0-50º, and your sensor is 10K at 25º, then the load resistance should be 10K. Hope this helps.

Guillem.
"Common sense is the least common of the senses" Anonymous.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Klave wrote:
I got different A and B results to the manufacturer but my errors were almost 0. Unless I got the Steinhart-Hart equation wrong I cant understand why I get a perfect fit to their data with a different co-efficients, and they calculate the data from the equation with different values...

Maybe because you've used log, instead of ln? Just guessing...

[edit] Dont need to redo all the calculations with ln or log. Just check if your numbers are different by a factor of about 2.3 .

Felipe Maimon