Rename DC/DC operation mode and control names
New control states allow to specify the reason for derating more detailed, also considering the input side. The operation mode is now also used as a return value for check_start_conditions function to get rid of magic numbers.
This commit is contained in:
+28
-23
@@ -38,7 +38,7 @@ Dcdc::Dcdc(PowerPort *hv_side, PowerPort *lv_side, DcdcOperationMode op_mode)
|
||||
lvs = lv_side;
|
||||
mode = op_mode;
|
||||
enable = true;
|
||||
state = DCDC_STATE_OFF;
|
||||
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);
|
||||
@@ -61,9 +61,7 @@ int Dcdc::perturb_observe_controller()
|
||||
PowerPort *in;
|
||||
PowerPort *out;
|
||||
|
||||
if (mode == MODE_MPPT_BUCK ||
|
||||
(mode == MODE_NANOGRID && lvs->current > 0.1))
|
||||
{
|
||||
if (mode == DCDC_MODE_BUCK || (mode == DCDC_MODE_AUTO && lvs->current > 0.1)) {
|
||||
// buck mode
|
||||
pwr_inc_pwm_direction = 1;
|
||||
in = hvs;
|
||||
@@ -82,36 +80,43 @@ int Dcdc::perturb_observe_controller()
|
||||
|
||||
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 != MODE_NANOGRID) {
|
||||
// swith off after 10s low power or negative power (if not in nanogrid mode)
|
||||
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()) {
|
||||
// output voltage target reached
|
||||
state = DCDC_STATE_CV;
|
||||
state = (out == lvs) ? DCDC_CONTROL_CV_LS : DCDC_CONTROL_CV_HS;
|
||||
pwr_inc_goal = -1; // decrease output power
|
||||
}
|
||||
else if (out->current > out->pos_current_limit) {
|
||||
// output charge current limit reached
|
||||
state = DCDC_STATE_CC;
|
||||
state = (out == lvs) ? 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
|
||||
|| temp_mosfets > 80 // temperature limits exceeded
|
||||
|| (in->bus->voltage < in->bus->src_control_voltage()
|
||||
&& out->current > 0.1) // input voltage below limit
|
||||
|| in->current < in->neg_current_limit) // input current (negative signs) limit exceeded
|
||||
{
|
||||
state = DCDC_STATE_DERATING;
|
||||
state = (in == hvs) ? 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) {
|
||||
// input voltage below limit
|
||||
state = (in == hvs) ? DCDC_CONTROL_CV_HS : DCDC_CONTROL_CV_LS;
|
||||
pwr_inc_goal = -1;
|
||||
}
|
||||
else if (temp_mosfets > 80) {
|
||||
// temperature limits exceeded
|
||||
state = DCDC_CONTROL_DERATING;
|
||||
pwr_inc_goal = -1;
|
||||
}
|
||||
else if (out->power < output_power_min && out->bus->voltage < out->bus->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_STATE_MPPT;
|
||||
state = DCDC_CONTROL_MPPT;
|
||||
if (power_prev > out->power) {
|
||||
pwm_delta = -pwm_delta;
|
||||
}
|
||||
@@ -136,7 +141,7 @@ int Dcdc::perturb_observe_controller()
|
||||
return (pwr_inc_goal == 0);
|
||||
}
|
||||
|
||||
__weak int Dcdc::check_start_conditions()
|
||||
__weak DcdcOperationMode Dcdc::check_start_conditions()
|
||||
{
|
||||
if (enable == false ||
|
||||
hvs->bus->voltage > hs_voltage_max || // also critical for buck mode because of ringing
|
||||
@@ -145,7 +150,7 @@ __weak int Dcdc::check_start_conditions()
|
||||
dev_stat.has_error(ERR_BAT_UNDERVOLTAGE | ERR_BAT_OVERVOLTAGE) ||
|
||||
(int)uptime() < (off_timestamp + (int)restart_interval))
|
||||
{
|
||||
return 0; // no energy transfer allowed
|
||||
return DCDC_MODE_OFF;
|
||||
}
|
||||
|
||||
if (lvs->bus->sink_current_margin > 0 &&
|
||||
@@ -154,7 +159,7 @@ __weak int Dcdc::check_start_conditions()
|
||||
hvs->bus->voltage > hvs->bus->src_control_voltage() &&
|
||||
hvs->bus->voltage * 0.85 > lvs->bus->voltage)
|
||||
{
|
||||
return 1; // start in buck mode allowed
|
||||
return DCDC_MODE_BUCK;
|
||||
}
|
||||
|
||||
if (hvs->bus->sink_current_margin > 0 &&
|
||||
@@ -162,10 +167,10 @@ __weak int Dcdc::check_start_conditions()
|
||||
lvs->bus->src_current_margin < 0 &&
|
||||
lvs->bus->voltage > lvs->bus->src_control_voltage())
|
||||
{
|
||||
return -1; // start in boost mode allowed
|
||||
return DCDC_MODE_BOOST;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return DCDC_MODE_OFF;
|
||||
}
|
||||
|
||||
bool Dcdc::check_hs_mosfet_short()
|
||||
@@ -217,7 +222,7 @@ __weak void Dcdc::control()
|
||||
|
||||
int startup_mode = check_start_conditions();
|
||||
|
||||
if (startup_mode != 0) {
|
||||
if (startup_mode != DCDC_MODE_OFF) {
|
||||
|
||||
// startup allowed, but we need to wait until voltages settle
|
||||
if (startup_inhibit()) {
|
||||
@@ -225,7 +230,7 @@ __weak void Dcdc::control()
|
||||
}
|
||||
|
||||
const char *mode_name = NULL;
|
||||
if (startup_mode == 1) {
|
||||
if (startup_mode == DCDC_MODE_BUCK) {
|
||||
mode_name = "buck";
|
||||
// Don't start directly at Vmpp (approx. 0.8 * Voc) to prevent high inrush
|
||||
// currents and stress on MOSFETs
|
||||
@@ -266,7 +271,7 @@ __weak void Dcdc::control()
|
||||
|
||||
if (stop_reason != NULL) {
|
||||
half_bridge_stop();
|
||||
state = DCDC_STATE_OFF;
|
||||
state = DCDC_CONTROL_OFF;
|
||||
off_timestamp = uptime();
|
||||
printf("DC/DC Stop: %s.\n", stop_reason);
|
||||
}
|
||||
@@ -288,7 +293,7 @@ void Dcdc::test()
|
||||
(CONFIG_CONTROL_FREQUENCY / 10 >= 1) ? (CONFIG_CONTROL_FREQUENCY / 10) : 1;
|
||||
|
||||
if (startup_delay_counter > num_wait_calls) {
|
||||
if (check_start_conditions() != 0) {
|
||||
if (check_start_conditions() != DCDC_MODE_OFF) {
|
||||
half_bridge_set_duty_cycle(lvs->bus->voltage / hvs->bus->voltage);
|
||||
half_bridge_start();
|
||||
printf("DC/DC test mode start (HV: %.2fV, LV: %.2fV, PWM: %.1f).\n",
|
||||
@@ -304,7 +309,7 @@ void Dcdc::test()
|
||||
void Dcdc::emergency_stop()
|
||||
{
|
||||
half_bridge_stop();
|
||||
state = DCDC_STATE_OFF;
|
||||
state = DCDC_CONTROL_OFF;
|
||||
off_timestamp = uptime();
|
||||
}
|
||||
|
||||
|
||||
+57
-23
@@ -7,7 +7,8 @@
|
||||
#ifndef DCDC_H
|
||||
#define DCDC_H
|
||||
|
||||
/** @file
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* @brief DC/DC buck/boost control functions
|
||||
*/
|
||||
@@ -19,34 +20,61 @@
|
||||
|
||||
#include "power_port.h"
|
||||
|
||||
/** DC/DC basic operation mode
|
||||
/**
|
||||
* DC/DC operation mode
|
||||
*
|
||||
* Defines which type of device is connected to the high side and low side ports
|
||||
*/
|
||||
enum DcdcOperationMode
|
||||
{
|
||||
MODE_MPPT_BUCK, ///< solar panel at high side port, battery / load at low side port (typical MPPT)
|
||||
MODE_MPPT_BOOST, ///< battery at high side port, solar panel at low side (e.g. e-bike charging)
|
||||
MODE_NANOGRID ///< accept input power (if available and need for charging) or provide output power
|
||||
///< (if no other power source on the grid and battery charged) on the high side port
|
||||
///< and dis/charge battery on the low side port, battery voltage must be lower than
|
||||
///< nano grid voltage.
|
||||
/**
|
||||
* DC/DC converter switched off
|
||||
*/
|
||||
DCDC_MODE_OFF,
|
||||
|
||||
/**
|
||||
* Buck converter mode
|
||||
*
|
||||
* Solar panel at high side port, battery / load at low side port (typical MPPT).
|
||||
*/
|
||||
DCDC_MODE_BUCK,
|
||||
|
||||
/**
|
||||
* Boost converter mode
|
||||
*
|
||||
* Battery at high side port, solar panel at low side (e.g. e-bike charging).
|
||||
*/
|
||||
DCDC_MODE_BOOST,
|
||||
|
||||
/**
|
||||
* Automatic mode selection
|
||||
*
|
||||
* Boost or buck mode is automatically chosen based on high-side and low-side port settings.
|
||||
*
|
||||
* May be used in nanogrid applications: Accept input power (if available and need for charging)
|
||||
* or provide output power (if no other power source available on the grid and battery charged)
|
||||
*/
|
||||
DCDC_MODE_AUTO
|
||||
};
|
||||
|
||||
/** DC/DC control state
|
||||
/**
|
||||
* DC/DC control state
|
||||
*
|
||||
* Allows to determine the current control state (off, CC, CV and MPPT)
|
||||
*/
|
||||
enum DcdcControlState
|
||||
{
|
||||
DCDC_STATE_OFF, ///< DC/DC switched off (low input power available or actively disabled)
|
||||
DCDC_STATE_MPPT, ///< Maximum Power Point Tracking
|
||||
DCDC_STATE_CC, ///< Constant-Current control
|
||||
DCDC_STATE_CV, ///< Constant-Voltage control
|
||||
DCDC_STATE_DERATING ///< Hardware-limits (current or temperature) reached
|
||||
DCDC_CONTROL_OFF, ///< DC/DC switched off (low input power or actively disabled)
|
||||
DCDC_CONTROL_MPPT, ///< Maximum Power Point Tracking
|
||||
DCDC_CONTROL_CC_LS, ///< Constant-Current control at low-side
|
||||
DCDC_CONTROL_CV_LS, ///< Constant-Voltage control at low-side
|
||||
DCDC_CONTROL_CC_HS, ///< Constant-Current control at high-side
|
||||
DCDC_CONTROL_CV_HS, ///< Constant-Voltage control at high-side
|
||||
DCDC_CONTROL_DERATING ///< Hardware-limits (current or temperature) reached
|
||||
};
|
||||
|
||||
/** DC/DC class
|
||||
/**
|
||||
* DC/DC class
|
||||
*
|
||||
* Contains all data belonging to the DC/DC sub-component of the PCB, incl.
|
||||
* actual measurements and calibration parameters.
|
||||
@@ -54,7 +82,8 @@ enum DcdcControlState
|
||||
class Dcdc
|
||||
{
|
||||
public:
|
||||
/** Initialize DC/DC and DC/DC port structs
|
||||
/**
|
||||
* Initialize DC/DC and DC/DC port structs
|
||||
*
|
||||
* See http://libre.solar/docs/dcdc_control for detailed information
|
||||
*
|
||||
@@ -64,29 +93,34 @@ public:
|
||||
*/
|
||||
Dcdc(PowerPort *hv_side, PowerPort* lv_side, DcdcOperationMode mode);
|
||||
|
||||
/** Check for valid start conditions of the DC/DC converter
|
||||
/**
|
||||
* Check for valid start conditions of the DC/DC converter
|
||||
*
|
||||
* @returns 1 for buck mode, -1 for boost mode and 0 for invalid conditions
|
||||
* @returns operation mode that is valid for starting up
|
||||
*/
|
||||
int check_start_conditions();
|
||||
DcdcOperationMode check_start_conditions();
|
||||
|
||||
/** Main control function for the DC/DC converter
|
||||
/**
|
||||
* Main control function for the DC/DC converter
|
||||
*
|
||||
* If DC/DC is off, this function checks start conditions and starts conversion if possible.
|
||||
*/
|
||||
void control();
|
||||
|
||||
/** Test mode for DC/DC, ramping up to 50% duty cycle
|
||||
/**
|
||||
* Test mode for DC/DC, ramping up to 50% duty cycle
|
||||
*/
|
||||
void test();
|
||||
|
||||
/** Fast emergency stop function
|
||||
/**
|
||||
* Fast emergency stop function
|
||||
*
|
||||
* May be called from an ISR which detected overvoltage / overcurrent conditions
|
||||
*/
|
||||
void emergency_stop();
|
||||
|
||||
/** Prevent overcharging of battery in case of shorted HS MOSFET
|
||||
/**
|
||||
* Prevent overcharging of battery in case of shorted HS MOSFET
|
||||
*
|
||||
* This function switches the LS MOSFET continuously on to blow the battery input fuse. The
|
||||
* reason for self destruction should be logged and stored to EEPROM prior to calling this
|
||||
|
||||
+1
-1
@@ -133,7 +133,7 @@ void control_thread()
|
||||
|
||||
// energy + soc calculation must be called exactly once per second
|
||||
#if DT_NODE_EXISTS(DT_PATH(dcdc))
|
||||
if (dcdc.state != DCDC_STATE_OFF) {
|
||||
if (dcdc.state != DCDC_CONTROL_OFF) {
|
||||
hv_terminal.energy_balance();
|
||||
}
|
||||
#endif
|
||||
|
||||
+3
-3
@@ -33,11 +33,11 @@ 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, MODE_NANOGRID);
|
||||
Dcdc dcdc(&hv_terminal, &dcdc_lv_port, DCDC_MODE_AUTO);
|
||||
#elif CONFIG_HV_TERMINAL_BATTERY
|
||||
Dcdc dcdc(&hv_terminal, &dcdc_lv_port, MODE_MPPT_BOOST);
|
||||
Dcdc dcdc(&hv_terminal, &dcdc_lv_port, DCDC_MODE_BOOST);
|
||||
#else
|
||||
Dcdc dcdc(&hv_terminal, &dcdc_lv_port, MODE_MPPT_BUCK);
|
||||
Dcdc dcdc(&hv_terminal, &dcdc_lv_port, DCDC_MODE_BUCK);
|
||||
#endif // CONFIG_HV_TERMINAL
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user