add check for implausible temperatures

This commit is contained in:
Kilian Bracher 2025-06-05 14:33:31 +02:00
parent 37cec353ec
commit 96b8e12f9a
Signed by: k.bracher
SSH Key Fingerprint: SHA256:mXpyZkK7RDiJ7qeHCKJX108woM0cl5TrCvNBJASu6lM
2 changed files with 17 additions and 0 deletions

View File

@ -6,6 +6,10 @@
#include <stdint.h>
#include <stddef.h>
#define MAX_PLAUSIBLE_TEMP 15000 // 150.0°C
#define MIN_PLAUSIBLE_TEMP -4000 // -40.0°C
#define MAX_ERRORED_TEMP 3 // number of implausible temperatures before panic (per BMS module)
#define ADBMS_NO_LOGGING_DEFS
#include "ADBMS_Driver.h"

View File

@ -135,9 +135,22 @@ HAL_StatusTypeDef battery_update() {
}
// Process temperature values
int failed_sensors = 0;
for (size_t j = 0; j < 10; j++) { // 10 GPIOs
battery.module[i].cellTemps[j] = ntc_mv_to_celsius(bms_data[i].auxVoltages[j]);
if (battery.module[i].cellTemps[j] > MAX_PLAUSIBLE_TEMP || battery.module[i].cellTemps[j] < MIN_PLAUSIBLE_TEMP) {
debug_log(LOG_LEVEL_ERROR, "Sensor %u on BMS %u has implausible temperature: %d0 mC", j, i,
battery.module[i].cellTemps[j]);
if (++failed_sensors >= MAX_ERRORED_TEMP) {
// If too many implausible temperatures, panic
debug_log(LOG_LEVEL_ERROR, "Too many implausible temperatures on BMS %u, erroring...", i);
update_error_window(true, i);
return HAL_ERROR;
}
}
// For new battery struct
if (battery.module[i].cellTemps[j] > battery.pack.max_temp) {
battery.pack.max_temp = battery.module[i].cellTemps[j];