From cd60e9af4d22ba8aed1dad6c543d1bd70f0bbc28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20J=C3=A4ger?= Date: Thu, 20 May 2021 14:24:23 +0200 Subject: [PATCH] ISL94202: Avoid balancing during measurements Fixes #16 --- src/isl94202/bms_isl94202.c | 25 +++++++++++++++++++++++++ src/isl94202/registers.h | 6 +++--- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/isl94202/bms_isl94202.c b/src/isl94202/bms_isl94202.c index f11abfc..474b951 100644 --- a/src/isl94202/bms_isl94202.c +++ b/src/isl94202/bms_isl94202.c @@ -118,6 +118,31 @@ bool bms_dis_switch(BmsConfig *conf, BmsStatus *status, bool enable) void bms_apply_balancing(BmsConfig *conf, BmsStatus *status) { + uint8_t stat3; + isl94202_read_bytes(ISL94202_STAT3, &stat3, 1); + + /* + * System scans for voltage, current and temperature measurements happen in different + * intervals depending on the mode. Cell balancing should be off during voltage scans. + * + * Each scan takes max. 1.7 ms. Choosing 16 ms off-time for voltages to settle. + */ + if (stat3 & ISL94202_STAT3_INIDLE_Msk) { + // IDLE mode: Scan every 256 ms + isl94202_write_delay(ISL94202_CBONT, ISL94202_DELAY_MS, 240, 0); + isl94202_write_delay(ISL94202_CBOFFT, ISL94202_DELAY_MS, 16, 0); + } + else if (stat3 & ISL94202_STAT3_INDOZE_Msk) { + // DOZE mode: Scan every 512 ms + isl94202_write_delay(ISL94202_CBONT, ISL94202_DELAY_MS, 496, 0); + isl94202_write_delay(ISL94202_CBOFFT, ISL94202_DELAY_MS, 16, 0); + } + else if (!(stat3 & ISL94202_STAT3_INSLEEP_Msk)) { + // NORMAL mode: Scan every 32 ms + isl94202_write_delay(ISL94202_CBONT, ISL94202_DELAY_MS, 16, 0); + isl94202_write_delay(ISL94202_CBOFFT, ISL94202_DELAY_MS, 16, 0); + } + /* * Balancing is done automatically, just reading status here (even though the datasheet * tells that the CBFC register value cannot be used for indication if a cell is diff --git a/src/isl94202/registers.h b/src/isl94202/registers.h index cda1491..c51bbc3 100644 --- a/src/isl94202/registers.h +++ b/src/isl94202/registers.h @@ -116,9 +116,9 @@ #define ISL94202_CBONT_Msk (0xFFFU << ISL94202_CBON_Pos) // Cell Balance Off Time (CBOFF) -#define ISL94202_CBOFT (0x26U) -#define ISL94202_CBOFT_Pos (0x0U) -#define ISL94202_CBOFT_Msk (0xFFFU << ISL94202_CBOF_Pos) +#define ISL94202_CBOFFT (0x26U) +#define ISL94202_CBOFFT_Pos (0x0U) +#define ISL94202_CBOFFT_Msk (0xFFFU << ISL94202_CBOF_Pos) // Cell Balance Minimum Temperature Limit (CBUTS) #define ISL94202_CBUTS (0x28U)