Files
jiacun-20s-200A/MOUDLE/NTC.c
T
2026-08-25 17:30:40 +08:00

173 lines
5.1 KiB
C

/**
******************************************************************************
* @file tim.c
* @author Jerry
* @version V2.1
* @date 19-April-2022
* @brief tim program body.
******************************************************************************
* @attention
*
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "stm32f10x.h"
#include "global.h"
#define SHORT_CIRCUIT_THRESHOLD 70
#define OPEN_CIRCUIT_THRESHOLD 33000
uint8_t ucTempeMiddle;
/*温度电阻对照表*/
//4根温度线——深圳诺睿斯:MF52D103F3950FCL500XH
//单位10欧
//-55 - +125
uint16_t const NTC_103AT[181]=
{
58354, 55464, 52696, 50048, 47515,
45097, 42789, 40589, 38492, 36496, 34597, 32791, 31075, 29444, 27896,
26427, 25034, 23713, 22460, 21273, 20148, 19083, 18075, 17120, 16216,
15361, 14551, 13785, 13061, 12376, 11728, 11114, 10535, 9986, 9468,
8977, 8513, 8075, 7660, 7267, 6896, 6545, 6212, 5898, 5601,
5319, 5053, 4801, 4562, 4336, 4122, 3920, 3728, 3546, 3374,
3211, 3057, 2910, 2771, 2639, 2515, 2396, 2284, 2177, 2076,
1978, 1889, 1802, 1720, 1642, 1568, 1497, 1430, 1366, 1306,
1248, 1193, 1141, 1092, 1044, 1000, 957, 916, 877, 840,
805, 771, 739, 709, 679, 652, 625, 600, 576, 552,
530, 509, 489, 470, 452, 434, 417, 401, 386, 371,
358, 344, 331, 318, 306, 295, 284, 274, 264, 254,
245, 236, 228, 220, 212, 205, 198, 191, 184, 178,
172, 166, 160, 155, 150, 145, 140, 135, 131, 126,
122, 118, 115, 111, 107, 104, 101, 97, 94, 91,
89, 86, 83, 81, 78, 76, 74, 71, 69, 67,
65, 63, 61, 60, 58, 56, 55, 53, 52, 50,
49, 47, 46, 45, 43, 42, 41, 40, 39, 38,
37, 36, 35, 34, 33, 32
};
//板贴热敏电阻——南京时恒:CMFA 103F3950
//单位10欧
//-40 - +125
uint16_t const NTC_103AT_CMFA[166]=
{
34527, 32279, 30192, 28254, 26454, 24781, 23225, 21777, 20429, 19173,
18003, 16912, 15894, 14944, 14057, 13228, 12452, 11726, 11048, 10413,
9818, 9261, 8740, 8251, 7792, 7362, 6958, 6579, 6223, 5889,
5574, 5278, 5000, 4738, 4491, 4259, 4040, 3833, 3638, 3454,
3281, 3117, 2963, 2817, 2680, 2549, 2426, 2309, 2199, 2094,
1995, 1902, 1813, 1729, 1649, 1574, 1502, 1434, 1369, 1308,
1250, 1195, 1142, 1092, 1045, 1000, 957, 916, 877, 840,
804, 771, 739, 708, 679, 652, 625, 600, 576, 553,
531, 510, 490, 471, 452, 435, 418, 402, 387, 372,
358, 345, 332, 320, 308, 297, 286, 276, 266, 256,
247, 238, 230, 222, 214, 207, 200, 193, 186, 180,
174, 168, 162, 157, 152, 147, 142, 137, 133, 129,
124, 120, 117, 113, 109, 106, 103, 100, 96, 94,
91, 88, 85, 83, 80, 78, 76, 73, 71, 69,
67, 65, 63, 61, 60, 58, 56, 55, 53, 52,
50, 49, 48, 46, 45, 44, 43, 42, 41, 40,
39, 38, 37, 36, 35, 34
};
//根据NTC阻值计算温度值:-55~125
//返回的温度值需要-2731
uint16_t TEMP_Cal(uint16_t ntcR)
{
uint8_t i;
uint16_t tempcalcu, temperature;
tempcalcu = ntcR ;
if(tempcalcu >= NTC_103AT[0])
{
temperature = 2731-550; //温度值小于-55度时 =-55度
}
else if(tempcalcu <= NTC_103AT[180])
{
temperature = 2731+1250; //温度值大于125度时 =125度
}
else
{
i = ucTempeMiddle;
if(tempcalcu > NTC_103AT[i])
{
for(i=ucTempeMiddle - 1; i>0; i--)
{
if(tempcalcu <= NTC_103AT[i]) //NTC103AT[i+1]<resis<NTC103AT[i]
{
break;
}
}
}
else
{
for(i=ucTempeMiddle+1; i<180; i++)
{
if(tempcalcu > NTC_103AT[i]) //NTC103AT[i-1]<resis<NTC103AT[i]
{
break;
}
}
i--;
}
ucTempeMiddle = i;
temperature = (uint16_t)(ucTempeMiddle-55)*10 + (NTC_103AT[i]-tempcalcu)*10 / (NTC_103AT[i]-NTC_103AT[i+1])+2731;
}
return temperature;
}
//根据NTC_CMFA阻值计算温度值-40~125
//返回的温度值需要-2731
uint16_t TEMP_Cal_CMFA(uint16_t ntcR)
{
uint8_t i;
uint16_t tempcalcu, temperature;
tempcalcu = ntcR ;
if(tempcalcu >= NTC_103AT_CMFA[0])
{
temperature = 2731-400; //温度值小于-40度时 =-40度
}
else if(tempcalcu <= NTC_103AT_CMFA[165])
{
temperature = 2731+1250; //温度值大于125度时 =125度
}
else
{
i = ucTempeMiddle;
if(tempcalcu > NTC_103AT_CMFA[i])
{
for(i=ucTempeMiddle - 1; i>0; i--)
{
if(tempcalcu <= NTC_103AT_CMFA[i]) //NTC103AT[i+1]<resis<NTC103AT[i]
{
break;
}
}
}
else
{
for(i=ucTempeMiddle+1; i<165; i++)
{
if(tempcalcu > NTC_103AT_CMFA[i]) //NTC103AT[i-1]<resis<NTC103AT[i]
{
break;
}
}
i--;
}
ucTempeMiddle = i;
temperature = (uint16_t)(ucTempeMiddle-40)*10 + (NTC_103AT_CMFA[i]-tempcalcu)*10 / (NTC_103AT_CMFA[i]-NTC_103AT_CMFA[i+1])+2731;
}
return temperature;
}