From 91c62f009cb5743a952d54d4ac9661c59a28434e Mon Sep 17 00:00:00 2001 From: Kilian Bracher Date: Sun, 13 Apr 2025 15:54:31 +0200 Subject: [PATCH] add overtemp check --- AMS_Master_Code/Core/Inc/battery.h | 2 +- AMS_Master_Code/Core/Inc/config_ADBMS6830.h | 2 ++ AMS_Master_Code/Core/Inc/ts_state_machine.h | 2 +- .../Core/Lib/ADBMS6830B_Driver/Core/Inc/ADBMS_Driver.h | 3 --- AMS_Master_Code/Core/Src/battery.c | 10 ++++++++++ AMS_Master_Code/Core/Src/status_led.c | 4 ++-- 6 files changed, 16 insertions(+), 7 deletions(-) diff --git a/AMS_Master_Code/Core/Inc/battery.h b/AMS_Master_Code/Core/Inc/battery.h index 4c7a664..0158579 100644 --- a/AMS_Master_Code/Core/Inc/battery.h +++ b/AMS_Master_Code/Core/Inc/battery.h @@ -3,9 +3,9 @@ #define __BATTERY_H #include "config_ADBMS6830.h" #include "stm32h7xx_hal.h" - #include #include + extern uint16_t min_voltage; extern uint16_t max_voltage; extern struct {uint16_t min; uint16_t max;} module_voltages[N_BMS]; diff --git a/AMS_Master_Code/Core/Inc/config_ADBMS6830.h b/AMS_Master_Code/Core/Inc/config_ADBMS6830.h index 2fdaa6a..c944f23 100644 --- a/AMS_Master_Code/Core/Inc/config_ADBMS6830.h +++ b/AMS_Master_Code/Core/Inc/config_ADBMS6830.h @@ -7,6 +7,8 @@ #define N_CELLS 16 #define ADBMS_MAX_CHIP_TEMP 110 // max temperature of ADBMS6830B (not battery) in C #define ADBMS_SPI_TIMEOUT 50 // Timeout in ms +#define DEFAULT_UV 3000 // mV +#define DEFAULT_OV 4200 // mV [[maybe_unused, gnu::always_inline]] static inline void mcuAdbmsCSLow() { diff --git a/AMS_Master_Code/Core/Inc/ts_state_machine.h b/AMS_Master_Code/Core/Inc/ts_state_machine.h index 85c878d..ace534c 100644 --- a/AMS_Master_Code/Core/Inc/ts_state_machine.h +++ b/AMS_Master_Code/Core/Inc/ts_state_machine.h @@ -53,7 +53,7 @@ static inline const char *TSStateToString(TSState state) { typedef enum { TS_ERRORKIND_NONE = 0x00, - TS_ERRORKIND_SLAVE_TIMEOUT = 0x01, + TS_ERRORKIND_CELL_OVERTEMP = 0x01, TS_ERRORKIND_SLAVE_PANIC = 0x02, TS_ERRORKIND_SHUNT_TIMEOUT = 0x03, TS_ERRORKIND_SHUNT_OVERCURRENT = 0x04, diff --git a/AMS_Master_Code/Core/Lib/ADBMS6830B_Driver/Core/Inc/ADBMS_Driver.h b/AMS_Master_Code/Core/Lib/ADBMS6830B_Driver/Core/Inc/ADBMS_Driver.h index 3fd188f..aed3c78 100644 --- a/AMS_Master_Code/Core/Lib/ADBMS6830B_Driver/Core/Inc/ADBMS_Driver.h +++ b/AMS_Master_Code/Core/Lib/ADBMS6830B_Driver/Core/Inc/ADBMS_Driver.h @@ -6,9 +6,6 @@ #define ERROR_TIME_THRESH 150 // ms -#define DEFAULT_UV 3000 // mV -#define DEFAULT_OV 4200 // mV - typedef enum : uint16_t { ADBMS_NO_ERROR = 0, ADBMS_OVERTEMP, diff --git a/AMS_Master_Code/Core/Src/battery.c b/AMS_Master_Code/Core/Src/battery.c index 7766d44..a6e6417 100644 --- a/AMS_Master_Code/Core/Src/battery.c +++ b/AMS_Master_Code/Core/Src/battery.c @@ -11,6 +11,8 @@ #define MAX_ERRORS 4 // max number of errors in window before panic #define MAX_ERRORS_WINDOW_SIZE 16 // size of the error window for error detection + +#define MAX_TEMP 60 // max temperature in C uint16_t min_voltage = 0xFFFF; uint16_t max_voltage = 0; @@ -107,6 +109,14 @@ HAL_StatusTypeDef battery_update() { if (cellTemps[i][j] < module_temps[i].min) { module_temps[i].min = cellTemps[i][j]; } + + if (cellTemps[i][j] > MAX_TEMP) { + debug_log(LOG_LEVEL_ERROR, "Cell %zu on BMS %zu overtemp: %d C", j, i, cellTemps[i][j]); + can_send_error(TS_ERRORKIND_CELL_OVERTEMP, i); + ts_sm_set_error_source(TS_ERROR_SOURCE_SLAVES, TS_ERRORKIND_CELL_OVERTEMP, true); + } else { + ts_sm_set_error_source(TS_ERROR_SOURCE_SLAVES, TS_ERRORKIND_CELL_OVERTEMP, false); + } } } diff --git a/AMS_Master_Code/Core/Src/status_led.c b/AMS_Master_Code/Core/Src/status_led.c index 20d49d5..ca9546d 100644 --- a/AMS_Master_Code/Core/Src/status_led.c +++ b/AMS_Master_Code/Core/Src/status_led.c @@ -82,7 +82,7 @@ void set_led_internal_error() { * * Error -> LED_2 mapping: * TS_ERRORKIND_NONE -> off - * TS_ERRORKIND_SLAVE_TIMEOUT -> blue + * TS_ERRORKIND_CELL_OVERTEMP -> blue * TS_ERRORKIND_SLAVE_PANIC -> magenta * TS_ERRORKIND_SHUNT_TIMEOUT -> green * TS_ERRORKIND_SHUNT_OVERCURRENT -> yellow @@ -113,7 +113,7 @@ void status_led_state(TSState state, TSErrorKind error) { case TS_ERRORKIND_NONE: set_led_color(LED_2, (LedColor) {.red = 0, .green = 0, .blue = 0}); break; - case TS_ERRORKIND_SLAVE_TIMEOUT: + case TS_ERRORKIND_CELL_OVERTEMP: set_led_color(LED_2, (LedColor) {.red = 0, .green = 0, .blue = 1}); break; case TS_ERRORKIND_SLAVE_PANIC: