Temperature sensor circuit temperature calculation
[Copy link]
This post was last edited by a 69-year-old comrade on 2024-10-18 13:14
**Circuit Principle**
After studying microcontrollers for so long, the hardest part is analyzing them together with circuits, because you need to learn the basic knowledge of circuits. Temperature sensors are usually made of thermistors, so the temperature is related to the resistance, and the resistance is indirectly calculated using the circuit, and the temperature is calculated by comparing the resistance with the temperature resistance table.
Because the ADC pin of the microcontroller samples the range of VREF- to VREF+, one of these two is usually connected to ground and the other to 3.3v, so the measurement range is 0~3.3V. Because the accuracy of the ADC is 12 bits, the voltage value converted from the sampled value is
V=sampling value*Vref/(2^12)=value*3.3/4096;
Usually a resistor divider circuit is used to measure the voltage of the thermistor, and the resistance value is deduced based on the voltage.
**Voltage Calculation**
For example, in the circuit shown in the figure, R58 and C73 do not participate in voltage division, and the capacitors can be regarded as open circuits and are not considered. The actual voltage division resistors are R59 and RT (not shown);
TEMP1 is connected to ADC, TEMP_IN1 is connected to RT resistor, which is not drawn in the figure;
UADC=VCC*RT/(RT+R59);
UADC=VALUE*VCC/2^12=VALUE*3.3/4096
. If the value sampled by ADC is known, UADC can be obtained, and RT value can be solved, and temperature value can be deduced according to RT table.
The calculation of temperature value is divided into two steps: one is to determine the integer part, and the other is to determine the decimal according to the ratio.
**Resistance calculation**
Find a detailed RT table, preferably with an accuracy of 1°C, otherwise the error will be relatively large, you can ask the merchant for it. Take the center value of the resistor, for example, at -55°C, the center value is 250.065KΩ.
Then draw a table in Excel, put the temperature and resistance value in it, and then calculate the sampling value of the microcontroller in advance. The sampling formula in the table is the voltage divider value of an RT resistor and a 4.3KΩ resistor. In this way, the resistance value can be deduced by comparing the sampling value with the table.
We can put this sampling table into the program and use an array to represent it. The first row represents the temperature corresponding to this sampling value, -45~-40 degrees. Generally, the experiment given by the manufacturer is around -50~100 degrees.
Then if you want to calculate the accuracy of 1 degree, compare the sampled value of the microcontroller with this table and use a for loop to traverse it. After calculating the integer part, the decimal part is calculated by roughly using the ratio of the sampled value to the two values. Because the temperature in the table starts at -45 degrees, the formula (i-45)*10 represents the integer part of the temperature, and the following part is the decimal. You can add decimals or subtract decimals, depending on whether your integer is the upper or lower limit. The res returned at the end is the actual temperature*10. In general, it is a more abstract way of thinking.
Generally speaking, ADC can only sample voltage values, so no matter what is sampled, it must be converted into a voltage value in the end.
The circuit below has the same idea, but the 10K resistor does not participate in the voltage division. Only the 2.37k resistor and RT divide the voltage to 3.3V.
The circuit in the figure below is a little more complicated because an amplifier is added. Due to space limitations, I will write about it next time.
|