Interpreting non-linear temperature thermistor value
Scott4
Posts: 45
1. I'm using an analog to digital converter to read the voltage across a thermistor used to measure engine water temperature. (see attached)
2. The thermistor temperature vs resistance curve is non-linear. (see attached)
3. I was thinking about using LOOKDOWN / LOOKUP but the steps would be in 10 degree increments.
4. I was also thinking about using linear interpolation but maybe there is a better way.
Can anyone suggest a good way of getting a one degree resolution?
2. The thermistor temperature vs resistance curve is non-linear. (see attached)
3. I was thinking about using LOOKDOWN / LOOKUP but the steps would be in 10 degree increments.
4. I was also thinking about using linear interpolation but maybe there is a better way.
Can anyone suggest a good way of getting a one degree resolution?
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
I for one would be interested in seeing an example.
linearVal = ( Kslope / ( nonLinearVal + Kyintercept ) ) - Koffset
You can check the curves in the Excel graphs to see if you are getting the interpolation you like. This saves on table reading/parsing, but may or may not give you the linearity you are looking for. The file was written for a Sharp IR detector, but can be used for any non-linear to linear conversion.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php
This particular program is for the thermistor that is in the Apogee environmental oxygen probe, and has a nominal resistance of 10kOhms at 25 degC. It is in series with a 25.5 kOhm precision resistor (included in the probe body). In the data logger (OWL2pe) the thermistor is connected to a 4.096 V reference, and the bottom of the 25.5 k resistor is connected to ground, and the junction goes to an input of a TLC2543 ADC. Voltage increases as temperature increases. The DATA in the table is the milliVolts is expected at -40, -35, ... and so on up to +85 degC. The program locates the present voltage in the table and then interpolates back to temperature. The program is set up to run in one slot of a BS2pe. If it runs in slot 0 (of any stamp), or if it is called with a cross-slot index of zero, it runs a test routine that shows current readings on the DEBUG screen. If it is called from some other slot, a slot index of 1 causes it to return Celsius (in units of 0.1 degree) in a word variable using an ADC channel stored in eeprom. If the calling slot index is 2, it uses a value passed in with the call to specify the ADC channel number (This project had to read several probes).
The spreadsheet generates the DATA statements for the program. The DATA in this example is entered at 5 degree Celsius increments. At the top are cells to enter the fixed resistance (25.5k in this case), and the reference voltage (4.096 V in this case). The spreadsheet is also useful for exploratory purposes to check for how much error you can expect, against a Steinhart-Hart or polynomial fit.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Depending on the way things are set up, isn't this the kind of thing for which it would make sense to simply have the BS2 report the raw data to PLX-DAQ, and have Excel do all the conversion? If I'm understanding it, that's what Zoot is suggesting. It must be easier to do that than to have the Stamp do the math.
My method (a space saver) uses the formula given to linearize a non-linear value (say from an IR ranger, thermistor, RCTIME value on a light sensor, etc). The thing is you need the three constants to plug in -- the Excel file lets you pre-calculate desired output value ranges, actual input readings, to generate the constants. These constants are used in the formula in Stamp Pbasic code.
For example, on two of my IR rangers, I took very accurate ADC readings at 10cm intervals, plugged the values into the Excel file, and calculated my three constants.
The table-based interpolation actually does the same thing, in a way, by going through a table of pre-defined data points, finding the closest match, then interpolating between those two points to get the closest value. Again, Dr. Allen's Excel file is used to *create* the original table of "ready-to-go" data points; those data statements are copied to the Stamp application to be read by the main program.
But, yes, if the data is being sent to a PC, doing it there would be fast.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php
Post Edited (Zoot) : 1/7/2010 9:52:38 PM GMT
-Mike
Edit: Oops, sorry! It looks like the Excel solution does the job.
In the end it may not matter -- I might argue that it is always beneficial to linearize sensitive input values in code, so that the app can *always* be tuned regardless of what sensors, circuitry or methods are used to acquire the input at the beginning.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php
It might be possible to implement the Steinhart-Hart equations on the Stamp, but I wouldn't want to tackle it. It involves the natural log and the natural log cubed of the resistance of the thermistor, added up with the specific coefficients to give the inverse of temperature. Not an easy thing to do on the Stamp. And PBASIC still has to calculate the resistance given a voltage divider, so there is more chance for cumulative error. I'd much rather do it as a direct table lookup with interpolation, and let Excel do the heavy lifting in advance.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Makes perfect sense! thanks! i was thinking of using a thermistor in a cabinet enclosure A/C controller using just rctime, acurracy would only need to be within 2-5 deg f. i think im gonna use an a/d converter now after some thought, probably a dual channel because i want to add a humidity sensor also.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Consequently you can also place a "virtual" 10K resistor in parallel with the Thermistor and mathematically calculate it in software.
R = 1 / [noparse][[/noparse] (1/Rt) + (1/10K) ]
Where:
Rt is the Thermistor resistance value
R is the linear resistance value
In the Attached Image, Rt is the 'top' resistance graph, while R is the 'bottom' resistance graph with a 10K resistor in parallel to the Thermistor.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Post Edited (Beau Schwabe (Parallax)) : 1/9/2010 7:30:18 AM GMT
Tracy,
Thanks for the spreadsheet you provided. I've been taking a look at it but was wondering what would be needed if I wanted to modify this to an different thermistor.
I have the was looking at using the the 2904 epcos (link) which is 10k Ohms @ 25 Deg C. I wonder if I just changed the given data points, source voltage and the resister in series with the Thermistor if I would be good to use your excel sheet. Or is there something else I would need to consider like insert the B 25 / 100 or anything like that?
thanks in advance
-J
-Phil
You should be able to use that spreadsheet. Alter the column of resistance to match your thermistor found in the table under type 2904. E.g, next to 25 degrees Celsius enter 10000 Ohms, next to 30 °C enter 7942 Ω and so on. And enter your reference resistor and excitation voltage. The program creates the DATA table that is used by the Stamp program to interpolate temperature in units of 0.1 °C. The program is set up to start at -40 °C.
That thermistor has tolerance of +/-5% or +/-10%. If you measure your thermistor at 25°C and find that it is 9500Ω instead of 10000Ω, then put 9500 next to 25 Celsius in the spreadsheet, and adjust all the resistance values in the spreadsheet by the same proportion. Note that 500Ω amounts to about 1 °C error if you don't bother to correct that. The table method can also be used in conjunction with one of the linearization techniques.
The B parameter is the basis of a math approximation to the thermistor curve. The B formula for a Excel would be:
Resistance =10000*EXP(4300*(1/(degC+273) - 1/(25+273)))
That gives resistance vs temperature, but remember that it is in fact an approximation (worse than the Steinhart-Hart formula) and the values you read from the table will be a better fit to the true performance. For fun you can enter the formula and compare with the values from the table.
For NTC it will require modification of array or function.
It depends if it is NTC or PTC and if it is connected to + or - .
The simplest way is to reverse array order with entries to keep ascending trend of .adc value ( then .temp values will go descending )
Second solution is to connect NTC to + and modify PTC_ADC(r) macro.
PTC_ADC(r) - macro assuming that ADC reference voltage is the for R + PTC circuit supply.
Preprocessor will calculate correct values of ADC for given resistance value from PTC datasheet.
As an aside, this is an 8 year old thread. This isnt to say your code contribution is unlikely to help someone, someday, but the immediate need has passed. Come join us in a current thread!
Once you have the equation for it, just plug in your read value.