From fa3ef04b583487341dd7eabc9a0caabb50926aed Mon Sep 17 00:00:00 2001 From: "Jasper v. Blanckenburg" Date: Thu, 23 May 2024 00:39:18 +0200 Subject: [PATCH] Add regen overcurrent limit --- Core/Inc/shunt_monitoring.h | 7 ++++--- Core/Src/shunt_monitoring.c | 5 +++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Core/Inc/shunt_monitoring.h b/Core/Inc/shunt_monitoring.h index 5c96a2a..41cbca7 100644 --- a/Core/Inc/shunt_monitoring.h +++ b/Core/Inc/shunt_monitoring.h @@ -5,9 +5,10 @@ #include "stm32f3xx_hal.h" -#define SHUNT_TIMEOUT 300 // ms -#define SHUNT_THRESH_OVERCURRENT 300000 // mA -#define SHUNT_THRESH_OVERTEMP 1000 // 1/10 °C +#define SHUNT_TIMEOUT 300 // ms +#define SHUNT_THRESH_OVERCURRENT 300000 // mA +#define SHUNT_THRESH_OVERCURRENT_REGEN 50000 // mA +#define SHUNT_THRESH_OVERTEMP 1000 // 1/10 °C typedef struct { int32_t current; // mA diff --git a/Core/Src/shunt_monitoring.c b/Core/Src/shunt_monitoring.c index 8fcd540..1c32865 100644 --- a/Core/Src/shunt_monitoring.c +++ b/Core/Src/shunt_monitoring.c @@ -28,9 +28,10 @@ void shunt_check() { if (HAL_GetTick() - shunt_data.last_message > SHUNT_TIMEOUT) { is_error = 1; can_send_error(TS_ERRORKIND_SHUNT_TIMEOUT, 0); - } else if (shunt_data.current >= SHUNT_THRESH_OVERCURRENT) { + } else if (shunt_data.current >= SHUNT_THRESH_OVERCURRENT || + shunt_data.current <= -SHUNT_THRESH_OVERCURRENT_REGEN) { is_error = 1; - can_send_error(TS_ERRORKIND_SHUNT_OVERTEMP, 0); + can_send_error(TS_ERRORKIND_SHUNT_OVERCURRENT, 0); } else if (shunt_data.busbartemp >= SHUNT_THRESH_OVERTEMP) { is_error = 1; can_send_error(TS_ERRORKIND_SHUNT_OVERTEMP, 0);