NTC -10K测量温度最便宜常用,搜到博主简易的NTC-10K-3950测温_ntc测温电路_chengzidun的博客-CSDN博客
简易测温有点不满足需求,于是对该程序加以修改,实现稍微精确的测温,代码如下:
#define TABLE_SIZE 181
#define TEMP_VALUE_MAX 125000
#define TEMP_VALUE_MIN -55000
const uint32_t g_rvTable[TABLE_SIZE] = {//-55 - 125
1034600, 959006, 889452, 825419, 766434,
712066, 661926, 615656, 572934, 533466, 496983, 463240, 432015, 403104, 376320,
351495, 328472, 307110, 287279, 268859, 251741, 235826, 221021, 207242, 194412,
182460, 171320, 160932, 151241, 142196, 133750, 125859, 118485, 111589, 105139,
99102, 93450, 88156, 83195, 78544, 74183, 70091, 66250, 66643, 59255,
56071, 53078, 50263, 47614, 45121, 42774, 40563, 38480, 36517, 34665,
32919,
31270, 29715, 28246, 26858, 25547, 24307, 23135, 22026, 20977, 19987,
19044, 18154, 17310, 16510, 15752, 15034, 14352, 13705, 13090, 12507,
11953, 11427, 10927, 10452, 10000, 9570, 9161, 8771, 8401, 8048,
7712, 7391, 7086, 6795, 6518, 6254, 6001, 5761, 5531, 5311,
5102, 4902, 4710, 4528, 4353, 4186, 4026, 3874, 3728, 3588,
3454, 3326, 3203, 3085, 2973, 2865, 2761, 2662, 2567, 2476,
2388, 2304, 2223, 2146, 2072, 2000, 1932, 1866, 1803, 1742,
1684, 1627, 1573, 1521, 1471, 1423, 1377, 1332, 1289, 1248,
1208, 1170, 1133, 1097, 1063, 1030, 998, 968, 938, 909,
882, 855, 829, 805, 781, 758, 735, 714, 693, 673,
653, 635, 616, 599, 582, 565, 550, 534, 519, 505,
491, 478, 465, 452, 440, 428, 416, 405, 395, 384,
374, 364, 355, 345, 337
};
int32_t Get_Temperature_Table_Calc(uint32_t Res)
{
uint8_t mid_point =0;
uint8_t start_point=0;
uint8_t end_point=TABLE_SIZE-1;
uint32_t comp_ref=0;
uint8_t index=0;
if(Res>=g_rvTable[0])return TEMP_VALUE_MIN;
else if(Res<=g_rvTable[end_point])return TEMP_VALUE_MAX;
do{
mid_point =start_point+((end_point-start_point)/2);
comp_ref =g_rvTable[mid_point];
if(Res==comp_ref){
return ((int32_t)mid_point-55)*1000;
}else if(Res>comp_ref){
index =mid_point-start_point+1;
end_point = mid_point;
}else{
index =end_point-mid_point+1;
start_point = mid_point;
}
}while(index>4);
for(index+=start_point;start_pointg_rvTable[start_point+1])){
float k =(float)(g_rvTable[start_point]-g_rvTable[start_point+1])/ -1000;
float b =(float)g_rvTable[start_point+1]-(((float)start_point-54)*1000*k);
return (int32_t)((float)Res-b)/k;
}
}
return TEMP_VALUE_MAX;
}
不管NTC是上拉还是下拉,经过计算很容易算出NTC实际电阻值,传入函数 Get_Temperature_Table_Calc() Res (单位欧姆)即可得到温度值(/1000 =实际温度)