Calculating NTC temperature

Thread Starter

nerdegutta

Joined Dec 15, 2009
2,689
I looked at the data again. Adding a resistor in parallel will reduce your sensitivity.

If you are using floating point arithmetic anyway, then you might as well go back to square one.

  1. Acquire the ADC counts
  2. Calculate the resistance R of the thermistor
  3. Take the log(R)
  4. fit to T vs log(R)
My equations are:


Assuming that the ADC Vref is the same as Vdd or Vcc, otherwise adjust as required.

R2 = 10000 where R2 is the load resistance
R = 1023*R2/ADC_COUNTS - 1
x = log(R)

where log( ) means the natural log or ln( )

a3 = 2.402675132814
a2 = -30.837075314796
a1 = 148.797883377607
a0 = -285.600560405728

T = a3*x^3 + a2*x^2 + a1*x + a0
Rich (BB code):
R2=10000;

R=(1023*R2)/adc_raw -1;
x = log(R);

a3=2.402675132814;
a2=-30.837075314796;
a1=148.797883377607;
a0=-285.600560405728;
temperature1 = a3*pow(x,3)+a2*pow(x,2)+a1*x+a0;
With this I got temperature1 = 502.1, which is the same as the ADC reading, except for the .1
 

Thread Starter

nerdegutta

Joined Dec 15, 2009
2,689


With this code, and a 33K resistor instead of the 10K:
Rich (BB code):
x=adc_raw;
a3=0.00000018524250;
a2=-0.00025641150597;
a1=0.19058077255347;
a0=-55.86182880225911;

temperature1 = a3*pow(x,3)+a2*pow(x,2)+a1*x+a0;

temperature2 = 0.0942833 * adc_raw - 22,9818;
temperature1 = T1

T2 is unchanged.

The closest we've got is with a 10K and:

Rich (BB code):
temperature2 = 0.0942833 * adc_raw - 22,9818;
How is the curve in Matlab for that setup?
 

Attachments

Thread Starter

nerdegutta

Joined Dec 15, 2009
2,689
Yesterday I filled a container with water and put it in the freezer. So I have a possibility to check for lower temperatures. I also soldered an NTC to some wires, and changed my software so it now reads from AN0 and AN4.


This is the result now:


The calculations are:
Rich (BB code):
temperature1 = 0.0942833 * adc_raw_ch0 - 22,9818;
temperature2 = 0.0942833 * adc_raw_ch4 - 22,9818;
temperature1 is T0, read from AN0
temperature2 is T4, read from AN4

I have not tried the calculations in post #60
 

MrChips

Joined Oct 2, 2009
35,092
While you are doing that, record on a piece of paper the ADC counts vs commercial temp for all readings for each thermistor. Identify each thermistor and don't mix them up.
 

Thread Starter

nerdegutta

Joined Dec 15, 2009
2,689
While you are doing that, record on a piece of paper the ADC counts vs commercial temp for all readings for each thermistor. Identify each thermistor and don't mix them up.
ADC Counts | Temp Commercial | Temp T0

232 | -4.3 | |
223 | -6.1 | |
218 | -6.7 | |
215 | -7,0 | |
209 | -7.5 | |
205 | -7.7 | -2.8|
200 | -7.9 | -3.0|
195 | -8.0 | -3.5|
191 | -8.1 | -3.7|
186 | -8.3 | -4.5|
184 | -8.4 | -4.7|
180 | -8.4 | -5.0|


The ADC0 was just about to change when I took the picture.
 

Attachments

Last edited:

MrChips

Joined Oct 2, 2009
35,092
Are the two thermistor located at the same spot?

Please record the data from each thermistor separately. We want to measure the temperature function of each thermistor and compare.
 

MrChips

Joined Oct 2, 2009
35,092
Yesterday I filled a container with water and put it in the freezer. So I have a possibility to check for lower temperatures. I also soldered an NTC to some wires, and changed my software so it now reads from AN0 and AN4.


This is the result now:


The calculations are:
Rich (BB code):
temperature1 = 0.0942833 * adc_raw_ch0 - 22,9818;
temperature2 = 0.0942833 * adc_raw_ch4 - 22,9818;
temperature1 is T0, read from AN0
temperature2 is T4, read from AN4

I have not tried the calculations in post #60
I am losing you somewhere.

1. Shouldn't 22,9818 be replaced with 22.9818 (or even 23)?

2. You said you have not tried the calculations in post #60. Then what is result you show on post #63?

3. If you change the pulldown resistor from 10k to 33k you cannot use this equation: temperature1 = 0.0942833 * adc_raw_ch0 - 22.9818;

4. What is the tolerance of the pulldown resistor? 5%, 1%? Let me know what resistance/tolerance you are using on each thermistor.

5. I would like to go to a 33k resistor and use the equations on post #60.
 

Thread Starter

nerdegutta

Joined Dec 15, 2009
2,689
Are the two thermistor located at the same spot?

Please record the data from each thermistor separately. We want to measure the temperature function of each thermistor and compare.
No, they are not on the same spot. One NTC is on a breadboard, less than 50cm from the commercial. The other NTC is soldered to some wires, appx 120cm long, with heat-shrink on, which is on the ice.

AN0=T0=NTC on ice
AN4=T4=NTC on breadboard

I will make a table of the two thermistors, with ADC reading, Temp and commercial temp. Like this:
AN0:
ADC reading | Temperature | Commercial
. | . | .|


AN4
ADC reading | Temperature | Commercial
. | . | .|

Will that be OK?

I am losing you somewhere.

1. Shouldn't 22,9818 be replaced with 22.9818 (or even 23)?
If it is 22,9818 it is shows nearly the same temperature as the commercial, if it is 22.9818 or 23, it's appx one 1° lower.

2. You said you have not tried the calculations in post #60. Then what is result you show on post #63?
Those were not on the ice. Sorry, should have made that clear.

3. If you change the pulldown resistor from 10k to 33k you cannot use this equation: temperature1 = 0.0942833 * adc_raw_ch0 - 22.9818;
I figured that out.

4. What is the tolerance of the pulldown resistor? 5%, 1%? Let me know what resistance/tolerance you are using on each thermistor.
Tolerance is 1%
Both are changed back to 10K.
[/QUOTE]
5. I would like to go to a 33k resistor and use the equations on post #60.
OK.

Now I got a 33K 1% tolerance resistor, and:

Rich (BB code):
x=adc_raw_ch0;
a3=0.00000018624250;
a2=-0.00025641150597;
a1=0.19058077255347;
a0=-55.86182880225911;

temperature1 = a3*pow(x,3)+a2*pow(x,2)+a1*x+a0;
ADC reading = 753
T0=21.9
 

MrChips

Joined Oct 2, 2009
35,092
If it is 22,9818 it is shows nearly the same temperature as the commercial, if it is 22.9818 or 23, it's appx one 1° lower.
I don't understand, what is the difference between 22,9818 and 22.9818?
I have never seen the comma being used in arithmetic programming before.

( I will be offline for a couple of hours.)
 

Thread Starter

nerdegutta

Joined Dec 15, 2009
2,689
I don't understand, what is the difference between 22,9818 and 22.9818?
I have never seen the comma being used in arithmetic programming before.

( I will be offline for a couple of hours.)

Here both thermistors, and the commercial sensor, is located close together.
On the commercial thermometer, the upper digits are from the internal sensor, the lower is from the one at the end of the cable. This is laying nearby the breadboard.

On my LCD:
T0 is the one soldered to wire, and with heat shrink tubing on.
T4 is the one on the breadboard.

For this setup/test, both NTC's has 10K 1% resistor.

Rich (BB code):
temperature1 = 0.0942833 * adc_raw_ch0 - 22.9818;
temperature2 = 0.0942833 * adc_raw_ch4 - 22,9818;
T0 = temperature1
T4 = temperature2

Initially, I think I swapped the . with the , due to how Norwegians write decimals. My fault.
 

Attachments

MrChips

Joined Oct 2, 2009
35,092
But what happens when you write:

Rich (BB code):
temperature2 = 0.0942833 * adc_raw_ch4 - 22,9818;
in a computer program?
 

MrChips

Joined Oct 2, 2009
35,092

Here both thermistors, and the commercial sensor, is located close together.
On the commercial thermometer, the upper digits are from the internal sensor, the lower is from the one at the end of the cable. This is laying nearby the breadboard.

On my LCD:
T0 is the one soldered to wire, and with heat shrink tubing on.
T4 is the one on the breadboard.

For this setup/test, both NTC's has 10K 1% resistor.

Rich (BB code):
temperature1 = 0.0942833 * adc_raw_ch0 - 22.9818;
temperature2 = 0.0942833 * adc_raw_ch4 - 22,9818;
T0 = temperature1
T4 = temperature2

Initially, I think I swapped the . with the , due to how Norwegians write decimals. My fault.
There is some inconsistency here.

With adc = 520, result = 26.05, you show 27.0
With adc = 521, result = 26.14, this one is correct
 

Thread Starter

nerdegutta

Joined Dec 15, 2009
2,689
ADC reading on AN0, with a 33K resistor, and calculations according to post #60.

Rich (BB code):
x=adc_raw_ch0;
a3=0.00000018624250;
a2=-0.00025641150597;
a1=0.19058077255347;
a0=-55.86182880225911;

temperature1 = a3*pow(x,3)+a2*pow(x,2)+a1*x+a0;
ADC reading | T0 | Commercial
770 | 24.0 | 25.8|
633 | 9.2 | 13.1|
575 | 4.0 | 9.4|
564 | 3.5 | 6.7|
515 | -0.3 | -0.3|
510 | -0.6 | -0.6|
496 | -1.7 | -2.6|
495 | -1.8 | -2.6|


The other temperatures were stable.
 
Top