The project offers support for NTC thermistor calculations. The Steinhart-Hart equation is a mathematical model for these thermistors that seems to fit for a wide range of temperatures with high precision. Software to calculate the characteristic Steinhart-Hart coefficients based on temperature-resistance tables for given thermistors as well as functions allowing conversion of temperature values to resistance and vice versa is provided.
A model for the resistivity of a semiconductor as a function of the temperature was found by Steinhart and Hart 1968 ([1]). The Steinhart-Hart law describes the absolute temperature T (in Kelvins) as a function of the NTC thermistor's resistivity (in Ω) according to the formula
^{1}/_{T} = a_{0} + a_{1} · ln r + a_{3} · (ln r)^{3} |
The figure below shows the typical graph of an NTC thermistors characteristic, giving the reciprocal temperature (in 1 / K) over the natural logarithm of the resistance (in Ω).
The constants a_{0}, a_{1} and a_{3}, also called Steinhart-Hart coefficients, vary depending on the type of thermistor. To support developer when creating temperature measurement applications, thermistor manufacturer often supply these constants for their products. They also publicate tables where resistivity of thermistor products for a wider range of temperature values are listed.
This project provides software to
Apart from the standard Steinhart-Hart equation other forms have been found. For application with lower CPU power a simplified form of the Steinhart-Hart equation can be used.
^{1}⁄_{T} = a_{0} + a_{1} · ln r |
On the other hand a quadratic term can be inserted into the formula to increase accuracy giving the extended Steinhart-Hart equation
^{1}/_{T} = a_{0} + a_{1} · ln r + a_{2}· (ln r)^{2} + a_{3} · (ln r)^{3} |
An introduction to thermistors and the Steinhart-Hart polynom can be found at Wikipedia [2].
Software is provided by this project for the calculations given in section algorithms. The classes / modules can be used for
The latter can be done for standard, simplified or extended Steinhart-Hart polynom.
Download the archives for C or Java here.
For Java the following classes are available
Class | Description |
---|---|
NtcException | Exception used in this thermistor framework |
NtcTable | Represents an T-R table for an NTC thermistor. |
NtcThermistorModel | Represents an NTC thermistor modelled using the Steinhart-Hart polynom ^{1}/_{T} = a_{0} + a_{1} · ln r + a_{3} · (ln r)^{3}. The model will be created using a NtcTable object. It provider methods to read the themistor name, get the NtcTable object, get the Steinhart-Hart coefficients as well as methods for conversion from temperature to resistance and vice versa. |
NtcThermistorExtendedModel | Represents an NTC thermistor modelled using the extended Steinhart-Hart polynom ^{1}/_{T} = a_{0} + a_{1} · ln r + a_{2}· (ln r)^{2} + a_{3} · (ln r)^{3}. |
NtcThermistorSimplifiedModel | Represents an NTC thermistor modelled using the simplified Steinhart-Hart polynom ^{1}⁄_{T} = a_{0} + a_{1} · ln r. Derived from NtcThermistorModel, provides the same methods. |
Note: Generics are used in the project so Java 5 or higher is required according to that.
A small test class NtcTest is part of the package together with an example text file containing an T-R table of a theoretical NTC (simu.txt). To make developers life easy the whole application is deployed as an (executable) jar file containing all sources, classes and a manifest file with main class NtcTest.
After download the test application can be invoked by
java -jar thermistor.0.1.jar
The output produced can be seen here.
Three C modules are available
Module | Description |
---|---|
coeff.c | Program used to calculate Steinhart-Hart coefficients from an NTC table (given as text file). |
ttor.c | Temperature to resistance calculation. |
rtot.c | Resistance to temperature calculation. |
For usage under Windows they have been compiled (using Cygwin's C compiler). For other OS please compile them with your system C-compiler. An example text file containing an T-R table of a theoretical NTC (simu.txt) is also provided for testing purposes.
Example outout of the "coeff" program is given here.
Based on a measured resistance value of an NTC thermistor the extended Steinhart-Hart equations allows a simple calculation of the temperature
^{1}/_{T} = a_{0} + a_{1} · ln r + a_{2}· (ln r)^{2} + a_{3} · (ln r)^{3}
Here r is the resistance in Ω and T the absolute temperature in K (K = Kelvin). With absolute zero T_{abs}= -273.15 ° C, the formula for the temperature t in °C finally leads to
t = 273,15 ° C + [ a_{0} + a_{1} · ln r + a_{2}· (ln r)^{2} + a_{3} · (ln r)^{3} ]^{-1}
By setting appropriate coefficients to zero, the calculation according to the simplified or standard Steinhart-Hart equation can be done as well.
To calculate resistance values in Ω from temperature in °C the root r of the extended Steinhart-Hart equation must be found (for the standard polynom simply set a_{2}=0 in the formulas below)
^{1}/_{T} = a_{0} + a_{1} · ln r + a_{2}· (ln r)^{2} + a_{3} · (ln r)^{3}
with y = ln r, we get
^{1}/_{T} = a_{0} + a_{1} · y + a_{2} · y ^{2} + a_{3} · y ^{3}
We introduce the substitutions
T = t + T_{abs}
b = a_{2} / a_{3}
c = a_{1} / a_{3}
d = (a_{0} - 1 ⁄ T) / a_{3}
p = c - ⅓· b^{2}
q = ^{2}/_{27} · b^{3} - ^{1}/_{3} · b · c + d
u = [ -q/2 + ( q^{2}/4 + p^{3}/27 )^{½} ]^{⅓}
v = [ -q/2 - ( q^{2}/4 + p^{3}/27 )^{½} ]^{⅓}
getting
r = e^{u + v - b/3}
for the resistance r (in Ω) of a given temperature t (in ° C).
Sometimes calculation of coefficients is done using special temperature values. Inserting four value pairs in the range of interest into the extended Steinhart-Hart poylonm leads to a system of linear algebraic equations (Three value pairs for the standard Steinhart-Hart polynom). Temperatures typically used are for example 0° C, 15° C, 25° C and 70° C. By solving this system the values for a_{0}, a_{1}, a_{2} and a_{3} can be determined.
A better approach is the mathematical optimization technique called ordinary least squares (OLS), that was introduced by Carl Friederich Gauß in 1801. Details about the theory of OLS are given at Wikipedia [3] or MathPlanet [4].
If the function that is approximated is a polynom, theory of vector spaces, scalar products and orthonormal bases eases the calculation. Given a list with n temperature-resistance pairs
(r_{0}, t_{0}), (r_{1}, t_{1}), ..., (r_{n-1}, t_{n-1})
(where n should be at least 3), the question for best fitting of the Steinhart-Hart coefficients leads to the minimization of
_{ n-1} | ||
sum := | Σ | [ t(r_{i}) -t_{i }]² |
^{i=0} |
where t_{i} is the i-th temperature value and t(r_{i}) is the calculated temperature according to the polynom.
This optimization requires a small mathematical excursion. For a positive integer n and given abscissa values x_{0}, x_{1}, ..., x_{n-1} the polynoms with degree ≤ n build a vector space V. On V a scalar product can be defined by
_{ n} | ||
[ p, q ] := | Σ | p(x_{i}) · q(x_{i }) |
^{i=0} |
By
the scalar products makes V a normed space. For a function f with ordinate values
y_{i }:= f(x_{i})
for i = 0, .., n-1 there is exactly one polynom p_{f} in V that matches the function in the coordinates (x_{0}, y_{0}), (x_{1}, y_{1}), ..., (x_{n-1}, y_{n-1}).
If a poisitve integer m, with m ≤ n, is given, all polynms of degree ≤ m build a sub space U of V. The question for the best approximation of f by polynoms from U is equivalent to the best approximation of p_{f} by polynom from U in respect to | |.
_{ n-1} | _{ n-1} | ||||||
s = | Σ | [ u_{f}(x_{i}) -y_{i }]² | = | Σ | [ u_{f}(x_{i}) -p_{f}(x_{i})]² | = | |u_{f} -p_{f}| |
^{i=0} | ^{i=0} |
Answering the last question turns out to be very easy, if an orthonormal base { u_{1}, u_{2}, ..., u_{m} } of U is given. For p_{f} the best approximation u_{f } evaluates as
_{m} | ||
u_{f} = | Σ | [ u_{i}, p_{f }] ·u _{i} |
^{i=1} |
If for example an R-T table with value pairs from 0° C up to 100° C in steps of 1° C is given, the polynom p_{f }has degree 101 (!). Fortunately it must not be found, in order to find the Steinhart-Hart coefficicents and thus finding u_{f}. Starting with the canonical base { v_{1}=1, v_{2}=x, v_{3}=x², v_{4}=x³ } of U, an orthonormal base { u_{1}, u_{2},u_{3}, u_{4} } can be evaluated. After that, the coefficients of u_{f} are calculated by the sum stated above.
The coordinates
(x_{0}, y_{0}), (x_{1}, y_{1}), ..., (x_{n-1}, y_{n-1})
are calculated from the temperature-resistance pairs as
x_{i} = ln r_{i}
y_{i} = 1/(t_{i} - T _{abs})
for i = 0, .., n-1.
The orthonormal base of U is evaluated recursively. We set
u_{1}=v_{1}=1
and
_{i-1} | ||
w_{i} = v_{i }- | Σ | [ u_{j}, u_{i }] ·u_{i} |
^{j=1} |
u_{i}=w_{i }/ |w_{i}|^{1/2}
for i = 2, ..., m = 4.
With this base we can calculate u_{f} as
_{m} | ||
u_{f} = | Σ | [ u_{i}, p_{f }] ·u_{i} |
^{i=1} |
and determine the Steinhart-Hart coefficients from this equation. (Note that the scalar product can be calculated without knowing p_{f} as stated above).
The software of this project is published under the GNU Lesser General Public License.
[1] J.S. Steinhart and S.R. Hart, “Calibration Curves for Thermistors,” Deep Sea Research, Vol. 15, 497-503, 1968.
[2] Thermistors, NTCs and Steinhart-Hart equation on Wikipedia