push script to generate NTC lut

This commit is contained in:
Alessandro Mauri 2026-04-17 22:21:18 +02:00
parent 4591e6e04a
commit 55bee1a5d8
2 changed files with 66 additions and 6 deletions

View file

@ -28,11 +28,12 @@
// constants
// LUT for converting NTC readings to degrees kelvin
// Nominal: 1kOhm, Beta: 3380, Step: 64
// TODO: Since the board temperature is almost always in the 300-200K range add
// more steps in order to better represent that interval
const uint8_t ntc_step_size = 64;
const int16_t ntc_table[64] = {
1180, 197, 155, 133, 119, 108, 100, 93, 87, 82, 77, 73, 69, 66, 63, 60, 57, 54, 52, 50, 47, 45, 43, 41, 39, 37, 35, 34, 32, 30, 28, 27, 25, 23, 22, 20, 19, 17, 15, 14, 12, 11, 9, 7, 6, 4, 2, 0, -1, -3, -5, -7, -9, -11, -14, -16, -19, -22, -25, -28, -33, -38, -44, -55
const int16_t ntc_lut[] = {
1316, 197, 155, 133, 119, 108, 100, 93, 87, 82, 77, 73, 69, 66, 63, 60,
57, 54, 52, 50, 47, 45, 43, 41, 39, 37, 35, 34, 32, 30, 28, 27,
25, 23, 22, 20, 19, 17, 15, 14, 12, 11, 9, 7, 6, 4, 2, 0,
-1, -3, -5, -7, -9, -11, -14, -16, -19, -22, -25, -28, -32, -38, -44, -55
};
@ -50,8 +51,8 @@ static inline int16_t get_temp_k(uint16_t adc_reading)
if (adc_reading > 4095) return 0;
uint8_t index = adc_reading / ntc_step_size;
uint8_t remainder = adc_reading % ntc_step_size;
int16_t temp_base = index < 64 ? ntc_table[index] : 0;
int16_t temp_next = index < 63 ? ntc_table[index + 1] : temp_base;
int16_t temp_base = index < 64 ? ntc_lut[index] : 0;
int16_t temp_next = index < 63 ? ntc_lut[index + 1] : temp_base;
return temp_base + ((temp_next - temp_base) * remainder)/ntc_step_size;
}