Skip to content

Commit

Permalink
Change SoC calculation to actually reach 100% state of charge
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartpittaway committed Mar 7, 2024
1 parent 8cb7524 commit 3fc920e
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions ESPController/src/CurrentMonitorINA229.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,15 @@ void CurrentMonitorINA229::SetSOCByMilliAmpCounter(uint32_t in,uint32_t out) {
void CurrentMonitorINA229::SetSOC(uint16_t value)
{
// Assume battery is fully charged
milliamphour_in = 1000 * (uint32_t)registers.batterycapacity_amphour;
//milliamphour_in = 1000 * (uint32_t)registers.batterycapacity_amphour;
// And we have consumed this much...
milliamphour_out = (uint32_t)((1.0F - ((float)value / 10000.0F)) * (float)milliamphour_in);
//milliamphour_out = (uint32_t)((1.0F - ((float)value / 10000.0F)) * (float)milliamphour_in);

// Updated SoC logic by delboy711 https://github.com/stuartpittaway/diyBMSv4ESP32/issues/232
// Assume battery is fully charged
milliamphour_in = lround(100000.0*(float)registers.batterycapacity_amphour/(registers.charge_efficiency_factor));
// And we have consumed this much...
milliamphour_out = (uint32_t)((1.0 - ((float)value / 10000.0)) * (1000.0*(float)registers.batterycapacity_amphour));

// Zero out readings using the offsets
milliamphour_out_offset = milliamphour_out;
Expand All @@ -101,6 +107,8 @@ void CurrentMonitorINA229::SetSOC(uint16_t value)
ESP_LOGI(TAG, "SetSOC mA in=%u, mA out=%u",milliamphour_in,milliamphour_out);
}



uint8_t CurrentMonitorINA229::readRegisterValue(INA_REGISTER r) const
{
// These are not really registers, but shape the SPI frame to indicate read/write
Expand Down

0 comments on commit 3fc920e

Please sign in to comment.