From 96b8e12f9aed09dd56f44f5a28adaaa1a4a44414 Mon Sep 17 00:00:00 2001 From: Kilian Bracher Date: Thu, 5 Jun 2025 14:33:31 +0200 Subject: [PATCH] add check for implausible temperatures --- AMS_Master_Code/Core/Inc/battery.h | 4 ++++ AMS_Master_Code/Core/Src/battery.c | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/AMS_Master_Code/Core/Inc/battery.h b/AMS_Master_Code/Core/Inc/battery.h index aaecfcc..575f924 100644 --- a/AMS_Master_Code/Core/Inc/battery.h +++ b/AMS_Master_Code/Core/Inc/battery.h @@ -6,6 +6,10 @@ #include #include +#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" diff --git a/AMS_Master_Code/Core/Src/battery.c b/AMS_Master_Code/Core/Src/battery.c index cc1f11a..c315220 100644 --- a/AMS_Master_Code/Core/Src/battery.c +++ b/AMS_Master_Code/Core/Src/battery.c @@ -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];