properly handle negative temperatures
This commit is contained in:
parent
bd078764e4
commit
b9220a04e9
@ -12,7 +12,7 @@
|
|||||||
#define NTC_D1 2.18765E-07f
|
#define NTC_D1 2.18765E-07f
|
||||||
|
|
||||||
#define VREF 3000.0f // 3V
|
#define VREF 3000.0f // 3V
|
||||||
#define TEMP_CONV 100.0f // 655.35°C max
|
#define TEMP_CONV 100.0f // i.e. a value of 1500 means 15.00 °C (range -327.68 to 327.67 °C)
|
||||||
#define CELSIUS_TO_KELVIN 273.15f
|
#define CELSIUS_TO_KELVIN 273.15f
|
||||||
#define CELSIUS_TO_KELVIN_SCALED (CELSIUS_TO_KELVIN * TEMP_CONV)
|
#define CELSIUS_TO_KELVIN_SCALED (CELSIUS_TO_KELVIN * TEMP_CONV)
|
||||||
|
|
||||||
@ -22,9 +22,9 @@
|
|||||||
// R_T/R_0 = 1 / V_REF / ADC - 1
|
// R_T/R_0 = 1 / V_REF / ADC - 1
|
||||||
|
|
||||||
[[gnu::optimize("fast-math")]]
|
[[gnu::optimize("fast-math")]]
|
||||||
static inline uint16_t ntc_mv_to_celsius(int16_t adc) {
|
static inline int16_t ntc_mv_to_celsius(int16_t adc) {
|
||||||
const float log_ohms = logf(1 / ((VREF / adc) - 1));
|
const float log_ohms = logf(1 / ((VREF / adc) - 1));
|
||||||
return (uint16_t)(TEMP_CONV / (NTC_A1 + NTC_B1 * log_ohms + NTC_C1 * log_ohms * log_ohms +
|
return (int16_t)(TEMP_CONV / (NTC_A1 + NTC_B1 * log_ohms + NTC_C1 * log_ohms * log_ohms +
|
||||||
NTC_D1 * log_ohms * log_ohms * log_ohms) - CELSIUS_TO_KELVIN_SCALED);
|
NTC_D1 * log_ohms * log_ohms * log_ohms) - CELSIUS_TO_KELVIN_SCALED);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
@ -23,7 +23,7 @@ extern struct {
|
|||||||
} pack;
|
} pack;
|
||||||
struct {
|
struct {
|
||||||
BMS_Chip * chip;
|
BMS_Chip * chip;
|
||||||
int16_t cellTemps[10];
|
int16_t cellTemps[10]; // °C with scaled factor 100, so 15000 = 150.0 °C
|
||||||
struct {
|
struct {
|
||||||
uint8_t min_v_idx : 4; uint8_t max_v_idx : 4; // cell index: 0-15
|
uint8_t min_v_idx : 4; uint8_t max_v_idx : 4; // cell index: 0-15
|
||||||
uint8_t min_t_idx : 4; uint8_t max_t_idx : 4; // used like this: battery->module[i].chip->cellVoltages[min_v_idx]
|
uint8_t min_t_idx : 4; uint8_t max_t_idx : 4; // used like this: battery->module[i].chip->cellVoltages[min_v_idx]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user