RT temperature sensor calculations help

Thread Starter

zazas321

Joined Nov 29, 2015
936
There is no need to calibrate the adc since the ESP32 has a built in conversion from the adc reading to the actual voltage. So instead of reading the ADC value, I read the voltage. This is better because the Voltage and ADC curve is not perfectly linear.


I have managed to write a table which consists a value for each temperature. Then I just find the closest match and determine what is the temperature.
 

ericgibbs

Joined Jan 29, 2010
18,766
hi zazas,
I would be interested in seeing your program for getting 0.1C resolution from the plot you produced.
What size Table did you use.?
E
 

Thread Starter

zazas321

Joined Nov 29, 2015
936
hi zazas,
I would be interested in seeing your program for getting 0.1C resolution from the plot you produced.
What size Table did you use.?
E

Hello. I am not actually getting the 0.1C resolution. My lookup table looks as following:
Code:
int temp_lookup[191] = 
{
[0]= 45, // 150
[1]= 46,
[2]= 47,
[3]= 48,
[4]= 49,
[5]= 50,
[6]= 51,
[7]= 52,
[8]= 54,
[9]= 55,
[10]= 56,
[11]= 57,
[12]= 58,
[13]= 60,
[14]= 61,
[15]= 62,
[16]= 64,
[17]= 65,
[18]= 67,
[19]= 68,
[20]= 70,
[21]= 71,
[22]= 73,
[23]= 74,
[24]= 76,
[25]= 78,
[26]= 79,
[27]= 81,
[28]= 83,
[29]= 85,
[30]= 87,
[31]= 89,
[32]= 91,
[33]= 93,
[34]= 95,
[35]= 98,
[36]= 100,
[37]= 102,
[38]= 105,
[39]= 107,
[40]= 110,
[41]= 112,
[42]= 115,
[43]= 118,
[44]= 121,
[45]= 124,
[46]= 127,
[47]= 130,
[48]= 133,
[49]= 137,
[50]= 140,
[51]= 143,
[52]= 147,
[53]= 151,
[54]= 154,
[55]= 158,
[56]= 162,
[57]= 167,
[58]= 171,
[59]= 175,
[60]= 180,
[61]= 184,
[62]= 189,
[63]= 194,
[64]= 199,
[65]= 204,
[66]= 210,
[67]= 215,
[68]= 221,
[69]= 227,
[70]= 233,
[71]= 239,
[72]= 245,
[73]= 252,
[74]= 259,
[75]= 266,
[76]= 273,
[77]= 280,
[78]= 288,
[79]= 295,
[80]= 303,
[81]= 312,
[82]= 320,
[83]= 329,
[84]= 338,
[85]= 347,
[86]= 357,
[87]= 367,
[88]= 377,
[89]= 387,
[90]= 398,
[91]= 409,
[92]= 421,
[93]= 432,
[94]= 444,
[95]= 457,
[96]= 470,
[97]= 483,
[98]= 496,
[99]= 510,
[100]= 524,
[101]= 539,
[102]= 554,
[103]= 570,
[104]= 585,
[105]= 602,
[106]= 619,
[107]= 636,
[108]= 654,
[109]= 672,
[110]= 690,
[111]= 709,
[112]= 729,
[113]= 749,
[114]= 770,
[115]= 791,
[116]= 813,
[117]= 835,
[118]= 857,
[119]= 880,
[120]= 904,
[121]= 929,
[122]= 953,
[123]= 979,
[124]= 1004,
[125]= 1031,
[126]= 1058,
[127]= 1085,
[128]= 1113,
[129]= 1141,
[130]= 1170,
[131]= 1200,
[132]= 1230,
[133]= 1260,
[134]= 1291,
[135]= 1322,
[136]= 1354,
[137]= 1386,
[138]= 1419,
[139]= 1452,
[140]= 1485,
[141]= 1519,
[142]= 1553,
[143]= 1587,
[144]= 1622,
[145]= 1656,
[146]= 1691,
[147]= 1726,
[148]= 1762,
[149]= 1797,
[150]= 1833, // 0
[151]= 1868, // -1
[152]= 1904,
[153]= 1939,
[154]= 1975,
[155]= 2010,
[156]= 2045,
[157]= 2081,
[158]= 2115,
[159]= 2150,
[160]= 2185,
[161]= 2219,
[162]= 2253,
[163]= 2286,
[164]= 2319,
[165]= 2352,
[166]= 2384,
[167]= 2416,
[168]= 2447,
[169]= 2478,
[170]= 2508,
[171]= 2537,
[172]= 2566,
[173]= 2595,
[174]= 2622,
[175]= 2650,
[176]= 2676,
[177]= 2702,
[178]= 2727,
[179]= 2752,
[180]= 2775,
[181]= 2798,
[182]= 2821,
[183]= 2843,
[184]= 2864,
[185]= 2884,
[186]= 2904,
[187]= 2923,
[188]= 2941,
[189]= 2959,
[190]= 2976, // 150

};

The way I am getting 0.1C resolution is by taking multiple measurement and averaging the final temperature value. The instantenous temperature will have a maximum resolution of 1C becuase that is how my table is defined.


But since I am doing 100 readings every 0.1 second and then averaging the results, I am getting some value for example 8.75 ( temperature was fluctuating between 9 and 8 degrees )
 

ericgibbs

Joined Jan 29, 2010
18,766
hi zazas,
I am running a similar method on a ESP32.
On starting the program it calculates a Table [array] using the equation
Rth = R0 * (Exp(Bval * ((1 / Tamb) - (1 / T0))))
Converting to an expected ADC out 0 thru 4095, saving that ADC value in the Table array
at 1Cdeg steps.
The main program then compares the ESP ADC out value with the array, checking for a 'fit' between the lower and higher values of the Table.

It works fine for 1C steps, but I am looking how to infer the 0.1C values.

E
I have an alternate method in mind, using Vadc, which I will try later.

Clip from Serial.print. [using a 50Kpot for ADCvin]

EG 921.png
 
Last edited:

ericgibbs

Joined Jan 29, 2010
18,766
hi zazas,
Look at his option.
I have remmed out the 'print all variables', pop it back in if you want to see All.

E

@zazas321

C-like:
/* thermistor temperature profile 17/10/2021 ESP57

Vadc = 3.3 * (Rt / (Rt + 22000))
ADCout = (Vadc / 3.3) * 4096
*/
#define ADCin1    35 // ESP32 pin

float R0 = 10000;  // Therm resistance at 25C
float Bval= 3350;  // Therm Beta value
float Rth = 0;
float ADCcnt= 0;
float Rser = 22000; // Series resistor with Therm
float ADCvolt = 0;
float Vss =3.3; // ESP32 ref Volts

float TambAvg =0;

float Tref = 298.15; // 25C
float Tamb = 298.15; // 25C
int i =0;
int avg=0;



void setup()
{
  Serial.begin(115200);
  Serial.println("NTC1");
}

void loop() {

for (i = 0; i<= 99; i++){

// get ADC count for the ADC inp voltage
  ADCcnt= analogRead(ADCin1);

// Calc ADC input voltage
  ADCvolt = Vss*(ADCcnt/4096);

// Calc Therm resistance that will give ADCvolt
  Rth= (ADCvolt*Rser)/(Vss-ADCvolt);

//Transposed Equation for Tamb, Therm Temperature
  Tamb =(Tref*Bval)/((Tref * log(Rth/R0)+Bval));
/*
  Serial.print("ADCcnt=");
  Serial.print(ADCcnt,0);
  Serial.print("  ADCvolt=");
  Serial.print(ADCvolt,4);
  Serial.print("  Rth=");
  Serial.print(Rth);
  Serial.print("  Cdeg=");
  Serial.println((Tamb-273.15),3);
*/
  TambAvg=TambAvg + Tamb;
  avg=avg+1;
}

  if (avg >= 99){
  Serial.print ("   TambAvg=");
  Serial.println((TambAvg/avg)-273.15);
  TambAvg=0;
  avg=0;
  delay(100);}
}

Added: with R/C filter on ADC
25.033
25.047
25.040
25.075
25.050
25.041
25.036
25.030
25.060
25.053
25.034
25.038
25.047
25.056
25.034
25.058
25.048
25.054
25.050
25.050
25.057
25.051
25.025
25.021
25.018
25.016
25.037
25.035
25.065
25.047
25.060
25.022
25.045
25.048
25.061
25.056
25.045
25.045
25.042
25.048
25.035
25.059
25.050
25.020
 

Attachments

Last edited:

ericgibbs

Joined Jan 29, 2010
18,766
hi, Carl
@crutschow

This LTS asc is a composite of 3 versions.
Thought you maybe interested is working with the circuits and results.

The ESP32 MCU ADC input has to be within 0V thru +3.3V limits,

The Rth is based on the TS's actual Thermistor spec.

Eric.
 

Attachments

Last edited:

MrChips

Joined Oct 2, 2009
30,712
I took 17 pairs of numbers from the data supplied and fitted a polynomial to the data set.


TEMPERATURE °CADC COUNT
-203112
-152919
-102711
-52495
02275
52056
101844
151642
201453
251280
301123
35982
40857
45747
50651
55567
60495


thermistor_fit.jpg

Here are the coefficients of the 3rd order polynomial:

a0 = 93.075
a1 = -8.1425e-2
a2 = 2.7121e-5
a3 = -4.0755e-9

The formula is:

temp = a0 + a1*x + a2*x^2 + a3*x^3

where x is the ADC count.

If you were to restrict the temperature range to a narrower range we could find a more simple (2nd order) polynomial.
 
Top