add overtemp check

This commit is contained in:
Kilian Bracher 2025-04-13 15:54:31 +02:00
parent bdddc49dab
commit 91c62f009c
Signed by: k.bracher
SSH Key Fingerprint: SHA256:mXpyZkK7RDiJ7qeHCKJX108woM0cl5TrCvNBJASu6lM
6 changed files with 16 additions and 7 deletions
AMS_Master_Code/Core

@ -3,9 +3,9 @@
#define __BATTERY_H #define __BATTERY_H
#include "config_ADBMS6830.h" #include "config_ADBMS6830.h"
#include "stm32h7xx_hal.h" #include "stm32h7xx_hal.h"
#include <stdint.h> #include <stdint.h>
#include <stddef.h> #include <stddef.h>
extern uint16_t min_voltage; extern uint16_t min_voltage;
extern uint16_t max_voltage; extern uint16_t max_voltage;
extern struct {uint16_t min; uint16_t max;} module_voltages[N_BMS]; extern struct {uint16_t min; uint16_t max;} module_voltages[N_BMS];

@ -7,6 +7,8 @@
#define N_CELLS 16 #define N_CELLS 16
#define ADBMS_MAX_CHIP_TEMP 110 // max temperature of ADBMS6830B (not battery) in C #define ADBMS_MAX_CHIP_TEMP 110 // max temperature of ADBMS6830B (not battery) in C
#define ADBMS_SPI_TIMEOUT 50 // Timeout in ms #define ADBMS_SPI_TIMEOUT 50 // Timeout in ms
#define DEFAULT_UV 3000 // mV
#define DEFAULT_OV 4200 // mV
[[maybe_unused, gnu::always_inline]] [[maybe_unused, gnu::always_inline]]
static inline void mcuAdbmsCSLow() { static inline void mcuAdbmsCSLow() {

@ -53,7 +53,7 @@ static inline const char *TSStateToString(TSState state) {
typedef enum { typedef enum {
TS_ERRORKIND_NONE = 0x00, TS_ERRORKIND_NONE = 0x00,
TS_ERRORKIND_SLAVE_TIMEOUT = 0x01, TS_ERRORKIND_CELL_OVERTEMP = 0x01,
TS_ERRORKIND_SLAVE_PANIC = 0x02, TS_ERRORKIND_SLAVE_PANIC = 0x02,
TS_ERRORKIND_SHUNT_TIMEOUT = 0x03, TS_ERRORKIND_SHUNT_TIMEOUT = 0x03,
TS_ERRORKIND_SHUNT_OVERCURRENT = 0x04, TS_ERRORKIND_SHUNT_OVERCURRENT = 0x04,

@ -6,9 +6,6 @@
#define ERROR_TIME_THRESH 150 // ms #define ERROR_TIME_THRESH 150 // ms
#define DEFAULT_UV 3000 // mV
#define DEFAULT_OV 4200 // mV
typedef enum : uint16_t { typedef enum : uint16_t {
ADBMS_NO_ERROR = 0, ADBMS_NO_ERROR = 0,
ADBMS_OVERTEMP, ADBMS_OVERTEMP,

@ -11,6 +11,8 @@
#define MAX_ERRORS 4 // max number of errors in window before panic #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_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 min_voltage = 0xFFFF;
uint16_t max_voltage = 0; uint16_t max_voltage = 0;
@ -107,6 +109,14 @@ HAL_StatusTypeDef battery_update() {
if (cellTemps[i][j] < module_temps[i].min) { if (cellTemps[i][j] < module_temps[i].min) {
module_temps[i].min = cellTemps[i][j]; 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);
}
} }
} }

@ -82,7 +82,7 @@ void set_led_internal_error() {
* *
* Error -> LED_2 mapping: * Error -> LED_2 mapping:
* TS_ERRORKIND_NONE -> off * TS_ERRORKIND_NONE -> off
* TS_ERRORKIND_SLAVE_TIMEOUT -> blue * TS_ERRORKIND_CELL_OVERTEMP -> blue
* TS_ERRORKIND_SLAVE_PANIC -> magenta * TS_ERRORKIND_SLAVE_PANIC -> magenta
* TS_ERRORKIND_SHUNT_TIMEOUT -> green * TS_ERRORKIND_SHUNT_TIMEOUT -> green
* TS_ERRORKIND_SHUNT_OVERCURRENT -> yellow * TS_ERRORKIND_SHUNT_OVERCURRENT -> yellow
@ -113,7 +113,7 @@ void status_led_state(TSState state, TSErrorKind error) {
case TS_ERRORKIND_NONE: case TS_ERRORKIND_NONE:
set_led_color(LED_2, (LedColor) {.red = 0, .green = 0, .blue = 0}); set_led_color(LED_2, (LedColor) {.red = 0, .green = 0, .blue = 0});
break; break;
case TS_ERRORKIND_SLAVE_TIMEOUT: case TS_ERRORKIND_CELL_OVERTEMP:
set_led_color(LED_2, (LedColor) {.red = 0, .green = 0, .blue = 1}); set_led_color(LED_2, (LedColor) {.red = 0, .green = 0, .blue = 1});
break; break;
case TS_ERRORKIND_SLAVE_PANIC: case TS_ERRORKIND_SLAVE_PANIC: