Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/src/bat_charger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,8 @@ void Charger::update_soc(BatConf *bat_conf)
static int soc_filtered = 0; // SOC / 100 for better filtering

if (fabs(port->current) < 0.2f) {
int soc_new = (int)((port->bus->voltage - bat_conf->ocv_empty)
int soc_new = (int)((port->bus->voltage / port->bus->series_multiplier
- bat_conf->ocv_empty)
/ (bat_conf->ocv_full - bat_conf->ocv_empty) * 10000.0f);

if (soc_new > 500 && soc_filtered == 0) {
Expand Down
14 changes: 14 additions & 0 deletions tests/src/tests_bat_charger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,18 @@ void no_soc_below_0()
TEST_ASSERT(0);
}

void soc_uses_series_battery_voltage()
{
init_structs();
bat_terminal.bus->series_multiplier = 2;
bat_terminal.bus->voltage = bat_conf.ocv_empty + bat_conf.ocv_full;
for (int i = 0; i < 2000; i++) {
charger.update_soc(&bat_conf);
}
TEST_ASSERT_INT_WITHIN(2, 50, charger.soc);
bat_terminal.bus->series_multiplier = 1;
}

int bat_charger_tests()
{
UNITY_BEGIN();
Expand Down Expand Up @@ -330,6 +342,8 @@ int bat_charger_tests()

// RUN_TEST(battery_values_propagated_to_lv_bus_int);

RUN_TEST(soc_uses_series_battery_voltage);

// ToDo: SOC calculation
// RUN_TEST(no_soc_above_100);
// RUN_TEST(no_soc_below_0);
Expand Down
Loading