Current compensation for load switch thresholds added
This commit is contained in:
+20
-6
@@ -48,23 +48,29 @@ void battery_conf_init(battery_conf_t *bat, bat_type type, int num_cells, float
|
||||
bat->voltage_max = num_cells * 2.4;
|
||||
bat->voltage_recharge = num_cells * 2.3;
|
||||
|
||||
// Cell-level thresholds based on EN 62509:2011 (both thresholds current-compensated)
|
||||
bat->voltage_load_disconnect = num_cells * 1.95;
|
||||
bat->voltage_load_reconnect = num_cells * 2.1;
|
||||
bat->voltage_load_reconnect = num_cells * 2.05; // maybe increase to 2.10, if hysteresis observed?
|
||||
bat->internal_resistance = num_cells * (1.95 - 1.80) / LOAD_CURRENT_MAX; // assumption: Battery selection matching charge controller
|
||||
|
||||
bat->voltage_absolute_min = num_cells * 1.8;
|
||||
|
||||
bat->ocv_full = num_cells * 2.2;
|
||||
bat->ocv_empty = num_cells * 1.9;
|
||||
bat->ocv_full = num_cells * 2.15;
|
||||
bat->ocv_empty = num_cells * 1.95;
|
||||
|
||||
// https://batteryuniversity.com/learn/article/charging_the_lead_acid_battery
|
||||
bat->current_cutoff_CV = bat->nominal_capacity * 0.04; // 3-5 % of C/1
|
||||
|
||||
bat->trickle_enabled = true;
|
||||
bat->time_trickle_recharge = 30*60;
|
||||
// http://batteryuniversity.com/learn/article/charging_the_lead_acid_battery
|
||||
bat->voltage_trickle = num_cells * ((type == BAT_TYPE_FLOODED) ? 2.25 : 2.3);
|
||||
// Values as suggested in EN 62509:2011
|
||||
bat->voltage_trickle = num_cells * ((type == BAT_TYPE_FLOODED) ? 2.35 : 2.3);
|
||||
|
||||
// Enable for flooded batteries only, according to
|
||||
// https://discoverbattery.com/battery-101/equalizing-flooded-batteries-only
|
||||
bat->equalization_enabled = false;
|
||||
bat->voltage_equalization = num_cells * 2.5;
|
||||
// Values as suggested in EN 62509:2011
|
||||
bat->voltage_equalization = num_cells * ((type == BAT_TYPE_FLOODED) ? 2.50 : 2.45);
|
||||
bat->time_limit_equalization = 60*60;
|
||||
bat->current_limit_equalization = (1.0 / 7.0) * bat->nominal_capacity;
|
||||
bat->equalization_trigger_time = 8; // weeks
|
||||
@@ -80,6 +86,7 @@ void battery_conf_init(battery_conf_t *bat, bat_type type, int num_cells, float
|
||||
|
||||
bat->voltage_load_disconnect = num_cells * 3.0;
|
||||
bat->voltage_load_reconnect = num_cells * 3.15;
|
||||
bat->internal_resistance = bat->voltage_load_disconnect * 0.05 / LOAD_CURRENT_MAX; // 5% voltage drop at max current
|
||||
bat->voltage_absolute_min = num_cells * 2.0;
|
||||
|
||||
bat->ocv_full = num_cells * 3.4; // will give really bad SOC calculation
|
||||
@@ -99,6 +106,8 @@ void battery_conf_init(battery_conf_t *bat, bat_type type, int num_cells, float
|
||||
|
||||
bat->voltage_load_disconnect = num_cells * 3.3;
|
||||
bat->voltage_load_reconnect = num_cells * 3.6;
|
||||
bat->internal_resistance = bat->voltage_load_disconnect * 0.05 / LOAD_CURRENT_MAX; // 5% voltage drop at max current
|
||||
|
||||
bat->voltage_absolute_min = num_cells * 2.5;
|
||||
|
||||
bat->ocv_full = num_cells * 4.0;
|
||||
@@ -143,6 +152,8 @@ bool battery_conf_check(battery_conf_t *bat_conf)
|
||||
bat_conf->voltage_recharge < (bat_conf->voltage_max - 0.4) &&
|
||||
bat_conf->voltage_recharge > (bat_conf->voltage_load_disconnect + 1) &&
|
||||
bat_conf->voltage_load_disconnect > (bat_conf->voltage_absolute_min + 0.4) &&
|
||||
bat_conf->internal_resistance < bat_conf->voltage_load_disconnect * 0.1 / LOAD_CURRENT_MAX && // max. 10% drop
|
||||
bat_conf->wire_resistance < bat_conf->voltage_max * 0.03 / LOAD_CURRENT_MAX && // max. 3% loss
|
||||
bat_conf->current_cutoff_CV < (bat_conf->nominal_capacity / 10.0) && // C/10 or lower allowed
|
||||
bat_conf->current_cutoff_CV > 0.01 &&
|
||||
(bat_conf->trickle_enabled == false ||
|
||||
@@ -150,6 +161,7 @@ bool battery_conf_check(battery_conf_t *bat_conf)
|
||||
bat_conf->voltage_trickle > bat_conf->voltage_load_disconnect))
|
||||
);
|
||||
}
|
||||
|
||||
void battery_conf_overwrite(battery_conf_t *source, battery_conf_t *destination, battery_state_t *bat_state)
|
||||
{
|
||||
// TODO: stop DC/DC
|
||||
@@ -166,6 +178,8 @@ void battery_conf_overwrite(battery_conf_t *source, battery_conf_t *destination,
|
||||
destination->voltage_trickle = source->voltage_trickle;
|
||||
destination->time_trickle_recharge = source->time_trickle_recharge;
|
||||
destination->temperature_compensation = source->temperature_compensation;
|
||||
destination->internal_resistance = source->internal_resistance;
|
||||
destination->wire_resistance = source->wire_resistance;
|
||||
|
||||
// reset Ah counter and SOH if battery nominal capacity was changed
|
||||
if (destination->nominal_capacity != source->nominal_capacity) {
|
||||
|
||||
+30
-4
@@ -150,18 +150,44 @@ typedef struct
|
||||
*/
|
||||
int equalization_trigger_deep_cycles;
|
||||
|
||||
/** Load disconnect voltage (V)
|
||||
/** Load disconnect open circuit voltage (V)
|
||||
*
|
||||
* When discharging, stop power to load if battery voltage drops below this value
|
||||
* Load output is disabled if battery voltage is below this threshold.
|
||||
*
|
||||
* The voltage is current-compensated using the battery internal resistance:
|
||||
* threshold = voltage_load_disconnect + battery_current * internal_resistance
|
||||
*
|
||||
* (Remark: battery_current negative during discharge, internal_resistance positive)
|
||||
*/
|
||||
float voltage_load_disconnect;
|
||||
|
||||
/** Load reconnect voltage (V)
|
||||
/** Load reconnect open circuit voltage (V)
|
||||
*
|
||||
* Re-enable the load only after charged beyond this value
|
||||
* Re-enable the load only after charged beyond this value.
|
||||
*
|
||||
* The voltage is current-compensated using the battery internal resistance:
|
||||
* threshold = voltage_load_reconnect + battery_current * internal_resistance
|
||||
*
|
||||
* (Remark: battery_current positive during charge, internal_resistance positive)
|
||||
*/
|
||||
float voltage_load_reconnect;
|
||||
|
||||
/** Battery internal resistance (Ohm)
|
||||
*
|
||||
* Resistance value for current-compensation of load switch voltage thresholds.
|
||||
*
|
||||
* The value must have a positive sign. Only resistance values leading to less than 10% voltage drop at max. current are allowed.
|
||||
*/
|
||||
float internal_resistance;
|
||||
|
||||
/** Resistance of wire between charge controller and battery (Ohm)
|
||||
*
|
||||
* Resistance value for current-compensation of charging voltages.
|
||||
*
|
||||
* The value must have a positive sign. Only resistance values leading to less than 3% voltage loss at max. current are allowed.
|
||||
*/
|
||||
float wire_resistance;
|
||||
|
||||
// used to calculate state of charge information
|
||||
float ocv_full;
|
||||
float ocv_empty;
|
||||
|
||||
+5
-5
@@ -35,7 +35,7 @@ void charger_state_machine(power_port_t *port, battery_conf_t *bat_conf, battery
|
||||
// Load management
|
||||
// battery port input state (i.e. battery discharging direction) defines load state
|
||||
if (port->input_allowed == true &&
|
||||
voltage < bat_conf->voltage_load_disconnect)
|
||||
voltage < bat_conf->voltage_load_disconnect - current * port->droop_res_input)
|
||||
{
|
||||
port->input_allowed = false;
|
||||
bat_state->num_deep_discharges++;
|
||||
@@ -50,7 +50,7 @@ void charger_state_machine(power_port_t *port, battery_conf_t *bat_conf, battery
|
||||
// simple SOH estimation
|
||||
bat_state->soh = bat_state->usable_capacity / bat_conf->nominal_capacity;
|
||||
}
|
||||
if (voltage >= bat_conf->voltage_load_reconnect) {
|
||||
if (voltage >= bat_conf->voltage_load_reconnect - current * port->droop_res_input) {
|
||||
port->input_allowed = true;
|
||||
}
|
||||
|
||||
@@ -69,14 +69,14 @@ void charger_state_machine(power_port_t *port, battery_conf_t *bat_conf, battery
|
||||
break;
|
||||
}
|
||||
case CHG_STATE_BULK: {
|
||||
if (voltage > port->voltage_output_target) {
|
||||
if (voltage > port->voltage_output_target - current * port->droop_res_output) {
|
||||
port->voltage_output_target = bat_conf->voltage_max;
|
||||
_enter_state(bat_state, CHG_STATE_TOPPING);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case CHG_STATE_TOPPING: {
|
||||
if (voltage >= port->voltage_output_target) {
|
||||
if (voltage >= port->voltage_output_target - current * port->droop_res_output) {
|
||||
bat_state->time_voltage_limit_reached = time(NULL);
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ void charger_state_machine(power_port_t *port, battery_conf_t *bat_conf, battery
|
||||
break;
|
||||
}
|
||||
case CHG_STATE_TRICKLE: {
|
||||
if (voltage >= port->voltage_output_target) {
|
||||
if (voltage >= port->voltage_output_target - current * port->droop_res_output) {
|
||||
bat_state->time_voltage_limit_reached = time(NULL);
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
//#define DCDC_MODE_INIT MODE_NANOGRID
|
||||
|
||||
// basic battery configuration
|
||||
#define BATTERY_TYPE BAT_TYPE_FLOODED // see enum battery_types in structs.h
|
||||
#define BATTERY_TYPE BAT_TYPE_GEL // GEL most suitable for general batteries (see battery.h for other types)
|
||||
#define BATTERY_NUM_CELLS 6
|
||||
#define BATTERY_CAPACITY 40
|
||||
|
||||
|
||||
@@ -82,16 +82,21 @@ const data_object_t data_objects[] = {
|
||||
{0x35, TS_CAT_CONF, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_FLOAT32, 1, (void*) &(bat_conf_user.current_cutoff_CV), "BatCutoff_A"},
|
||||
{0x36, TS_CAT_CONF, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_INT32, 0, (void*) &(bat_conf_user.time_limit_CV), "BatCutoff_s"},
|
||||
{0x37, TS_CAT_CONF, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_BOOL, 0, (void*) &(bat_conf_user.trickle_enabled), "TrickleEn"},
|
||||
{0x38, TS_CAT_CONF, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_FLOAT32, 1, (void*) &(bat_conf_user.voltage_trickle), "Trickle_V"},
|
||||
{0x38, TS_CAT_CONF, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_FLOAT32, 2, (void*) &(bat_conf_user.voltage_trickle), "Trickle_V"},
|
||||
{0x39, TS_CAT_CONF, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_INT32, 0, (void*) &(bat_conf_user.time_trickle_recharge), "TrickleRecharge_s"},
|
||||
//{0x3A, TS_CAT_CONF, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_BOOL, 0, (void*) &(bat_conf_user.equalization_enabled), "EqualEn"},
|
||||
//{0x3B, TS_CAT_CONF, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_FLOAT32, 2, (void*) &(bat_conf_user.voltage_equalization), "Equal_V"},
|
||||
// 0x3A-0x3E reserved for equalization charging
|
||||
{0x3F, TS_CAT_CONF, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_FLOAT32, 2, (void*) &(bat_conf_user.temperature_compensation), "TempFactor"},
|
||||
|
||||
|
||||
// load settings
|
||||
{0x40, TS_CAT_CONF, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_BOOL, 0, (void*) &(load.enabled_target), "LoadEnDefault"},
|
||||
{0x41, TS_CAT_CONF, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_BOOL, 0, (void*) &(load.usb_enabled_target), "USBEnDefault"},
|
||||
{0x42, TS_CAT_CONF, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_FLOAT32, 2, (void*) &(bat_conf_user.voltage_load_disconnect), "LoadDisconnect_V"},
|
||||
{0x43, TS_CAT_CONF, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_FLOAT32, 2, (void*) &(bat_conf_user.voltage_load_reconnect), "LoadReconnect_V"},
|
||||
{0x44, TS_CAT_CONF, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_FLOAT32, 3, (void*) &(bat_conf_user.internal_resistance), "BatInt_Ohm"},
|
||||
{0x45, TS_CAT_CONF, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_FLOAT32, 3, (void*) &(bat_conf_user.wire_resistance), "BatWire_Ohm"},
|
||||
//{0x44, TS_CAT_CONF, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_FLOAT32, 2, (void*) &(bat_conf_user.voltage_load_disconnect), "USBDisconnect_V"},
|
||||
//{0x45, TS_CAT_CONF, TS_ACCESS_READ | TS_ACCESS_WRITE, TS_T_FLOAT32, 2, (void*) &(bat_conf_user.voltage_load_reconnect), "USBReconnect_V"},
|
||||
|
||||
|
||||
+2
-2
@@ -54,8 +54,8 @@ int _dcdc_output_control(dcdc_t *dcdc, power_port_t *out, power_port_t *in)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else if (out->voltage > (out->voltage_output_target - out->droop_resistance * out->current) // output voltage above target
|
||||
|| (in->voltage < (in->voltage_input_start - in->droop_resistance * in->current) && out->current > 0.1)) // input voltage below limit
|
||||
else if (out->voltage > (out->voltage_output_target - out->droop_res_output * out->current) // output voltage above target
|
||||
|| (in->voltage < (in->voltage_input_start - in->droop_res_input * in->current) && out->current > 0.1)) // input voltage below limit
|
||||
{
|
||||
dcdc->state = DCDC_STATE_CV;
|
||||
return -1; // decrease output power
|
||||
|
||||
@@ -97,8 +97,8 @@ void oled_output(dcdc_t *dcdc, power_port_t *solar_port, power_port_t *bat_port
|
||||
oled.printf("%4.1fV", solar_port->voltage);
|
||||
//}
|
||||
|
||||
// battey data
|
||||
tmp = bat_port->voltage * (bat_port->current - load->current);
|
||||
// battery data
|
||||
tmp = bat_port->voltage * bat_port->current;
|
||||
oled.setTextCursor(42, 18);
|
||||
oled.printf("%5.1fW", (abs(tmp) < 0.1) ? 0 : tmp); // remove negative zeros
|
||||
oled.setTextCursor(42, 26);
|
||||
|
||||
+4
-1
@@ -24,10 +24,12 @@ void power_port_init_bat(power_port_t *port, battery_conf_t *bat)
|
||||
port->voltage_input_start = bat->voltage_load_reconnect;
|
||||
port->voltage_input_stop = bat->voltage_load_disconnect;
|
||||
port->current_input_max = -bat->charge_current_max; // TODO: discharge current
|
||||
port->droop_res_input = -(bat->internal_resistance + -bat->wire_resistance); // negative sign for compensation of actual resistance
|
||||
|
||||
port->voltage_output_target = bat->voltage_max;
|
||||
port->voltage_output_min = bat->voltage_absolute_min;
|
||||
port->current_output_max = bat->charge_current_max;
|
||||
port->droop_res_output = -bat->wire_resistance; // negative sign for compensation of actual resistance
|
||||
}
|
||||
|
||||
void power_port_init_solar(power_port_t *port)
|
||||
@@ -48,9 +50,10 @@ void power_port_init_nanogrid(power_port_t *port)
|
||||
port->voltage_input_start = 30.0; // starting buck mode above this point
|
||||
port->voltage_input_stop = 20.0; // stopping buck mode below this point
|
||||
port->current_input_max = -5.0;
|
||||
port->droop_res_input = 0.1; // 1 Ohm means 1V change of target voltage per amp
|
||||
|
||||
port->voltage_output_target = 28.0; // starting idle mode above this point
|
||||
port->current_output_max = 5.0;
|
||||
port->voltage_output_min = 10.0;
|
||||
port->droop_resistance = 1.0; // 1 Ohm means 1V change of target voltage per amp
|
||||
port->droop_res_output = 0.1; // 1 Ohm means 1V change of target voltage per amp
|
||||
}
|
||||
|
||||
+2
-1
@@ -37,7 +37,7 @@ typedef struct {
|
||||
float current; ///< measured current (positive sign = out of the port to external device)
|
||||
|
||||
float voltage_output_target; ///< target voltage if port is configured as output
|
||||
float droop_resistance; ///< v_target = v_out_max - r_droop * current
|
||||
float droop_res_output; ///< v_target = v_out_max - r_droop_output * current
|
||||
float voltage_output_min; ///< minimum voltage to allow current output (necessary
|
||||
///< to prevent charging of deep-discharged Li-ion batteries)
|
||||
|
||||
@@ -45,6 +45,7 @@ typedef struct {
|
||||
float voltage_input_start; ///< minimum voltage to allow current input (= discharging of batteries),
|
||||
///< starting point for discharging of batteries (load reconnect)
|
||||
float voltage_input_stop; ///< absolute minimum = load disconnect for batteries
|
||||
float droop_res_input; ///< v_stop = v_input_stop - r_droop_input * current
|
||||
|
||||
float current_output_max; ///< charging direction for battery port
|
||||
float current_input_max; ///< discharging direction for battery port: must be negative value !!!
|
||||
|
||||
+1
-1
@@ -144,7 +144,7 @@ void pwm_switch_control(pwm_switch_t *pwm_switch, power_port_t *solar_port, powe
|
||||
pwm_switch_stop();
|
||||
printf("PWM charger stop.\n");
|
||||
}
|
||||
else if (bat_port->voltage > (bat_port->voltage_output_target - bat_port->droop_resistance * bat_port->current) // output voltage above target
|
||||
else if (bat_port->voltage > (bat_port->voltage_output_target - bat_port->droop_res_output * bat_port->current) // output voltage above target
|
||||
|| bat_port->current > bat_port->current_output_max // output current limit exceeded
|
||||
//|| (solar_port->voltage < (solar_port->voltage_input_start - solar_port->droop_resistance * solar_port->current) && bat_port->current > 0.1) // input voltage below limit
|
||||
|| solar_port->current < solar_port->current_input_max // input current (negative signs) above limit
|
||||
|
||||
Reference in New Issue
Block a user