- 测温电路原理图。
- 测温程序
//温度-电阻表 索引为温度,值为电阻值(欧姆)
//温度区间10度,从0度开始
static float table_ntc[16] =
{
32660,19900,12490,8058,5326,3602,2488,1751,1256,916.4,679.2, //0 - 100
510.8,389.4,300.6,234.8,185.4 //110 - 150
};
//AD值转温度 3.3v--10k--ntc(10k)--gnd
float get_temp_by_ad(int value_ad)
{
float v_r = value_ad/4095.0f * 3.3f; //NTC电压
float R = (10000*v_r)/(3.3f-v_r); //当前NTC电阻
float temp = 0;
//查表得实际温度
for (size_t i = 0; i < 16; i++)
{
float R0 = table_ntc[i]; //参考阻值1
float R1 = table_ntc[i+1]; //参考阻值2
if(R<=R0)
{
if (R>=R1)
{
temp = i*10 + (R0-R)/(R0-R1)*10;
break;
}
else if(i >= 15)
{
temp = 150; //温度最大值
}
}
else
{
temp = 0; //温度最小值
}
}
return temp;
}