您的当前位置:首页正文

NTC温度计算

2024-11-30 来源:个人技术集锦

NTC温度计算


根据NTC阻值查表计算NTC温度


1.得到NTC阻值

2.具体算法实现

#include "math.h"

static const u16   Rref = 10; 	//基准电阻
static const float kd = 1; 		//系数

/*=============================
NTC电阻温度查找表
RS[0] 代表 温度为-40° 对应 电阻值为 192.6
RS[1] 代表 温度为-39° 对应 电阻值为 182.4
......
RS[40] 代表 温度为0°   对应 电阻值为 27.37
......
RS[160] 代表 温度为120°   对应 电阻值为 0.5975
=============================*/
float RS[161]={192.6,182.4,172.8,163.7,155.1,147.1,139.5,132.3,125.6,119.2,113.2,107.5,
			102.2,97.09,92.3,87.77,83.49,79.45,75.62,71.99,68.56,65.32,62.24,59.33,
			56.56,53.95,51.46,49.11,46.87,44.75,42.74,40.83,39.01,37.29,35.65,34.09,
			32.61,31.2,29.86,28.59,27.37,26.22,25.12,24.07,23.07,22.12,21.21,20.35,
			19.52,18.73,17.98,17.26,16.58,15.93,15.3,14.7,14.13,13.59,13.07,12.57,
			12.09,11.64,11.2,10.78,10.38,10,9.633,9.282,8.945,8.622,8.312,8.015,
			7.731,7.457,7.195,6.944,6.702,6.471,6.248,6.034,5.829,5.631,5.441,5.259,
			5.084,4.915,4.753,4.597,4.446,4.302,4.163,4.029,3.9,3.776,3.656,3.541,
			3.429,3.322,3.219,3.12,3.024,2.931,2.842,2.755,2.672,2.592,2.515,2.44,
			2.367,2.298,2.23,2.165,2.102,2.042,1.983,1.926,1.871,1.818,1.767,1.717,
			1.669,1.623,1.578,1.534,1.492,1.451,1.412,1.374,1.337,1.301,1.266,1.233,
			1.2,1.168,1.138,1.108,1.079,1.052,1.025,0.9985,0.9731,0.9485,0.9246,0.9014,
			0.879,0.8572,0.836,0.8155,0.7956,0.7763,0.7575,0.7393,0.7216,0.7045,0.6878,
			0.6716,0.6559,0.6407,0.6258,0.6114,0.5975};

/*==========================================
函数描述:获取NTC温度
函数输入:uiTempValue:NTC电压值,uiVrefValue:基准电阻电压值
函数输出:
==========================================*/
s8 APP_GetTemp(u16 uiTempValue,u16 uiVrefValue)
{
	float Vsub,Rvalue;
	u8 ucCountf,i;
	
	//计算NTC电阻值
	if(uiVrefValue>uiTempValue)
	{
		//基准电阻电压
		Vsub = uiVrefValue*kd-uiTempValue;
		//计算NTC阻值
		Rvalue = (float)((uiTempValue/Vsub)*Rref);	
	}
	else
	{
	    return (s8)(TEMP_ERROR_VALUE); // 设置异常情况下温度为196度
	}
		
	//查找温度
	//温度超过下限
    if(Rvalue >= RS[0])
    {
		return (s8)(TEMP_ERROR_VALUE); // 设置异常情况下温度为196度
    }
	
	//温度超过上限
    if (Rvalue <= RS[160])
    {
		return (s8)(TEMP_ERROR_VALUE); // 设置异常情况下温度为196度
    }	
	
	//按照数组查找温度
    ucCountf = 0;
    for(i=0;i<160;i++)
    {        
        if(Rvalue<RS[i+1])
        {
            ucCountf++;
        }
    }

    return (s8)(((s8)ucCountf)-40);
}

显示全文