From fdd9c3f4af6a84f9ec695d0df8027b02f5db177a Mon Sep 17 00:00:00 2001 From: "Jasper v. Blanckenburg" Date: Wed, 9 Aug 2023 09:37:02 +0200 Subject: [PATCH] Fix coulomb counting --- Core/Src/soc_estimation.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Core/Src/soc_estimation.c b/Core/Src/soc_estimation.c index ed5d3df..9c08ebd 100644 --- a/Core/Src/soc_estimation.c +++ b/Core/Src/soc_estimation.c @@ -32,7 +32,7 @@ void soc_init() { void soc_update() { uint32_t now = HAL_GetTick(); - if (shunt_data.current >= SOC_ESTIMATION_NO_CURRENT_THRESH) { + if (abs(shunt_data.current) >= SOC_ESTIMATION_NO_CURRENT_THRESH) { last_current_time = now; if (!current_was_flowing) { soc_before_current = current_soc; @@ -52,7 +52,7 @@ void soc_update() { // Otherwise, use the current counter to update SoC float as_delta = shunt_data.current_counter - mAs_before_current; float soc_delta = as_delta / SOC_ESTIMATION_BATTERY_CAPACITY * 100; - current_soc = soc_before_current + soc_delta; + current_soc = soc_before_current - soc_delta; } }