DC/DC: Use high/low DcBus instead of PowerPort for control
This makes more sense because the DC/DC converter actually connects two DcBuses and does not need separate PowerPorts. Also makes the code look more clean as variable access like dcdc.hvs->bus->voltage is avoided. The DcBus pointers in the Dcdc are now called hvb and lvb for high- voltage side bus and low-voltage side bus.
This commit is contained in:
+4
-4
@@ -198,15 +198,15 @@ void daq_update()
|
||||
#endif
|
||||
|
||||
#if DT_NODE_EXISTS(DT_PATH(dcdc))
|
||||
dcdc_lv_port.current =
|
||||
dcdc.inductor_current =
|
||||
adc_scaled(ADC_POS(i_dcdc), vref, ADC_GAIN(i_dcdc), dcdc_current_offset_raw);
|
||||
|
||||
lv_terminal_current += dcdc_lv_port.current;
|
||||
lv_terminal_current += dcdc.inductor_current;
|
||||
|
||||
hv_terminal.current = -dcdc_lv_port.current * lv_terminal.bus->voltage /
|
||||
hv_terminal.current = -dcdc.inductor_current * lv_terminal.bus->voltage /
|
||||
hv_terminal.bus->voltage;
|
||||
|
||||
dcdc_lv_port.power = dcdc_lv_port.bus->voltage * dcdc_lv_port.current;
|
||||
dcdc.power = dcdc.lvb->voltage * dcdc.inductor_current;
|
||||
hv_terminal.power = hv_terminal.bus->voltage * hv_terminal.current;
|
||||
#endif
|
||||
lv_terminal.current = lv_terminal_current;
|
||||
|
||||
+55
-50
@@ -32,16 +32,14 @@ extern DeviceStatus dev_stat;
|
||||
#define HV_EXT_SENSE_GPIO DT_CHILD(DT_PATH(outputs), hv_ext_sense)
|
||||
#endif
|
||||
|
||||
Dcdc::Dcdc(PowerPort *hv_side, PowerPort *lv_side, DcdcOperationMode op_mode)
|
||||
Dcdc::Dcdc(DcBus *high, DcBus *low, DcdcOperationMode op_mode)
|
||||
{
|
||||
hvs = hv_side;
|
||||
lvs = lv_side;
|
||||
hvb = high;
|
||||
lvb = low;
|
||||
mode = op_mode;
|
||||
enable = true;
|
||||
state = DCDC_CONTROL_OFF;
|
||||
lvs->neg_current_limit = -DT_PROP(DT_PATH(dcdc), current_max);
|
||||
lvs->pos_current_limit = DT_PROP(DT_PATH(dcdc), current_max);
|
||||
ls_current_max = DT_PROP(DT_PATH(dcdc), current_max);
|
||||
inductor_current_max = DT_PROP(DT_PATH(dcdc), current_max);
|
||||
hs_voltage_max = DT_PROP(DT_PATH(pcb), hs_voltage_max);
|
||||
ls_voltage_max = DT_PROP(DT_PATH(pcb), ls_voltage_max);
|
||||
ls_voltage_min = 9.0;
|
||||
@@ -58,51 +56,58 @@ Dcdc::Dcdc(PowerPort *hv_side, PowerPort *lv_side, DcdcOperationMode op_mode)
|
||||
int Dcdc::perturb_observe_controller()
|
||||
{
|
||||
int pwr_inc_pwm_direction; // direction of PWM duty cycle change for increasing power
|
||||
PowerPort *in;
|
||||
PowerPort *out;
|
||||
DcBus *in;
|
||||
DcBus *out;
|
||||
float out_power;
|
||||
|
||||
if (mode == DCDC_MODE_BUCK || (mode == DCDC_MODE_AUTO && lvs->current > 0.1)) {
|
||||
if (mode == DCDC_MODE_BUCK || (mode == DCDC_MODE_AUTO && inductor_current > 0.1)) {
|
||||
// buck mode
|
||||
pwr_inc_pwm_direction = 1;
|
||||
in = hvs;
|
||||
out = lvs;
|
||||
in = hvb;
|
||||
out = lvb;
|
||||
out_power = power;
|
||||
}
|
||||
else {
|
||||
// boost mode
|
||||
pwr_inc_pwm_direction = -1;
|
||||
in = lvs;
|
||||
out = hvs;
|
||||
in = lvb;
|
||||
out = hvb;
|
||||
out_power = -power;
|
||||
}
|
||||
|
||||
if (out->power >= output_power_min) {
|
||||
if (out_power >= output_power_min) {
|
||||
power_good_timestamp = uptime(); // reset the time
|
||||
}
|
||||
|
||||
int pwr_inc_goal = 0; // stores if we want to increase (+1) or decrease (-1) power
|
||||
|
||||
if ((uptime() - power_good_timestamp > 10 || out->power < -1.0) && mode != DCDC_MODE_AUTO) {
|
||||
if ((uptime() - power_good_timestamp > 10 || out_power < -1.0) && mode != DCDC_MODE_AUTO) {
|
||||
// switch off after 10s low power or negative power (if not in nanogrid mode)
|
||||
pwr_inc_goal = 0;
|
||||
}
|
||||
else if (out->bus->voltage > out->bus->sink_control_voltage()) {
|
||||
else if (out->voltage > out->sink_control_voltage()) {
|
||||
// output voltage target reached
|
||||
state = (out == lvs) ? DCDC_CONTROL_CV_LS : DCDC_CONTROL_CV_HS;
|
||||
state = (out == lvb) ? DCDC_CONTROL_CV_LS : DCDC_CONTROL_CV_HS;
|
||||
pwr_inc_goal = -1; // decrease output power
|
||||
}
|
||||
else if (out->current > out->pos_current_limit) {
|
||||
else if (out->sink_current_margin < 0) {
|
||||
// output charge current limit reached
|
||||
state = (out == lvs) ? DCDC_CONTROL_CC_LS : DCDC_CONTROL_CC_HS;
|
||||
state = (out == lvb) ? DCDC_CONTROL_CC_LS : DCDC_CONTROL_CC_HS;
|
||||
pwr_inc_goal = -1; // decrease output power
|
||||
}
|
||||
else if (fabs(lvs->current) > ls_current_max // current above hardware maximum
|
||||
|| in->current < in->neg_current_limit) // input current (negative signs) limit exceeded
|
||||
{
|
||||
state = (in == hvs) ? DCDC_CONTROL_CC_HS : DCDC_CONTROL_CC_LS;
|
||||
else if (in->src_current_margin > 0) {
|
||||
// input current (negative signs) limit exceeded
|
||||
state = (in == hvb) ? DCDC_CONTROL_CC_HS : DCDC_CONTROL_CC_LS;
|
||||
pwr_inc_goal = -1; // decrease output power
|
||||
}
|
||||
else if (in->bus->voltage < in->bus->src_control_voltage() && out->current > 0.1) {
|
||||
else if (fabs(inductor_current) > inductor_current_max) {
|
||||
// current above hardware maximum
|
||||
state = DCDC_CONTROL_CC_LS;
|
||||
pwr_inc_goal = -1; // decrease output power
|
||||
}
|
||||
else if (in->voltage < in->src_control_voltage() && out_power > output_power_min) {
|
||||
// input voltage below limit
|
||||
state = (in == hvs) ? DCDC_CONTROL_CV_HS : DCDC_CONTROL_CV_LS;
|
||||
state = (in == hvb) ? DCDC_CONTROL_CV_HS : DCDC_CONTROL_CV_LS;
|
||||
pwr_inc_goal = -1;
|
||||
}
|
||||
else if (temp_mosfets > 80) {
|
||||
@@ -110,14 +115,14 @@ int Dcdc::perturb_observe_controller()
|
||||
state = DCDC_CONTROL_DERATING;
|
||||
pwr_inc_goal = -1;
|
||||
}
|
||||
else if (out->power < output_power_min && out->bus->voltage < out->bus->src_control_voltage()) {
|
||||
else if (out_power < output_power_min && out->voltage < out->src_control_voltage()) {
|
||||
// no load condition (e.g. start-up of nanogrid) --> raise voltage
|
||||
pwr_inc_goal = 1; // increase output power
|
||||
}
|
||||
else {
|
||||
// start MPPT
|
||||
state = DCDC_CONTROL_MPPT;
|
||||
if (power_prev > out->power) {
|
||||
if (power_prev > out_power) {
|
||||
pwm_delta = -pwm_delta;
|
||||
}
|
||||
pwr_inc_goal = pwm_delta;
|
||||
@@ -128,12 +133,12 @@ int Dcdc::perturb_observe_controller()
|
||||
printf("P: %.2fW (prev %.2fW), in: %.2fV %.2fA (limit %.2fA), "
|
||||
"out: %.2fV (target %.2fV) %.2fA (limit %.2fA), "
|
||||
"PWM: %.1f, chg_state: %d, pwr_inc: %d, buck/boost: %d\n",
|
||||
out->power, power_prev, in->bus->voltage, in->current, in->neg_current_limit,
|
||||
out->bus->voltage, out->bus->sink_voltage_intercept, out->current, out->pos_current_limit,
|
||||
out_power, power_prev, in->voltage, in->current, in->neg_current_limit,
|
||||
out->voltage, out->sink_voltage_intercept, out->current, out->pos_current_limit,
|
||||
half_bridge_get_duty_cycle() * 100.0, state, pwr_inc_goal, pwr_inc_pwm_direction);
|
||||
#endif
|
||||
|
||||
power_prev = out->power;
|
||||
power_prev = out_power;
|
||||
|
||||
// change duty cycle by single minimum step
|
||||
half_bridge_set_ccr(half_bridge_get_ccr() + pwr_inc_goal * pwr_inc_pwm_direction);
|
||||
@@ -144,28 +149,28 @@ int Dcdc::perturb_observe_controller()
|
||||
__weak DcdcOperationMode Dcdc::check_start_conditions()
|
||||
{
|
||||
if (enable == false ||
|
||||
hvs->bus->voltage > hs_voltage_max || // also critical for buck mode because of ringing
|
||||
lvs->bus->voltage > ls_voltage_max ||
|
||||
lvs->bus->voltage < ls_voltage_min ||
|
||||
hvb->voltage > hs_voltage_max || // also critical for buck mode because of ringing
|
||||
lvb->voltage > ls_voltage_max ||
|
||||
lvb->voltage < ls_voltage_min ||
|
||||
dev_stat.has_error(ERR_BAT_UNDERVOLTAGE | ERR_BAT_OVERVOLTAGE) ||
|
||||
(int)uptime() < (off_timestamp + (int)restart_interval))
|
||||
{
|
||||
return DCDC_MODE_OFF;
|
||||
}
|
||||
|
||||
if (lvs->bus->sink_current_margin > 0 &&
|
||||
lvs->bus->voltage < lvs->bus->sink_control_voltage() &&
|
||||
hvs->bus->src_current_margin < 0 &&
|
||||
hvs->bus->voltage > hvs->bus->src_control_voltage() &&
|
||||
hvs->bus->voltage * 0.85 > lvs->bus->voltage)
|
||||
if (lvb->sink_current_margin > 0 &&
|
||||
lvb->voltage < lvb->sink_control_voltage() &&
|
||||
hvb->src_current_margin < 0 &&
|
||||
hvb->voltage > hvb->src_control_voltage() &&
|
||||
hvb->voltage * 0.85 > lvb->voltage)
|
||||
{
|
||||
return DCDC_MODE_BUCK;
|
||||
}
|
||||
|
||||
if (hvs->bus->sink_current_margin > 0 &&
|
||||
hvs->bus->voltage < hvs->bus->sink_control_voltage() &&
|
||||
lvs->bus->src_current_margin < 0 &&
|
||||
lvs->bus->voltage > lvs->bus->src_control_voltage())
|
||||
if (hvb->sink_current_margin > 0 &&
|
||||
hvb->voltage < hvb->sink_control_voltage() &&
|
||||
lvb->src_current_margin < 0 &&
|
||||
lvb->voltage > lvb->src_control_voltage())
|
||||
{
|
||||
return DCDC_MODE_BOOST;
|
||||
}
|
||||
@@ -176,7 +181,7 @@ __weak DcdcOperationMode Dcdc::check_start_conditions()
|
||||
bool Dcdc::check_hs_mosfet_short()
|
||||
{
|
||||
static uint32_t first_time_detected = 0;
|
||||
if (lvs->current > 0.5 && half_bridge_enabled() == false) {
|
||||
if (inductor_current > 0.5 && half_bridge_enabled() == false) {
|
||||
// if there is current even though the DC/DC is switched off, the
|
||||
// high-side MOSFET must be broken --> set flag and let main() decide
|
||||
// what to do... (e.g. call dcdc_self_destruction)
|
||||
@@ -234,19 +239,19 @@ __weak void Dcdc::control()
|
||||
mode_name = "buck";
|
||||
// Don't start directly at Vmpp (approx. 0.8 * Voc) to prevent high inrush
|
||||
// currents and stress on MOSFETs
|
||||
half_bridge_set_duty_cycle(lvs->bus->voltage / (hvs->bus->voltage - 1));
|
||||
half_bridge_set_duty_cycle(lvb->voltage / (hvb->voltage - 1));
|
||||
}
|
||||
else {
|
||||
mode_name = "boost";
|
||||
// Will automatically start with max. duty (0.97) if connected to a
|
||||
// nanogrid not yet started up (zero voltage)
|
||||
half_bridge_set_duty_cycle(lvs->bus->voltage / (hvs->bus->voltage + 1));
|
||||
half_bridge_set_duty_cycle(lvb->voltage / (hvb->voltage + 1));
|
||||
}
|
||||
|
||||
half_bridge_start();
|
||||
power_good_timestamp = uptime();
|
||||
printf("DC/DC %s mode start (HV: %.2fV, LV: %.2fV, PWM: %.1f).\n", mode_name,
|
||||
hvs->bus->voltage, lvs->bus->voltage, half_bridge_get_duty_cycle() * 100);
|
||||
hvb->voltage, lvb->voltage, half_bridge_get_duty_cycle() * 100);
|
||||
|
||||
}
|
||||
else {
|
||||
@@ -256,7 +261,7 @@ __weak void Dcdc::control()
|
||||
else { // half bridge is on
|
||||
|
||||
const char *stop_reason = NULL;
|
||||
if (lvs->bus->voltage > ls_voltage_max || hvs->bus->voltage > hs_voltage_max) {
|
||||
if (lvb->voltage > ls_voltage_max || hvb->voltage > hs_voltage_max) {
|
||||
stop_reason = "emergency (voltage limits exceeded)";
|
||||
}
|
||||
else if (enable == false) {
|
||||
@@ -292,10 +297,10 @@ void Dcdc::test()
|
||||
|
||||
if (startup_delay_counter > num_wait_calls) {
|
||||
if (check_start_conditions() != DCDC_MODE_OFF) {
|
||||
half_bridge_set_duty_cycle(lvs->bus->voltage / hvs->bus->voltage);
|
||||
half_bridge_set_duty_cycle(lvb->voltage / hvb->voltage);
|
||||
half_bridge_start();
|
||||
printf("DC/DC test mode start (HV: %.2fV, LV: %.2fV, PWM: %.1f).\n",
|
||||
hvs->bus->voltage, lvs->bus->voltage, half_bridge_get_duty_cycle() * 100);
|
||||
hvb->voltage, lvb->voltage, half_bridge_get_duty_cycle() * 100);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -347,6 +352,6 @@ void Dcdc::output_hvs_disable()
|
||||
|
||||
#else
|
||||
|
||||
Dcdc::Dcdc(PowerPort *hv_side, PowerPort *lv_side, DcdcOperationMode op_mode) {}
|
||||
Dcdc::Dcdc(DcBus *high, DcBus *low, DcdcOperationMode op_mode) {}
|
||||
|
||||
#endif /* DT_NODE_EXISTS(DT_PATH(dcdc)) */
|
||||
|
||||
+9
-7
@@ -87,11 +87,11 @@ public:
|
||||
*
|
||||
* See http://libre.solar/docs/dcdc_control for detailed information
|
||||
*
|
||||
* @param hv_side High voltage terminal (e.g. solar input for MPPT buck)
|
||||
* @param lv_side Low voltage terminal (e.g. battery output for MPPT buck)
|
||||
* @param high High voltage bus (e.g. solar input for MPPT buck)
|
||||
* @param low Low voltage bus (e.g. battery output for MPPT buck)
|
||||
* @param mode Operation mode (buck, boost or nanogrid)
|
||||
*/
|
||||
Dcdc(PowerPort *hv_side, PowerPort* lv_side, DcdcOperationMode mode);
|
||||
Dcdc(DcBus *high, DcBus* low, DcdcOperationMode mode);
|
||||
|
||||
/**
|
||||
* Check for valid start conditions of the DC/DC converter
|
||||
@@ -135,8 +135,10 @@ public:
|
||||
uint16_t state; ///< Control state (off / MPPT / CC / CV)
|
||||
|
||||
// actual measurements
|
||||
PowerPort *hvs; ///< Pointer to DC bus at high voltage side
|
||||
PowerPort *lvs; ///< Pointer to DC bus at low voltage (inductor) side
|
||||
DcBus *hvb; ///< Pointer to DC bus at high voltage side
|
||||
DcBus *lvb; ///< Pointer to DC bus at low voltage (inductor) side
|
||||
float inductor_current; ///< Inductor current
|
||||
float power; ///< Low-side power
|
||||
float temp_mosfets; ///< MOSFET temperature measurement (if existing)
|
||||
|
||||
// current state
|
||||
@@ -146,8 +148,8 @@ public:
|
||||
int32_t power_good_timestamp; ///< Last time the DC/DC reached above minimum output power
|
||||
|
||||
// maximum allowed values
|
||||
float ls_current_max = 0; ///< Maximum low-side (inductor) current
|
||||
float hs_voltage_max = 0; ///< Maximum high-side voltage
|
||||
float inductor_current_max = 0; ///< Maximum low-side (inductor) current
|
||||
float hs_voltage_max = 0; ///< Maximum high-side voltage
|
||||
float ls_voltage_max; ///< Maximum low-side voltage
|
||||
float ls_voltage_min; ///< Minimum low-side voltage, e.g. for driver supply
|
||||
float output_power_min; ///< Minimum output power (if lower, DC/DC is switched off)
|
||||
|
||||
@@ -122,8 +122,8 @@ void DeviceStatus::update_min_max_values()
|
||||
#endif
|
||||
|
||||
#if DT_NODE_EXISTS(DT_PATH(dcdc))
|
||||
if (dcdc.lvs->current > dcdc_current_max) {
|
||||
dcdc_current_max = dcdc.lvs->current;
|
||||
if (dcdc.inductor_current > dcdc_current_max) {
|
||||
dcdc_current_max = dcdc.inductor_current;
|
||||
}
|
||||
|
||||
if (dcdc.temp_mosfets > mosfet_temp_max) {
|
||||
|
||||
+3
-4
@@ -31,13 +31,12 @@ PowerPort lv_terminal(&lv_bus, true); // low voltage terminal (battery for typ
|
||||
#if DT_NODE_EXISTS(DT_PATH(dcdc))
|
||||
DcBus hv_bus;
|
||||
PowerPort hv_terminal(&hv_bus, true); // high voltage terminal (solar for typical MPPT)
|
||||
PowerPort dcdc_lv_port(&lv_bus); // internal low voltage side of DC/DC converter
|
||||
#if CONFIG_HV_TERMINAL_NANOGRID
|
||||
Dcdc dcdc(&hv_terminal, &dcdc_lv_port, DCDC_MODE_AUTO);
|
||||
Dcdc dcdc(&hv_bus, &lv_bus, DCDC_MODE_AUTO);
|
||||
#elif CONFIG_HV_TERMINAL_BATTERY
|
||||
Dcdc dcdc(&hv_terminal, &dcdc_lv_port, DCDC_MODE_BOOST);
|
||||
Dcdc dcdc(&hv_bus, &lv_bus, DCDC_MODE_BOOST);
|
||||
#else
|
||||
Dcdc dcdc(&hv_terminal, &dcdc_lv_port, DCDC_MODE_BUCK);
|
||||
Dcdc dcdc(&hv_bus, &lv_bus, DCDC_MODE_BUCK);
|
||||
#endif // CONFIG_HV_TERMINAL
|
||||
#endif
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@ extern PowerPort lv_terminal;
|
||||
#if DT_NODE_EXISTS(DT_PATH(dcdc))
|
||||
extern DcBus hv_bus;
|
||||
extern PowerPort hv_terminal;
|
||||
extern PowerPort dcdc_lv_port;
|
||||
extern Dcdc dcdc;
|
||||
#endif
|
||||
|
||||
|
||||
@@ -86,12 +86,6 @@ void check_load_terminal_readings()
|
||||
TEST_ASSERT_EQUAL_FLOAT(adcval.load_current, round(load.current * 10) / 10);
|
||||
}
|
||||
|
||||
void check_lv_bus_int_readings()
|
||||
{
|
||||
TEST_ASSERT_EQUAL_FLOAT(adcval.battery_voltage, round(dcdc_lv_port.bus->voltage * 10) / 10);
|
||||
TEST_ASSERT_EQUAL_FLOAT(adcval.dcdc_current, round(dcdc_lv_port.current * 10) / 10);
|
||||
}
|
||||
|
||||
void check_temperature_readings()
|
||||
{
|
||||
TEST_ASSERT_EQUAL_FLOAT(adcval.bat_temperature, round(charger.bat_temperature * 10) / 10);
|
||||
@@ -208,7 +202,6 @@ void daq_tests()
|
||||
RUN_TEST(check_solar_terminal_readings);
|
||||
RUN_TEST(check_bat_terminal_readings);
|
||||
RUN_TEST(check_load_terminal_readings);
|
||||
RUN_TEST(check_lv_bus_int_readings);
|
||||
|
||||
//RUN_TEST(check_temperature_readings); // TODO
|
||||
|
||||
|
||||
+48
-29
@@ -25,16 +25,18 @@ static void init_structs_buck(int num_batteries = 1)
|
||||
hv_terminal.update_bus_current_margins();
|
||||
|
||||
battery_conf_init(&bat_conf, BAT_TYPE_GEL, 6, 100);
|
||||
charger.port = &dcdc_lv_port;
|
||||
charger.port = &lv_terminal;
|
||||
charger.init_terminal(&bat_conf);
|
||||
dcdc_lv_port.bus->voltage = 14 * num_batteries;
|
||||
dcdc_lv_port.bus->series_multiplier = num_batteries;
|
||||
dcdc_lv_port.current = 0;
|
||||
dcdc_lv_port.update_bus_current_margins();
|
||||
lv_terminal.bus->voltage = 14 * num_batteries;
|
||||
lv_terminal.bus->series_multiplier = num_batteries;
|
||||
lv_terminal.current = 0;
|
||||
lv_terminal.update_bus_current_margins();
|
||||
|
||||
dcdc.mode = DCDC_MODE_BUCK;
|
||||
dcdc.temp_mosfets = 25;
|
||||
dcdc.off_timestamp = 0;
|
||||
dcdc.inductor_current = 0;
|
||||
dcdc.power = 0;
|
||||
dcdc.power_prev = 0;
|
||||
dcdc.pwm_delta = 1;
|
||||
dcdc.enable = true;
|
||||
@@ -56,12 +58,12 @@ static void init_structs_boost(int num_batteries = 1)
|
||||
half_bridge_stop();
|
||||
|
||||
hv_terminal.init_solar();
|
||||
dcdc_lv_port.bus->voltage = 20;
|
||||
dcdc_lv_port.bus->src_voltage_intercept = 18;
|
||||
dcdc_lv_port.bus->series_multiplier = 1;
|
||||
dcdc_lv_port.current = 0;
|
||||
dcdc_lv_port.power = 0;
|
||||
dcdc_lv_port.update_bus_current_margins();
|
||||
lv_terminal.bus->voltage = 20;
|
||||
lv_terminal.bus->src_voltage_intercept = 18;
|
||||
lv_terminal.bus->series_multiplier = 1;
|
||||
dcdc.inductor_current = 0;
|
||||
dcdc.power = 0;
|
||||
lv_terminal.update_bus_current_margins();
|
||||
|
||||
int num_cells = (num_batteries == 1) ? 10 : 5;
|
||||
battery_conf_init(&bat_conf, BAT_TYPE_NMC, num_cells, 9);
|
||||
@@ -134,7 +136,7 @@ void no_start_if_dcdc_disabled()
|
||||
void no_start_if_dcdc_lv_voltage_low()
|
||||
{
|
||||
init_structs_buck();
|
||||
dcdc_lv_port.bus->voltage = dcdc.ls_voltage_min - 0.5;
|
||||
lv_terminal.bus->voltage = dcdc.ls_voltage_min - 0.5;
|
||||
TEST_ASSERT_EQUAL(DCDC_MODE_OFF, dcdc.check_start_conditions());
|
||||
}
|
||||
|
||||
@@ -143,14 +145,14 @@ void no_start_if_dcdc_lv_voltage_low()
|
||||
void no_buck_start_if_bat_voltage_high()
|
||||
{
|
||||
init_structs_buck();
|
||||
dcdc_lv_port.bus->voltage = bat_conf.topping_voltage + 0.1;
|
||||
lv_terminal.bus->voltage = bat_conf.topping_voltage + 0.1;
|
||||
TEST_ASSERT_EQUAL(DCDC_MODE_OFF, dcdc.check_start_conditions());
|
||||
}
|
||||
|
||||
void no_buck_start_if_bat_chg_not_allowed()
|
||||
{
|
||||
init_structs_buck();
|
||||
dcdc_lv_port.bus->sink_current_margin = 0;
|
||||
lv_terminal.bus->sink_current_margin = 0;
|
||||
TEST_ASSERT_EQUAL(DCDC_MODE_OFF, dcdc.check_start_conditions());
|
||||
}
|
||||
|
||||
@@ -187,14 +189,14 @@ void no_boost_start_if_bat_chg_not_allowed()
|
||||
void no_boost_start_if_solar_voltage_high()
|
||||
{
|
||||
init_structs_boost();
|
||||
dcdc_lv_port.bus->voltage = dcdc.ls_voltage_max + 1;
|
||||
lv_terminal.bus->voltage = dcdc.ls_voltage_max + 1;
|
||||
TEST_ASSERT_EQUAL(DCDC_MODE_OFF, dcdc.check_start_conditions());
|
||||
}
|
||||
|
||||
void no_boost_start_if_solar_voltage_low()
|
||||
{
|
||||
init_structs_boost();
|
||||
dcdc_lv_port.bus->voltage = 17;
|
||||
lv_terminal.bus->voltage = 17;
|
||||
TEST_ASSERT_EQUAL(DCDC_MODE_OFF, dcdc.check_start_conditions());
|
||||
}
|
||||
|
||||
@@ -213,7 +215,7 @@ void buck_derating_output_voltage_too_high()
|
||||
{
|
||||
start_buck();
|
||||
float pwm_before = half_bridge_get_duty_cycle();
|
||||
dcdc_lv_port.bus->voltage = dcdc_lv_port.bus->sink_voltage_intercept + 0.1;
|
||||
lv_terminal.bus->voltage = lv_terminal.bus->sink_voltage_intercept + 0.1;
|
||||
dcdc.control();
|
||||
float pwm_after = half_bridge_get_duty_cycle();
|
||||
TEST_ASSERT(pwm_after < pwm_before); // less duty cycle = higher voltage
|
||||
@@ -224,7 +226,19 @@ void buck_derating_output_current_too_high()
|
||||
{
|
||||
start_buck();
|
||||
float pwm_before = half_bridge_get_duty_cycle();
|
||||
dcdc_lv_port.current = dcdc_lv_port.pos_current_limit + 0.1;
|
||||
lv_terminal.current = lv_terminal.pos_current_limit + 0.1;
|
||||
lv_terminal.update_bus_current_margins();
|
||||
dcdc.control();
|
||||
float pwm_after = half_bridge_get_duty_cycle();
|
||||
TEST_ASSERT(pwm_after < pwm_before);
|
||||
TEST_ASSERT_EQUAL(DCDC_CONTROL_CC_LS, dcdc.state);
|
||||
}
|
||||
|
||||
void buck_derating_inductor_current_too_high()
|
||||
{
|
||||
start_buck();
|
||||
float pwm_before = half_bridge_get_duty_cycle();
|
||||
dcdc.inductor_current = dcdc.inductor_current_max + 0.1;
|
||||
dcdc.control();
|
||||
float pwm_after = half_bridge_get_duty_cycle();
|
||||
TEST_ASSERT(pwm_after < pwm_before);
|
||||
@@ -236,7 +250,7 @@ void buck_derating_input_voltage_too_low()
|
||||
start_buck();
|
||||
float pwm_before = half_bridge_get_duty_cycle();
|
||||
hv_terminal.bus->voltage = hv_terminal.bus->src_voltage_intercept - 0.1;
|
||||
dcdc_lv_port.current = 0.2;
|
||||
dcdc.power = 1.2;
|
||||
dcdc.control();
|
||||
float pwm_after = half_bridge_get_duty_cycle();
|
||||
TEST_ASSERT(pwm_after < pwm_before);
|
||||
@@ -248,6 +262,7 @@ void buck_derating_input_current_too_high()
|
||||
start_buck();
|
||||
float pwm_before = half_bridge_get_duty_cycle();
|
||||
hv_terminal.current = hv_terminal.neg_current_limit - 0.1;
|
||||
hv_terminal.update_bus_current_margins();
|
||||
dcdc.control();
|
||||
float pwm_after = half_bridge_get_duty_cycle();
|
||||
TEST_ASSERT(pwm_after < pwm_before);
|
||||
@@ -275,7 +290,7 @@ void buck_stop_input_power_too_low()
|
||||
void buck_stop_high_voltage_emergency()
|
||||
{
|
||||
start_buck();
|
||||
dcdc_lv_port.bus->voltage = dcdc.ls_voltage_max + 0.1;
|
||||
lv_terminal.bus->voltage = dcdc.ls_voltage_max + 0.1;
|
||||
dcdc.control();
|
||||
TEST_ASSERT(half_bridge_enabled() == false);
|
||||
}
|
||||
@@ -284,15 +299,15 @@ void buck_correct_mppt_operation()
|
||||
{
|
||||
start_buck();
|
||||
|
||||
dcdc_lv_port.power = 5;
|
||||
dcdc.power = 5;
|
||||
dcdc.control();
|
||||
float pwm1 = half_bridge_get_duty_cycle();
|
||||
dcdc_lv_port.power = 7;
|
||||
dcdc.power = 7;
|
||||
dcdc.control();
|
||||
float pwm2 = half_bridge_get_duty_cycle();
|
||||
TEST_ASSERT(pwm2 > pwm1);
|
||||
|
||||
dcdc_lv_port.power = 6; // decrease power to make the direction turn around
|
||||
dcdc.power = 6; // decrease power to make the direction turn around
|
||||
dcdc.control();
|
||||
float pwm3 = half_bridge_get_duty_cycle();
|
||||
TEST_ASSERT(pwm3 < pwm2);
|
||||
@@ -325,6 +340,7 @@ void boost_derating_output_current_too_high()
|
||||
start_boost();
|
||||
float pwm_before = half_bridge_get_duty_cycle();
|
||||
hv_terminal.current = hv_terminal.pos_current_limit + 0.1;
|
||||
hv_terminal.update_bus_current_margins();
|
||||
dcdc.control();
|
||||
float pwm_after = half_bridge_get_duty_cycle();
|
||||
TEST_ASSERT(pwm_after > pwm_before);
|
||||
@@ -334,10 +350,12 @@ void boost_derating_input_voltage_too_low()
|
||||
{
|
||||
start_boost();
|
||||
float pwm_before = half_bridge_get_duty_cycle();
|
||||
dcdc_lv_port.bus->voltage = dcdc_lv_port.bus->src_voltage_intercept - 0.1;
|
||||
hv_terminal.current = 0.2;
|
||||
lv_terminal.bus->voltage = lv_terminal.bus->src_voltage_intercept - 0.1;
|
||||
dcdc.power = -1.2;
|
||||
hv_terminal.update_bus_current_margins();
|
||||
dcdc.control();
|
||||
float pwm_after = half_bridge_get_duty_cycle();
|
||||
TEST_ASSERT_EQUAL(DCDC_CONTROL_CV_LS, dcdc.state);
|
||||
TEST_ASSERT(pwm_after > pwm_before);
|
||||
}
|
||||
|
||||
@@ -345,7 +363,7 @@ void boost_derating_input_current_too_high()
|
||||
{
|
||||
start_boost();
|
||||
float pwm_before = half_bridge_get_duty_cycle();
|
||||
dcdc_lv_port.current = dcdc_lv_port.neg_current_limit - 0.1;
|
||||
dcdc.inductor_current = lv_terminal.neg_current_limit - 0.1;
|
||||
dcdc.control();
|
||||
float pwm_after = half_bridge_get_duty_cycle();
|
||||
TEST_ASSERT(pwm_after > pwm_before);
|
||||
@@ -381,15 +399,15 @@ void boost_correct_mppt_operation()
|
||||
{
|
||||
start_boost();
|
||||
|
||||
hv_terminal.power = 5;
|
||||
dcdc.power = -5;
|
||||
dcdc.control();
|
||||
float pwm1 = half_bridge_get_duty_cycle();
|
||||
hv_terminal.power = 7;
|
||||
dcdc.power = -7;
|
||||
dcdc.control();
|
||||
float pwm2 = half_bridge_get_duty_cycle();
|
||||
TEST_ASSERT(pwm2 < pwm1);
|
||||
|
||||
hv_terminal.power = 6; // decrease power to make the direction turn around
|
||||
dcdc.power = -6; // decrease power to make the direction turn around
|
||||
dcdc.control();
|
||||
float pwm3 = half_bridge_get_duty_cycle();
|
||||
TEST_ASSERT(pwm3 > pwm2);
|
||||
@@ -435,6 +453,7 @@ void dcdc_tests()
|
||||
RUN_TEST(buck_increasing_power);
|
||||
RUN_TEST(buck_derating_output_voltage_too_high);
|
||||
RUN_TEST(buck_derating_output_current_too_high);
|
||||
RUN_TEST(buck_derating_inductor_current_too_high);
|
||||
RUN_TEST(buck_derating_input_voltage_too_low);
|
||||
RUN_TEST(buck_derating_input_current_too_high);
|
||||
RUN_TEST(buck_derating_temperature_limits_exceeded);
|
||||
|
||||
@@ -69,7 +69,7 @@ void dev_stat_new_bat_voltage_max()
|
||||
|
||||
void dev_stat_new_dcdc_current_max()
|
||||
{
|
||||
dcdc.lvs->current = 21;
|
||||
dcdc.inductor_current = 21;
|
||||
dev_stat.update_min_max_values();
|
||||
TEST_ASSERT_EQUAL(21, dev_stat.dcdc_current_max);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user