NTC 查表和公式
查表法
/** ************************************************************Author:Liming*** * @brief NTC阻值表 * @param float型电阻值 * @retval None *****************************************************************0X49E7FC7B****/ //NTC R25=10K 1% B25/50=3950K 1% #define NTC_TAB_SIZE 181 code float NTC_TAB[NTC_TAB_SIZE]={ 739.500, 705.664, 669.165, 631.466, 593.686, 556.644, 520.911, 486.858, 454.704, 424.553,//0-9 -55 to -46 396.426, 370.283, 346.049, 323.623, 302.890, 283.730, 266.022, 249.649, 234.498, 220.466,//10-19 -45 to -36 207.454, 195.372, 184.139, 173.681, 163.931, 154.827, 146.315, 138.347, 130.877, 123.866,//20-29 -35 to -26 117.280, 111.084, 105.252, 99.756, 94.573, 89.682, 85.063, 80.699, 76.574, 72.672,//30-39 -25 to -16 68.982, 65.489, 62.183, 59.052, 56.087, 53.280, 50.620, 48.100, 45.712, 43.450,//40-49 -15 to -6 41.306, 39.274, 37.349, 35.524, 33.795, 32.116, 30.601, 29.128, 27.732, 26.408,//50-59 -5 to 4 25.152, 23.962, 22.833, 21.762, 20.746, 19.783, 18.868, 18.000, 17.177, 16.395,//60-69 5 to 14 15.652, 14.947, 14.277, 13.641, 13.036, 12.461, 11.915, 11.395, 10.901, 10.431,//70-79 15 to 24 10.000, 9.557, 9.151, 8.765, 8.397, 8.047, 7.712, 7.394, 7.090, 6.800,//80-89 25 to 34 6.523, 6.259, 6.008, 5.767, 5.537, 5.318, 5.108, 4.907, 4.716, 4.532,//90-99 35 to 44 4.357, 4.189, 4.029, 3.875, 3.728, 3.588, 3.453, 3.324, 3.200, 3.081,//00-09 45 to 54 2.968, 2.859, 2.754, 2.654, 2.558, 2.466, 2.377, 2.293, 2.211, 2.133,//10-19 55 to 64 2.058, 1.986, 1.917, 1.850, 1.786, 1.725, 1.666, 1.610, 1.555, 1.503,//20-29 65 to 74 1.452, 1.404, 1.358, 1.313, 1.270, 1.228, 1.189, 1.150, 1.113, 1.078,//30-39 75 to 84 1.044, 1.011, 0.979, 0.948, 0.919, 0.890, 0.863, 0.837, 0.811, 0.787,//40-49 85 to 94 0.763, 0.740, 0.718, 0.697, 0.676, 0.657, 0.637, 0.619, 0.601, 0.584,//50-59 95 to 104 0.567, 0.551, 0.535, 0.520, 0.505, 0.491, 0.478, 0.464, 0.451, 0.439,//60-69 105 to 114 0.427, 0.415, 0.404, 0.393, 0.382, 0.371, 0.361, 0.351, 0.342, 0.333,//70-79 115 to 124 0.324 };
/** ************************************************************Author:Liming*** * @brief 根据NTC阻值查表计算当前温度 STC8G2K 24M 约 140us * @param Rntc float型电阻值 * @retval None *****************************************************************0X49E7FC7B****/ char Calculate_Temperature(float Rntc) { uint8_t st,ed,m; uint8_t i; st = 0; ed = NTC_TAB_SIZE-1; i = 0; //2分法查表,表中数据阻值从大到小 if (Rntc >= NTC_TAB[st])return st; else if(Rntc <= NTC_TAB[ed]) return ed; while (st < ed) { m = (st+ed)/2; if (Rntc == NTC_TAB[m])break; if ((Rntc < NTC_TAB[m])&&(Rntc>NTC_TAB[m+1]))break; if (Rntc > NTC_TAB[m]) ed = m; else st = m; if (i++ >= 181) break; } if (st>ed) return 0; return (m-55); }
公式法
/** ************************************************************Author:Liming*** * @brief 根据NTC阻值计算当前温度,因为使用了log所以需要包含头文件math.h
STC8G2K 24M 约500us * @param Rntc float型的电阻值 * @retval None *****************************************************************0X49E7FC7B****/ float BSP_ADC_GetTemperature(float Rntc) { float N1,N2,N3,N4; float BX = 3950;//NTC B值 float T25 = 298.15;//额定温度 绝对温度+常温273.15+25 float R25 = 10;// N1 = (log(Rntc)-log(R25))/BX; N2 = 1/T25 + N1; N3 = 1/N2; N4 = N3-273.15; return N4; }