IAR-YT-HEAT/DOC/temp_table.h

89 lines
3.7 KiB
C
Raw Permalink Normal View History

2025-08-06 04:59:57 +00:00
#ifndef TEMP_TABLE_H
#define TEMP_TABLE_H
#include <stdint.h>
/**
* @file temp_table.h
* @brief NTC热敏电阻温度- (:10Ω)
*
* .txt
* 238
*
*/
const uint16_t r_temp[] = {
9533, 9265, 9005, 8754, 8510, 8273, 8044, 7822, 7606, 7398,
7195, 6999, 6808, 6624, 6444, 6271, 6102, 5939, 5780, 5626,
5476, 5331, 5191, 5054, 4921, 4792, 4667, 4546, 4428, 4314,
4202, 4094, 3989, 3887, 3788, 3692, 3598, 3508, 3419, 3333,
3250, 3169, 3090, 3013, 2938, 2866, 2795, 2727, 2660, 2595,
2532, 2471, 2411, 2353, 2296, 2241, 2187, 2135, 2085, 2035,
1987, 1940, 1895, 1850, 1807, 1765, 1724, 1684, 1645, 1607,
1570, 1534, 1499, 1465, 1431, 1399, 1367, 1337, 1307, 1221,
1194, 1167, 1141, 1116, 1092, 1068, 1044, 1022, 1000, 978,
957, 936, 916, 896, 877, 858, 840, 822, 805, 788,
771, 755, 739, 724, 709, 694, 680, 666, 652, 639,
626, 613, 600, 588, 576, 565, 553, 542, 531, 521,
510, 500, 490, 480, 471, 462, 453, 444, 435, 427,
418, 410, 402, 395, 387, 380, 372, 365, 358, 351,
345, 338, 332, 326, 320, 314, 308, 302, 296, 291,
286, 280, 275, 270, 265, 260, 256, 251, 238, 233,
229, 225, 221, 217, 213, 210, 206, 202, 199, 195,
192, 189, 185, 182, 179, 176, 173, 170, 167, 164,
161, 159, 156, 153, 151, 148, 146, 143, 141, 139,
136, 134, 132, 130, 127, 125, 123, 121, 119, 117,
115, 114, 112, 110, 108, 107, 105, 103, 101, 100,
98, 97, 95, 94, 92, 91, 89, 88, 87, 85,
84, 83, 81, 80, 79, 78, 77, 75, 74, 73,
72, 71, 70, 69, 68, 67, 66
};
/**
* @brief 线
* @param resistance 10Ω
* @return
*
* 2380-237
* 0.5°C温度步进
* -20.0°C 98.5°C
*/
static inline float get_temp_from_resistance(uint16_t resistance) {
int i = 0;
const int array_size = 238; // 实际数组大小
const int last_index = array_size - 1; // 最后一个索引237
// 处理超出上限的电阻值(大于最大电阻值)
if (resistance >= r_temp[0]) {
i = 0; // 使用第一个区间进行外推
}
// 处理低于下限的电阻值(小于最小电阻值)
else if (resistance <= r_temp[last_index]) {
i = last_index - 1; // 使用最后一个区间进行外推索引236-237
}
// 在有效范围内查找区间
else {
// 遍历237个区间索引0-236对应区间0-1,1-2,...,236-237
for (; i < last_index; i++) {
// 检查电阻值是否在当前区间 [r_temp[i], r_temp[i+1]) 内
if (resistance <= r_temp[i] && resistance > r_temp[i+1]) {
break;
}
}
}
// 获取当前区间的电阻边界值
float R_high = r_temp[i]; // 较高电阻值(对应较低温度)
float R_low = r_temp[i+1]; // 较低电阻值(对应较高温度)
// 获取当前区间的温度边界值
float T_high = -20.0f + 0.5f * i; // 较低温度
float T_low = -20.0f + 0.5f * (i+1); // 较高温度
// 最高温度:-20 + 0.5 * 237 = 98.5°C
// 线性插值计算温度
// 公式T = T_high + (R_high - resistance) * (T_low - T_high) / (R_high - R_low)
return T_high + (R_high - resistance) * (T_low - T_high) / (R_high - R_low);
}
#endif // TEMP_TABLE_H