From 1f8b4f2d2c94715114f8f45aab51042491211dbe Mon Sep 17 00:00:00 2001 From: Yannis Chatzikonstantinou Date: Sun, 25 Feb 2024 21:29:01 +0200 Subject: [PATCH] enforce minimum trip current value --- firmware/src/common.h | 6 ++++++ firmware/src/controller/controller.c | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/firmware/src/common.h b/firmware/src/common.h index 8b8ee745..a610aeeb 100644 --- a/firmware/src/common.h +++ b/firmware/src/common.h @@ -123,6 +123,12 @@ #define BOARD_REV_IDX 21 #endif +#if defined BOARD_REV_R3 || defined BOARD_REV_R5 +#define MIN_TRIP_CURRENT (5.0f) // A +#elif defined BOARD_REV_M5 +#define MIN_TRIP_CURRENT (1.0f) // A +#endif + #define TIMER_FREQ_HZ (ACLK_FREQ_HZ >> TXCTL_PS_DIV) #define SENSOR_COMMON_RES_BITS (13) diff --git a/firmware/src/controller/controller.c b/firmware/src/controller/controller.c index 815bda11..1545e920 100644 --- a/firmware/src/controller/controller.c +++ b/firmware/src/controller/controller.c @@ -107,8 +107,8 @@ void Controller_ControlLoop(void) { state.warnings = 0; const float Iq = controller_get_Iq_estimate(); - if ((Iq > (config.I_limit * I_TRIP_MARGIN)) || - (Iq < -(config.I_limit * I_TRIP_MARGIN))) + const float Iq_trip = our_fmaxf(config.I_limit * I_TRIP_MARGIN, MIN_TRIP_CURRENT); + if (our_fabsf(Iq) > Iq_trip) { state.errors |= CONTROLLER_ERRORS_CURRENT_LIMIT_EXCEEDED; }