Overvoltage limit overflow fix (#80)

The bat config calculation did calculate the absolute max voltage
too high, it was doing an unnecessary multiplication.
This triggered an issue in the voltage limit set code, which did not
handle the overflow of the 16bit limit value properly.

Both are fixed now. We limit the limit value to what the ADC is able
to deliver, so that we detect overvoltage for sure, even if the setting
is out of ADC range.
This commit is contained in:
hogthrob
2019-11-10 17:55:43 +01:00
committed by Martin Jäger
parent 1536e176a9
commit d1ff837c5e
4 changed files with 37 additions and 21 deletions
+2 -2
View File
@@ -111,7 +111,7 @@ void battery_conf_init(BatConf *bat, BatType type, int num_cells, float nominal_
case BAT_TYPE_NMC:
case BAT_TYPE_NMC_HV:
bat->topping_voltage = num_cells * ((type == BAT_TYPE_NMC_HV) ? 4.35 : 4.20);
bat->voltage_absolute_max = num_cells * (bat->topping_voltage + 0.05);
bat->voltage_absolute_max = bat->topping_voltage + num_cells * 0.05;
bat->voltage_recharge = num_cells * 3.9;
bat->voltage_load_disconnect = num_cells * 3.3;
@@ -191,7 +191,7 @@ void battery_conf_overwrite(BatConf *source, BatConf *destination, Charger *char
destination->voltage_absolute_min = source->voltage_absolute_min;
destination->charge_current_max = source->charge_current_max;
destination->topping_current_cutoff = source->topping_current_cutoff;
destination->topping_duration = source->topping_duration;
destination->topping_duration = source->topping_duration;
destination->trickle_enabled = source->trickle_enabled;
destination->trickle_voltage = source->trickle_voltage;
destination->trickle_recharge_time = source->trickle_recharge_time;