RT temperature sensor calculations help

ericgibbs

Joined Jan 29, 2010
21,440
hi z,
If you want to display the actual temperature to +/-0.1 C how do you plan to do that using a Table of +/-1C.?

Using an averaged value of say 100 readings will give a close enough value.

What programming language are you using.?

What ADC input voltage range do you expect over the known temperature range.?

E
 

ericgibbs

Joined Jan 29, 2010
21,440
What I am concerned with, is how do I map these values with my ADC readings. For example my ADC votlage is 0,92V
Hi z,
I follow now.:)

One method is a Table of the voltages in the program and the Temperature, an index of the Table.

Simplify the Output voltage values to suit the ADC bit width.
E
 

Thread Starter

zazas321

Joined Nov 29, 2015
936
I am using a mixture of C/C++. I am programming ESP32 microcontroller.

The RT table that I have provided is not a full table, I have shown it just as an example. The whole table is from -20 to +100 degrees and I expect voltages between 2,5V (for minimal temperature value -20) and 0,1V (for maximum value 100) .

Can you clarify what you mean by Simplify the Output voltage values to suit the ADC bit width.
 

Ian0

Joined Aug 7, 2020
13,131
You need a spreadsheet.
Adjust the values at the top for you 25°C reference resitance, and your pullup value
Save as csv, then remove the surplus commas with a text editor, then copy into your data table
 

Attachments

Thread Starter

zazas321

Joined Nov 29, 2015
936
You need a spreadsheet.
Adjust the values at the top for you 25°C reference resitance, and your pullup value
Save as csv, then remove the surplus commas with a text editor, then copy into your data table
I get the idea what you are trying to do here, but is still not fully clear to me. Please clarify the following questions:

1. You define a value for each value of my adc ( 4096 total values )


2. For example, values from 0-20 will map to the highest temperature of the sensor (100 degrees), the the next 19 values or so will correspond to temeprature 99 or so.

3. Please clarify to me how do I map adc values to temperature in your case
 

ericgibbs

Joined Jan 29, 2010
21,440
Can you clarify what you mean by Simplify the Output voltage values to suit the ADC bit width.
Hi z,
You do not need the lengthy decimal part.
Reduce to say 3 to 4 decimal places and multiply by say 1000 to raise to integers.
This will simplify and speed up the processing.
E
EG 899.png
 

Ian0

Joined Aug 7, 2020
13,131
It works right to left.
Each entry represents the A/D value that you have read (column F)
That translates to a resistance value (Column E)
Then to a temperature in Kelvin (Column D)
Then to an integer in column B which is degrees Celsius x 10.
If R1 contains the 12 bit data read from the A/D, and R3 is the base address of the table
then
LDRSH R0,[R3,R1,LSL#1]
gives you the temperature in tenths of a degree in R0. (ARM code, LSL#1 because each entry is a half word or 2 bytes)
[Edit] corrected LDR to LDRSH
 
Last edited:

ericgibbs

Joined Jan 29, 2010
21,440
hi z.
This is what I see with VB6., convert this code fragment into 'C' and write a test program.
E

Private Sub Calc()
'All Single
Rt = 0
R0 = 10000
Bval = 3350
Tamb = 253.15 + 25
T0 = 273.15 + 25

For Tamb = 253.15 To 318.15
Rt = R0 * (Exp(Bval * ((1 / Tamb) - (1 / T0))))

Vadc = 3.3 * (Rt / (Rt + 22000))

rtb1.SelText = "Tamb C= " & Int(Tamb - 273) & " " & "Rth= " & Int(Rt) & " Vadc=" & Vadc & vbCrLf

Next Tamb

End Sub
 

Attachments

Ian0

Joined Aug 7, 2020
13,131
You need it the other way round.
Vadc is the data that is available. From that we need to find the temperature.
 

crutschow

Joined Mar 14, 2008
38,504
Using a resistor as a voltage divider to generate a thermistor sensor output voltage gives you an additional non-linearity in addition to that of the sensor (since the output is determined by Rsen / (Rsen +R1) which is non-linear with a change in Rsen).
Using a constant current source will eliminate that non-linearity.

Below is the LTspice simulation of an example circuit that uses an op amp in a bridge configuration to generates a constant current through the example thermistor, and offset the output voltage to the range desired:

1634304529831.png
 
Last edited:

ericgibbs

Joined Jan 29, 2010
21,440
Ian
I know that!

This example is show the TS how to Cal Rth, NOT to find the Temperature... OK

@Ian0
Perhaps a better explanation is called for.

The TS in his opening Post is using a web Calc program to calculate each individual resistance point.

The simple program I have posted for him, if he writes it, will enable him to do the calculations in a fraction of the time, also it should enable him to recall the 'old' maths.

He can also adjust the Beta value etc ...

E
 
Last edited:

ericgibbs

Joined Jan 29, 2010
21,440
Hi Carl,
I would agree, it should simplify and speed up the calculations, he is planning to do 100 samples then create the average Voltage value.

It would be interesting to know what he is measuring and how often he needs to sample the temperature.

E
 

MrChips

Joined Oct 2, 2009
34,810
I have done this many times and I can show you how to do it.

If you are using an ADC to measure voltage, you don't need to know the voltage because it is just an intermediate step.
A 12-bit ADC outputs a number from 0 to 4095 and that is all you need (besides knowing your supply voltage, supply resistor value, and ADC reference voltage}.

I am on the road and you will have to wait until I get back in a week.
 

ericgibbs

Joined Jan 29, 2010
21,440
hi zazus,
As you are using the ESP32, be aware of the linearity problems with the onboard 12 Bit ADC.
This video covers some of the points regarding the ADC's, approx 14 minutes into the Vid.

E
 

MrChips

Joined Oct 2, 2009
34,810
You can account for all non-linearities and uncertainties in one calibration procedure.

Calibrate your system by recording the ADC count vs temperature at five temperatures spanning your desired temperature range. Ten points would be even better.

Then I will provide you with a formula that you can code into your MCU.
 

Ian0

Joined Aug 7, 2020
13,131
I have done this many times and I can show you how to do it.

If you are using an ADC to measure voltage, you don't need to know the voltage because it is just an intermediate step.
A 12-bit ADC outputs a number from 0 to 4095 and that is all you need (besides knowing your supply voltage, supply resistor value, and ADC reference voltage}.

I am on the road and you will have to wait until I get back in a week.
My spreadsheet is similar (which you probably can't open) unless you're at home with a computer. I'd be interested to see your method, as my spreadsheet can be a little cumbersome.
 

MrChips

Joined Oct 2, 2009
34,810
I am sure it is the same method.

I enter ten pairs of data points (or how many data points you have acquired) of ADC counts vs temperature into a table.

Then you perform a curve fit to a polynomial. If luck is on your side you might be able to compromise accuracy with simplicity by using a 2nd order polynomial (three constants in the formula). In other words the order of the polynomial dictates how much error you are willing to accept.

You can do this on a spreadsheet. I use MATLAB.
Then I manipulate my constants carefully so that the conversion from ADC count to temperature is performed in fixed point arithmetic.
 

MrChips

Joined Oct 2, 2009
34,810
My spreadsheet is similar (which you probably can't open) unless you're at home with a computer. I'd be interested to see your method, as my spreadsheet can be a little cumbersome.
I am typing on a mobile device and far away from home.
 

BobaMosfet

Joined Jul 1, 2009
2,211
Hello. I have an RT temperature sensor and I have been given the RT table as below:

I have been trying to find a good way to come up with an equation or a formula to convert the sensor output into the temperature but I have not managed to find a way yet, perhaps someone could point me in the right direction.



TEMPERATURERESISTANCEOUTPUT VOTLAGE
-20​
69693​
2,508227​
-19​
66329​
2,478073​
-17​
60140​
2,416143​
-16​
57294​
2,38442​
-15​
54600​
2,352219​
-14​
52049​
2,319568​
-13​
49633​
2,286501​
-12​
47344​
2,253046​
-11​
45174​
2,219225​
-10​
43117​
2,185084​
-9​
41166​
2,150648​
-8​
39315​
2,11595​
-7​
37559​
2,081041​
-6​
35891​
2,045919​
-5​
34307​
2,01064​
-4​
32803​
1,975255​
-3​
31373​
1,939762​
-2​
30015​
1,904249​
-1​
28723​
1,868697​
0​
27494​
1,833156​
1​
26325​
1,797672​
2​
25212​
1,762255​
3​
24153​
1,726971​
4​
23144​
1,691813​
5​
22184​
1,656871​
6​
21268​
1,622086​
7​
20396​
1,587574​
8​
19564​
1,553296​
9​
18771​
1,519323​
10​
18015​
1,48568​
11​
17294​
1,45239​
12​
16605​
1,419415​
13​
15948​
1,386856​
14​
15320​
1,354662​
15​
14720​
1,322876​
16​
14148​
1,29159​
17​
13600​
1,260674​
18​
13077​
1,230268​
19​
12577​
1,200338​
20​
12099​
1,170905​
21​
11641​
1,141919​
22​
11204​
1,113516​
23​
10785​
1,085573​
24​
10384​
1,058152​
25​
10000​
1,03125​
26​
9632​
1,004856​
27​
9280​
0,979028​
28​
8943​
0,95375​
29​
8620​
0,929001​
30​
8310​
0,904751​
31​
8012​
0,880968​
32​
7728​
0,857858​
33​
7454​
0,83514​
34​
7192​
0,813017​
35​
6940​
0,791361​
36​
6699​
0,770295​
37​
6467​
0,749679​
38​
6244​
0,729543​
39​
6030​
0,709918​
40​
5825​
0,690836​
41​
5628​
0,672231​
42​
5438​
0,654035​
43​
5256​
0,636366​
44​
5080​
0,619055​
45​
4912​
0,602319​
46​
4750​
0,585981​
47​
4594​
0,570061​
48​
4444​
0,554576​
49​
4300​
0,539544​
50​
4161​
0,524877​
51​
4027​
0,510589​
52​
3898​
0,496695​
53​
3774​
0,483208​
54​
3654​
0,470032​
55​
3539​
0,457289​
56​
3428​
0,44488​
57​
3322​
0,432928​
58​
3219​
0,421218​
59​
3119​
0,409758​
60​
3023​
0,398669​
61​
2931​
0,387963​


The first 2 columns of the table are provided. The 3rd row I have calculated myself and I will explain how below.

So I know what resistor values the temperature will give at any given temperature. The way I read the sensor values is by converting it to the voltage via the voltage divider and then connecting this to my ADC_pin of my microcontroller.

Vsupply = 3.3V
R1 = 22Kohms
R2 = Temperature_sensor_output
The following online calculator can be used:
https://ohmslawcalculator.com/voltage-divider-calculator


For example, when the temperature sensor outputs 10Kohms ( at 25 degrees Celcius) , the voltage output will be 1.031V.



Is there any formula that I can use to determine the current temperature ? Since the relationship is not linear, it makes it quite complicated to come up with an equation that I could use for all the possible values. Any help is appreciated.
What micro-controller are you using? The datasheet will tell you what the formula is for the resolution of the ADC. Likewise the datasheet for the temp sensor you are using will tell you what you need to know about it....
 
Top