NTC temperature measurement precision hardware circuit and software design

What is the NTC

NTC thermistors, whose resistance value is sensitive to temperature change at different temperatures, may exhibit different resistance values.

The thermistor has two types, one is a negative temperature coefficient of resistance (the NTC), the temperature increases, the resistance value decreases, the other is a positive temperature coefficient resistor (the PTC), the temperature increases, the resistance value increases.

Calculation of the resistance value of the thermistor

Relationship between the resistance value R of the NTC temperature can be approximated as:

NTC temperature measurement precision hardware circuit and software design

Equation 1, the functional relationship between resistance and temperature

Where T is the absolute temperature values ​​are in degrees centigrade +273.15 unit is K (Kelvin).

Generally the temperature is 25 ℃ R0 i.e., when the resistance value 298.15K, taking T0 corresponding to 25 ℃, i.e. 298.15K.

B is a material constant. Different materials village or B values ​​can lead to the production process is changed, even in the operating range of the thermistor, B values ​​are likely to change, rather than strictly constant;

Because the resistance of the NTC temperature nonlinear relationship, and kept the temperature increases, the smaller the temperature change rate with temperature change.

Therefore, with increasing temperature, NTC precision temperature change;

It is more suitable for small temperature variations usage scenarios, such as ambient temperature (about -20 ℃ -50 ℃) or detecting a water (0 ℃ -100 ℃).

The figure is searched in a Taobao the NTC, a resistance value according to the temperature of 25 deg.] C, may have different specifications 5KΩ, 10 KΩ and the like, while the material is fixed to the coefficient values ​​B 3950.

NTC temperature measurement precision hardware circuit and software design

Taobao search to a NTC

We chose 10K in size, according to the formula 1, can obtain the relationship between resistance and temperature of the NTC is this:

NTC temperature measurement precision hardware circuit and software design

Equation 2, as a function of the temperature resistance of formula

By the equation excel spreadsheet, excel in the first column of the input temperature of the workbook, may enter the formula column to obtain a second resistance values ​​at different temperatures, such as 0 ℃ 33.6 KΩ

NTC temperature measurement precision hardware circuit and software design

AD value calculated using excel

NTC temperature measurement circuit is designed

NTC temperature having a core comprising MCU ADC function, the circuit is relatively simple, just to a fixed voltage via a further high-precision resistor divider to the NTC resistor, and the divided voltage value is connected to the ADC input port of the MCU.

As shown below:

NTC temperature measurement precision hardware circuit and software design

NTC temperature measurement circuit

R1 is 1% tolerance resistors, R2 is a NTC,

0.1uF的电容C1除了可以滤除从电源引入或者从电路板感应来的高频干扰信号,另外当ADC有多路AD输入在转换时,MCU的AD模块需要通过模拟开关切换不同的通道,再进行采样转换,电容C1可以在ADC切换通道之后,迅速向采样电容充电,从而可以提到转换速度,避免因采样时间太短而导致测量不准确。

R1上拉的电源应该和MCU的ADC的参考电源共用一个电源(在一般的设计中,MCU的供电电源和ADC的参考电源共用一个电源)。

这是因为:

输入ADC的AD值为(假设为12位的ADC):

NTC temperature measurement precision hardware circuit and software design

AD值计算公式

如果上拉的电源ADC的参考电源共用一个电源,可以得到和上位电源无关的一个公式:

NTC temperature measurement precision hardware circuit and software design

AD值计算公式

所以可以消除电源精度对测试的影响,同时减少了计算的复杂性;

NTC测温软件的设计

我看到在一个网友的程序设计中,他直接将公式1取对数,通过复杂的对数运算和倒数运算得到温度值,这是不合适的,

主要是:

  1. 普通的单片机不一定提供这样的数学函数库。
  2. 普通的单片机没有浮点数运算,浮点数都是转成整弄运算的,不可避免会有舍入误差。
  3. 单片机做对数,倒数的运算,只能是近似算法,而且会耗费大量的运算时间,可能会到几百ms级,影响了对其它功能处理的实时性。
  4. 公式1只是一个近似公式,B值也并不是一个常数,用这样具体的解析公式计算,没有办法根据实际测量值对计算值进行标定,从而提高测量精度。

我在实际的项目中,采用的是分段线性化的方法,步骤如下:

NTC temperature measurement precision hardware circuit and software design

采用excel表格自动生成C语言中包含AD与温度的二维数组

  1. 将测温范围分若干个区间,比如在0-100度的范围内,分100个区间,每个区间范围为1℃
  2. 计算或者实测每一个区间下限和区间上限的温度值; 比如区间30℃-31℃,根据公式1计算或者实际测试出30℃以及31℃的AD值。
  3. 将这些区间表示为2维数组(这个2维数组也可以通过实际测试形成);
  4. 取出将AD转换并多次平均之后数值,编历分段的区间,与这些区间的AD上、下限进行比较,判断落在哪一个区间,
  5. 根据一次函数的公式进行区间内的插值修正:

Test temperature range the lower temperature limit value + = (the upper limit temperature range - lower limit of the temperature range) / (AD upper section - the lower limit of the interval AD) * (AD measured value - lower limit interval AD)

Finally offer piecewise linearization procedure I use:

NTC temperature measurement precision hardware circuit and software design

Piecewise linear programming

Guess you like

Origin www.cnblogs.com/ct20150811/p/11276595.html