硬件模块应用之NTC热敏电阻RT关系转换公式

	float Rt,temperature;
	float votage;	
	unsigned int temm,temm2;
	unsigned int temm3;
	
	const float degreeKelvinK = 273.15;	//开尔文绝对温度,单位:K
	const float T2 = degreeKelvinK +25.0;	//25℃的开尔文温度
	const unsigned long R_T2 = 10000;	//常温(25℃)下的阻值
	const unsigned int NTC_B = 3950;	//B值是负温度系数热敏电阻器的热敏常数
	const signed trim_K = -2;			//温度微调系数
	temm3 = ADCRead();
	votage=(2.6/0x7ff)*temm3;	//将AD值转换成电压值	内部参考电压2.6V,11位精度
	//votage=(2.6/0x7b3)*temm3;	//将AD值转换成电压值	内部参考电压2.6V,11位精度
	
	Rt=votage*10.0/(2.5-votage);//NTC负接	,求得电阻阻值
	// Rt=(2.6-votage)*10/votage;	//NTC正接	,求得电阻阻值
	temperature=1/(logf(Rt * 1000 / R_T2) / NTC_B + 1 / T2) - degreeKelvinK + trim_K;//根据RT表公式求得对应的温度值
	temm = (unsigned int)(temperature*10.0);		//将温度值放大10倍
	//个位>5,=5,<5,=0
	temm2 = temm%10;
	if(temm2 >5){
		temm = temm-(temm2-5);
	}
	if(temm2 <5){
		temm = temm-temm2;
	}	
	return temm;

猜你喜欢

转载自blog.csdn.net/LinQiPing233/article/details/89095330