I am currently trying to find the right settings for an in-circuit evaluation of a solar-powered lead-acid battery charge .
here is my current (partial)programm for that task:
//===============================================
// Measure Battery
// Battery measurements from INA226
ina_voltage = INA.getBusMilliVolts(0);
ina_shunt = INA.getShuntMicroVolts(0);
ina_current = INA.getBusMicroAmps(0);
ina_power = INA.getBusMicroWatts(0);
voltage += (ina_voltage / 1000 - voltage) / 10; // Low Pass filter 2min
current += (ina_current / -1000000 - current) / 10; // -"-
if (NewMinute)
{
float m = battery.voltage;
float n = battery.current;
battery.voltage = voltage;
battery.current = current;
battery.power = voltage * current;
delta_voltage = battery.voltage - m;
delta_current = battery.current - n;
// Evaluate battery charge
float d = 0;
if (battery.current >= 0.3)
{
d = 500; // mV
}
else if (battery.current <= 0.3)
{
d = -500; // mV
}
percent_charged = map(battery.voltage * 1000, MIN_VOLT * 1000 + d, MAX_VOLT * 1000 + d - 800, 0, 100);
percent_charged = constrain( percent_charged, 0, 100);
if (battery.current < 0 && battery.voltage < 12.8 && battery.voltage > (MIN_VOLT + 0.5))
{
// Evaluate battery internal resistance (r = dv / di) if inside regular limits and smooth it.
if (fabs(delta_current) > 0.005) internal_resistance = internal_resistance + ((fabs(delta_voltage / delta_current)) - internal_resistance) / 10;
}
}// end if new minute
// Daily Battery voltage comparison
if (SecondOfDay == 14400) voltageAt4h = battery.voltage; // taking the voltage at 04:00 to evaluate if the battery gained/lost during the previous day.
if (SecondOfDay == 14399) voltageDelta = battery.voltage - voltageAt4h;// set ranges at 03:59:59
// Battery Stat integration
currentInt += battery.current;
nCurrent ++;
if (HourExpiring)
{
AhBat[Hour] = currentInt / nCurrent;
nCurrent = 0;
currentInt = 0;
AhBat[25] = AhBat[Hour]; //last hour
AhBat[27] = 0; // today (0h->current hour)
for (byte n = 0; n < Hour; n++)
{
AhBat[27] = AhBat[27] + AhBat[n];
}
} // end hour expiring
if (DayExpiring)
{
AhBat[26] = AhBat[27];
}
It basically records the mAh for every hour in an array, measures the internal resistance of the battery whenver a sufficient change of load/charge happened (but not over 12,8v und under 11,8v)
and tries to evaluate the degree of load depending on wether it is charging/discharging/~being idle.
Additionally I record the voltage at 4h in the morning and compare with the day before.
To visualize, I am currently sending the data to a cloud-based dashboard. It is cheaper than soldering hardware displays and MUCH more powerful: