[STC32G application] NTC temperature measurement is still using the look-up table method?

Tip: After the article is written, the table of contents can be automatically generated. How to generate it can refer to the help document on the right


foreword

Temperature measurement is a function often used by single-chip microcomputers. I remember that the single-bus sensor DS18B20 was used in schools in the early days, and there was also a sensor integrating temperature and humidity in the back. Later, in some application fields, especially in the farming and planting industry, there are more NTC resistors in this way. One is that the price is relatively cheap, and the other application field is basically distributed. The distance between the sensor and the controller may be hundreds of meters, and the NTC resistor has more advantages.


提示:以下是本篇文章正文内容,下面案例可供参考

1. The principle of NTC temperature measurement

NTC is actually a resistance that changes with temperature, with positive and negative temperature coefficients. In the past, when 51 was doing NTC temperature measurement, it usually chose the look-up table method to calculate the temperature. The look-up table method is to form an array of NTC resistance values ​​corresponding to each temperature. After the single-chip computer calculates the NTC resistance value, it searches in the array to find the corresponding temperature value. The advantage of this method is fast speed, but the disadvantage is that the error is relatively large, especially the smaller the number of arrays, the greater the error, and if the number of arrays is large, it will take up storage space.

In fact, NTC has another way of testing, which is to calculate through formulas.
NTC resistance has a parameter, B value. The B value is related to the material of the NTC resistor.
NTC thermistor B value formula is: B=T1T2 Ln(RT1/RT2)/(T2-T1)

Among them, B: the B value of the NTC thermistor, provided by the manufacturer; RT1, RT2: the resistance value of the thermistor when the temperature is T1, T2 respectively; T1, T2: absolute temperature scale.

In the past, the 51 look-up table method was used a lot, and one reason is that the calculation efficiency through formulas is relatively low, but now that the STC32G comes out, the amount of calculation is not a problem.

2. NTC temperature measurement function

The code is as follows (example):

const float Rp=10000.0; //100K
const float T2 = (273.15+25.0);//T2
const float B0 = 3950.0;//B
const float B1 = 3435.0;//B
const float Ka = 273.15;

float Get_Temp(float Rt,float Bx)
{
    
    
    float temp;
    //like this R=5000, T2=273.15+25,B=3470, RT=5000*EXP(3470*(1/T1-1/(273.15+25)),
    temp = Rt/Rp;
    temp = log(temp);//ln(Rt/Rp)
    temp/=Bx;//ln(Rt/Rp)/B
    temp+=(1/T2);
    temp = 1/(temp);
    temp-=Ka;
    return temp;
}

Summarize

It is relatively more accurate to calculate the NTC resistance value through the formula. However, some filtering operations are generally required before and after calculation to make the temperature value smoother.

Guess you like

Origin blog.csdn.net/lunzilx/article/details/131888957