Differentiate between src and sink droop res again
Necessary for improved load disconnect switch behavior.
This commit is contained in:
+10
-12
@@ -293,7 +293,7 @@ void Charger::discharge_control(BatConf *bat_conf)
|
||||
if (port->neg_current_limit < 0) {
|
||||
// discharging currently allowed. see if that's still valid:
|
||||
if (port->bus->voltage < num_batteries *
|
||||
(bat_conf->voltage_load_disconnect - port->current * port->bus->droop_res))
|
||||
port->bus->src_droop_voltage(bat_conf->voltage_load_disconnect))
|
||||
{
|
||||
uv_debounce_counter++;
|
||||
if (uv_debounce_counter >= 3) { // 3s in undervoltage --> switch off
|
||||
@@ -334,7 +334,7 @@ void Charger::discharge_control(BatConf *bat_conf)
|
||||
else {
|
||||
// discharging currently not allowed. should we allow it?
|
||||
if (port->bus->voltage >= num_batteries *
|
||||
(bat_conf->voltage_load_reconnect - port->current * port->bus->droop_res)
|
||||
port->bus->src_droop_voltage(bat_conf->voltage_load_reconnect)
|
||||
&& bat_temperature < bat_conf->discharge_temp_max - 1
|
||||
&& bat_temperature > bat_conf->discharge_temp_min + 1)
|
||||
{
|
||||
@@ -395,9 +395,7 @@ void Charger::charge_control(BatConf *bat_conf)
|
||||
port->bus->sink_voltage_bound = num_batteries * (bat_conf->topping_voltage +
|
||||
bat_conf->temperature_compensation * (bat_temperature - 25));
|
||||
|
||||
if (port->bus->voltage >
|
||||
port->bus->droop_voltage(port->bus->sink_voltage_bound))
|
||||
{
|
||||
if (port->bus->voltage > port->bus->sink_droop_voltage()) {
|
||||
target_voltage_timer = 0;
|
||||
enter_state(CHG_STATE_TOPPING);
|
||||
}
|
||||
@@ -408,9 +406,7 @@ void Charger::charge_control(BatConf *bat_conf)
|
||||
port->bus->sink_voltage_bound = num_batteries * (bat_conf->topping_voltage +
|
||||
bat_conf->temperature_compensation * (bat_temperature - 25));
|
||||
|
||||
if (port->bus->voltage >=
|
||||
port->bus->droop_voltage(port->bus->sink_voltage_bound) - 0.05F)
|
||||
{
|
||||
if (port->bus->voltage >= port->bus->sink_droop_voltage() - 0.05F) {
|
||||
// battery is full if topping target voltage is still reached (i.e. sufficient
|
||||
// solar power available) and time limit or cut-off current reached
|
||||
if (port->current < bat_conf->topping_current_cutoff ||
|
||||
@@ -457,9 +453,7 @@ void Charger::charge_control(BatConf *bat_conf)
|
||||
port->bus->sink_voltage_bound = num_batteries * (bat_conf->trickle_voltage +
|
||||
bat_conf->temperature_compensation * (bat_temperature - 25));
|
||||
|
||||
if (port->bus->voltage >= num_batteries *
|
||||
(port->bus->sink_voltage_bound - port->current * port->bus->droop_res))
|
||||
{
|
||||
if (port->bus->voltage >= port->bus->sink_droop_voltage()) {
|
||||
time_target_voltage_reached = uptime();
|
||||
}
|
||||
|
||||
@@ -512,5 +506,9 @@ void Charger::init_terminal(BatConf *bat)
|
||||
port->pos_current_limit = bat->charge_current_max;
|
||||
|
||||
// negative sign for compensation of actual resistance
|
||||
port->bus->droop_res = -(bat->internal_resistance + bat->wire_resistance) * num_batteries;
|
||||
port->bus->sink_droop_res = -bat->wire_resistance;
|
||||
|
||||
// in discharging direction also include battery internal resistance for current-compensation
|
||||
// of voltage setpoints
|
||||
port->bus->src_droop_res = -bat->wire_resistance - bat->internal_resistance * num_batteries;
|
||||
}
|
||||
|
||||
+2
-2
@@ -78,7 +78,7 @@ int Dcdc::duty_cycle_delta()
|
||||
// swith off after 10s low power or negative power (if not in nanogrid mode)
|
||||
pwr_inc_goal = 0;
|
||||
}
|
||||
else if (out->bus->voltage > out->bus->droop_voltage(out->bus->sink_voltage_bound)) {
|
||||
else if (out->bus->voltage > out->bus->sink_droop_voltage()) {
|
||||
// output voltage target reached
|
||||
state = DCDC_STATE_CV;
|
||||
pwr_inc_goal = -1; // decrease output power
|
||||
@@ -90,7 +90,7 @@ int Dcdc::duty_cycle_delta()
|
||||
}
|
||||
else if (fabs(lvs->current) > ls_current_max // current above hardware maximum
|
||||
|| temp_mosfets > 80 // temperature limits exceeded
|
||||
|| (in->bus->voltage < in->bus->droop_voltage(in->bus->src_voltage_bound)
|
||||
|| (in->bus->voltage < in->bus->src_droop_voltage()
|
||||
&& out->current > 0.1) // input voltage below limit
|
||||
|| in->current < in->neg_current_limit) // input current (negative signs) limit exceeded
|
||||
{
|
||||
|
||||
+4
-1
@@ -16,7 +16,10 @@ void PowerPort::init_nanogrid()
|
||||
{
|
||||
pos_current_limit = 5.0;
|
||||
neg_current_limit = -5.0;
|
||||
bus->droop_res = 0.1; // 1 Ohm means 1V change of target voltage per amp
|
||||
|
||||
// 1 Ohm means 1V change of target voltage per amp, same droop for both current directions.
|
||||
bus->sink_droop_res = 0.1;
|
||||
bus->src_droop_res = 0.1;
|
||||
|
||||
// also initialize the connected bus
|
||||
bus->src_voltage_bound = 30.0; // starting buck mode above this point
|
||||
|
||||
+35
-4
@@ -46,11 +46,18 @@ public:
|
||||
float src_voltage_bound;
|
||||
|
||||
/**
|
||||
* Droop resistance to adjust voltage bounds depending on actual current
|
||||
* Droop resistance to adjust voltage bounds for current in sourcing direction
|
||||
*
|
||||
* control voltage = nominal voltage - droop_res * current
|
||||
*/
|
||||
float droop_res;
|
||||
float src_droop_res;
|
||||
|
||||
/**
|
||||
* Droop resistance to adjust voltage bounds for current in sinking direction
|
||||
*
|
||||
* control voltage = nominal voltage - droop_res * current
|
||||
*/
|
||||
float sink_droop_res;
|
||||
|
||||
/**
|
||||
* Pointer to current measurement that is used to determine the droop. This is typically the
|
||||
@@ -70,10 +77,34 @@ public:
|
||||
*/
|
||||
float src_current_margin;
|
||||
|
||||
inline float droop_voltage(float v0)
|
||||
/**
|
||||
* Calculate current-compensated voltage based on bus reference current
|
||||
*
|
||||
* @param voltage_zero_current Voltage at zero current (without droop). If this parameter is
|
||||
* left empty, the src_voltage_bound is considered.
|
||||
*/
|
||||
inline float src_droop_voltage(float voltage_zero_current = 0)
|
||||
{
|
||||
float v0 = (voltage_zero_current == 0) ? src_voltage_bound : voltage_zero_current;
|
||||
if (ref_current != nullptr) {
|
||||
return v0 - droop_res * (*ref_current);
|
||||
return v0 - src_droop_res * (*ref_current);
|
||||
}
|
||||
else {
|
||||
return v0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate current-compensated voltage based on bus reference current
|
||||
*
|
||||
* @param voltage_zero_current Voltage at zero current (without droop). If this parameter is
|
||||
* left empty, the sink_voltage_bound is considered.
|
||||
*/
|
||||
inline float sink_droop_voltage(float voltage_zero_current = 0)
|
||||
{
|
||||
float v0 = (voltage_zero_current == 0) ? sink_voltage_bound : voltage_zero_current;
|
||||
if (ref_current != nullptr) {
|
||||
return v0 - sink_droop_res * (*ref_current);
|
||||
}
|
||||
else {
|
||||
return v0;
|
||||
|
||||
+3
-4
@@ -179,10 +179,9 @@ void PwmSwitch::control()
|
||||
off_timestamp = uptime();
|
||||
print_info("PWM charger stop.\n");
|
||||
}
|
||||
else if (bus->voltage > (bus->sink_voltage_bound -
|
||||
bus->droop_res * current) // voltage above target
|
||||
|| current < neg_current_limit // port current limit exceeded
|
||||
|| current < -PWM_CURRENT_MAX) // PCB current limit exceeded
|
||||
else if (bus->voltage > bus->sink_droop_voltage() // bus voltage above target
|
||||
|| current < neg_current_limit // port current limit exceeded
|
||||
|| current < -PWM_CURRENT_MAX) // PCB current limit exceeded
|
||||
{
|
||||
// decrease power, as limits were reached
|
||||
|
||||
|
||||
@@ -95,7 +95,7 @@ void stop_topping_after_time_limit()
|
||||
charger.target_voltage_timer = bat_conf.topping_duration - 1;
|
||||
bat_terminal.current = bat_conf.topping_current_cutoff + 0.1;
|
||||
bat_terminal.bus->voltage = bat_conf.topping_voltage -
|
||||
bat_terminal.current * bat_terminal.bus->droop_res + 0.1;
|
||||
bat_terminal.current * bat_terminal.bus->sink_droop_res + 0.1;
|
||||
|
||||
charger.charge_control(&bat_conf);
|
||||
TEST_ASSERT_EQUAL(CHG_STATE_TOPPING, charger.state);
|
||||
@@ -112,7 +112,7 @@ void stop_topping_at_cutoff_current()
|
||||
charger.target_voltage_timer = 0;
|
||||
bat_terminal.current = bat_conf.topping_current_cutoff - 0.1;
|
||||
bat_terminal.bus->voltage = bat_conf.topping_voltage -
|
||||
bat_terminal.current * bat_terminal.bus->droop_res + 0.1;
|
||||
bat_terminal.current * bat_terminal.bus->sink_droop_res + 0.1;
|
||||
charger.charge_control(&bat_conf);
|
||||
TEST_ASSERT_EQUAL(CHG_STATE_TRICKLE, charger.state);
|
||||
}
|
||||
@@ -125,7 +125,7 @@ void trickle_to_idle_for_li_ion()
|
||||
charger.time_state_changed = time(NULL) - 1;
|
||||
bat_terminal.current = bat_conf.topping_current_cutoff - 0.1;
|
||||
bat_terminal.bus->voltage = bat_conf.topping_voltage -
|
||||
bat_terminal.current * bat_terminal.bus->droop_res + 0.1;
|
||||
bat_terminal.current * bat_terminal.bus->sink_droop_res + 0.1;
|
||||
charger.charge_control(&bat_conf);
|
||||
TEST_ASSERT_EQUAL(CHG_STATE_IDLE, charger.state);
|
||||
}
|
||||
@@ -176,7 +176,7 @@ void trickle_to_equalization_if_enabled_and_time_limit_reached()
|
||||
charger.time_state_changed = time(NULL) - 1;
|
||||
bat_terminal.current = bat_conf.topping_current_cutoff - 0.1;
|
||||
bat_terminal.bus->voltage = bat_conf.topping_voltage -
|
||||
bat_terminal.current * bat_terminal.bus->droop_res + 0.1;
|
||||
bat_terminal.current * bat_terminal.bus->sink_droop_res + 0.1;
|
||||
charger.charge_control(&bat_conf);
|
||||
TEST_ASSERT_EQUAL(CHG_STATE_EQUALIZATION, charger.state);
|
||||
}
|
||||
@@ -192,7 +192,7 @@ void trickle_to_equalization_if_enabled_and_deep_dis_limit_reached()
|
||||
charger.time_state_changed = time(NULL) - 1;
|
||||
bat_terminal.current = bat_conf.topping_current_cutoff - 0.1;
|
||||
bat_terminal.bus->voltage = bat_conf.topping_voltage -
|
||||
bat_terminal.current * bat_terminal.bus->droop_res + 0.1;
|
||||
bat_terminal.current * bat_terminal.bus->sink_droop_res + 0.1;
|
||||
charger.charge_control(&bat_conf);
|
||||
TEST_ASSERT_EQUAL(CHG_STATE_EQUALIZATION, charger.state);
|
||||
}
|
||||
@@ -204,7 +204,7 @@ void stop_equalization_after_time_limit()
|
||||
|
||||
charger.time_state_changed = time(NULL) - bat_conf.equalization_duration + 1;
|
||||
bat_terminal.bus->voltage = bat_conf.equalization_voltage -
|
||||
bat_terminal.current * bat_terminal.bus->droop_res + 0.1;
|
||||
bat_terminal.current * bat_terminal.bus->sink_droop_res + 0.1;
|
||||
|
||||
charger.charge_control(&bat_conf);
|
||||
TEST_ASSERT_EQUAL(CHG_STATE_EQUALIZATION, charger.state);
|
||||
|
||||
Reference in New Issue
Block a user