Add regen overcurrent limit

This commit is contained in:
Jasper Blanckenburg 2024-05-23 00:39:18 +02:00
parent 7c7ae41ee6
commit fa3ef04b58
2 changed files with 7 additions and 5 deletions

View File

@ -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

View File

@ -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);