BCU/app/stm32fxxx_app/table/table_ntc.c

116 lines
3.6 KiB
C
Raw Normal View History

2024-11-26 15:52:49 +08:00
#include "kit_data.h"
#include "table_comm.h"
//温感demo 单位为Ω -41~126℃
const uint16_t table_ntc1[BSP_NTC_TABLE_LEN]=
{
24861, 22861, 21401, 19913, 18801, 17567, 16412, 15339, 14555, 13579, 12859, 11952, 11330, 10745, 10193,
9673, 9183, 8721, 8285, 7873, 7485, 7118, 6771, 6443, 6133, 5840, 5562, 5300, 5051, 4816, 4593,
4381, 4181, 3991, 3811, 3640, 3477, 3323, 3177, 3038, 2905, 2780, 2660, 2546, 2438, 2335, 2237,
2144, 2055, 1970, 1890, 1813, 1739, 1669, 1602, 1539, 1478, 1420, 1364, 1311, 1261,
1212, 1166, 1122, 1079, 1039, 1000,
963, 927, 893, 861, 830, 800, 771, 743, 717, 692, 667, 644,
622, 600, 580, 560, 541, 523, 505, 488, 472, 457, 442, 427,
413, 400, 387, 375, 363, 351, 340, 330, 319, 309, 300, 291,
282, 273, 265, 257, 249, 242, 235, 228, 221, 215, 209, 203,
197, 191, 186, 180, 175, 170, 166, 161, 157, 152, 148, 144,
140, 137, 133, 129, 126, 123, 119, 116, 113, 110, 107, 105, 102,
99, 97, 95, 92, 90, 88, 85, 83, 81, 79, 77, 76, 74, 72,
70, 69, 67, 65, 64, 62, 61, 60, 58, 57, 56, 55, 53, 51
};
//时恒_CWF4B_103F3950 温感demo 10k
const uint16_t table_ntc2[BSP_NTC_TABLE_LEN]=
{
38000, 30280, 28839, 27388, 25947, 24534, 23162, 21841, 20579, 19380, 18246,
17177, 16172, 15230, 14347, 13521, 12749, 12026, 11350, 10718, 10125,
9570, 9049, 8560, 8100, 7668, 7262, 6879, 6518, 6177, 5856, 5553, 5267, 4996,
4741, 4499, 4271, 4055, 3850, 3657, 3474, 3301, 3137, 2982, 2836, 2697, 2566,
2441, 2323, 2212, 2106, 2001, 1912, 1822, 1737, 1656, 1580, 1507, 1438, 1373,
1311, 1252, 1197, 1144, 1093, 1045, 1000,
957, 916, 877, 839, 804, 770, 738, 707, 678, 651, 624, 599, 575, 552, 530, 509,
489, 470, 451, 434, 417, 401, 386, 371, 357, 344, 331, 319, 307, 296, 285, 275,
265, 256, 247, 238, 229, 221, 214, 206, 199, 192, 186, 180, 174, 168, 162, 157,
152, 147, 142, 137, 133, 129, 124, 121, 117, 113, 110, 106, 103, 100,
97, 94, 91, 88, 85, 83, 80, 78, 76, 74, 71, 69, 67, 65, 64, 62, 60, 58, 57, 55,
54, 52, 51, 49, 48, 47, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 25
};
typedef struct
{
uint16_t rate;
const uint16_t *table;
}NtcTable;
NtcTable ntc_table_list[kNtcType_End] =
{
{10, table_ntc1},
{10, table_ntc2},
};
uint16_t bms_get_linear_temp(int32_t res, NtcType tab)
{
int32_t left = -1, right = BSP_NTC_TABLE_LEN, mid;
uint16_t rate = ntc_table_list[tab].rate;
if(tab >= kNtcType_End)
{
tab = kNtcType_SH10K;
}
const uint16_t * table = ntc_table_list[tab].table;
while ((left + 1) != right)
{
mid = left + ((right - left) >> 1);
if (table[mid] * rate > res)
{
left = mid;
}
else if (table[mid] * rate < res)
{
right = mid;
}
else
{
return mid * 10 - 410 + 500;
}
}
if (left == -1)
{
return (uint16_t)KIT_NTC_TEMP_OPEN_VALUE; //-50度
}
else if (right == BSP_NTC_TABLE_LEN)
{
return (uint16_t)KIT_NTC_TEMP_SHORT_VALUE; //125度
}
else
{
left = table[right] * rate - table[right - 1] * rate;
mid = (res - (int32_t)table[right] * rate + left * right) * 10 / left - 410 + 500;
}
return mid;
}
NtcType bms_get_temp_table(NtcType tab, uint8_t *buf)
{
uint32_t addr = 0;
if(tab >= kNtcType_End)
{
tab = kNtcType_SH10K;
}
//长度占位
WRITE_LT_INT16U(buf, addr, 0);
WRITE_LT_INT16U(buf, addr, tab);
WRITE_LT_INT16U(buf, addr, ntc_table_list[tab].rate);
kit_copy_buf(&buf[6], ntc_table_list[tab].table, BSP_NTC_TABLE_LEN * 2);
addr += BSP_NTC_TABLE_LEN * 2 + 2;
WRITE_LT_INT16U_BY_CONST_POS(buf, 0, addr);
kit_append_crc16(buf, addr - 2);
return tab;
}