DC/DC converter
DC/DC buck/boost control functions.
High-level functions to control the DC/DC converter. This module does not directly access any hardware. The PWM signal for the half bridge is generated in a separate module.
Enums
-
enum DcdcOperationMode
DC/DC operation mode
Defines which type of device is connected to the high side and low side ports
Values:
-
enumerator DCDC_MODE_OFF
DC/DC converter switched off
-
enumerator DCDC_MODE_BUCK
Buck converter mode
Solar panel at high side port, battery / load at low side port (typical MPPT).
-
enumerator DCDC_MODE_BOOST
Boost converter mode
Battery at high side port, solar panel at low side (e.g. e-bike charging).
-
enumerator DCDC_MODE_AUTO
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)
-
enumerator DCDC_MODE_OFF
-
enum DcdcControlState
DC/DC control state
Allows to determine the current control state (off, CC, CV and MPPT)
Values:
-
enumerator DCDC_CONTROL_OFF
DC/DC switched off (low input power or actively disabled)
-
enumerator DCDC_CONTROL_MPPT
Maximum Power Point Tracking.
-
enumerator DCDC_CONTROL_CC_LS
Constant-Current control at low-side.
-
enumerator DCDC_CONTROL_CV_LS
Constant-Voltage control at low-side.
-
enumerator DCDC_CONTROL_CC_HS
Constant-Current control at high-side.
-
enumerator DCDC_CONTROL_CV_HS
Constant-Voltage control at high-side.
-
enumerator DCDC_CONTROL_DERATING
Hardware-limits (current or temperature) reached.
-
enumerator DCDC_CONTROL_OFF
Functions
-
void dcdc_low_level_controller()
Low-level control function
Implement this function e.g. for cycle-by-cylce current limitation.
It is called from the DMA after each new current reading, i.e. it runs in ISR context with high frequency and must be VERY fast!
-
class Dcdc
- #include <dcdc.h>
DC/DC class
Contains all data belonging to the DC/DC sub-component of the PCB, incl. actual measurements and calibration parameters.
Public Functions
-
Dcdc(DcBus *high, DcBus *low, DcdcOperationMode mode)
Initialize DC/DC and DC/DC port structs
See http://libre.solar/docs/dcdc_control for detailed information
- Parameters:
high – High voltage bus (e.g. solar input for MPPT buck)
low – Low voltage bus (e.g. battery output for MPPT buck)
mode – Operation mode (buck, boost or nanogrid)
-
DcdcOperationMode check_start_conditions()
Check for valid start conditions of the DC/DC converter
- Returns:
operation mode that is valid for starting up
-
void control()
Main control function for the DC/DC converter
If DC/DC is off, this function checks start conditions and starts conversion if possible.
-
void test()
Test mode for DC/DC, ramping up/down to 50% duty cycle
-
void stop()
Fast stop function (bypassing control loop)
May be called from an ISR which detected overvoltage / overcurrent conditions.
DC/DC will be restarted automatically from control function if condtions are valid.
-
void fuse_destruction()
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 function, as the charge controller power supply will be cut after the fuse is destroyed.
Public Members
-
DcdcOperationMode mode
DC/DC mode (buck, boost or nanogrid)
-
bool enable
Can be used to disable the DC/DC power stage.
-
uint16_t state
Control state (off / MPPT / CC / CV)
-
float inductor_current
Inductor current.
-
float power
Low-side power.
-
float temp_mosfets
MOSFET temperature measurement (if existing)
-
float power_prev
Stores previous conversion power (set via dcdc_control)
-
int32_t pwm_direction
Direction of PWM change for MPPT.
-
int32_t off_timestamp
Last time the DC/DC was switched off.
-
int32_t power_good_timestamp
Last time the DC/DC reached above minimum output power.
-
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)
-
uint32_t restart_interval
Restart interval (s): When should we retry to start charging after low output power cut-off?
Private Functions
-
void perturb_observe_buck()
MPPT perturb & observe control (buck mode)
- Returns:
calculated pwm duty cycle delta or 0 if the DC/DC should be stopped
-
void perturb_observe_boost()
MPPT perturb & observe control (boost mode)
- Returns:
calculated pwm duty cycle delta or 0 if the DC/DC should be stopped
-
void output_hvs_enable()
If manual control of the reverse polarity MOSFET on the high-side is available, this function enables it to use the high voltage side as output.
-
void output_hvs_disable()
Disable the reverse polarity MOSFET on the high-side (if option available)
-
bool check_hs_mosfet_short()
Check if the high-side MOSFET is shorted
-
bool startup_inhibit(bool reset = false)
Check if we need to wait for voltages to settle before starting the DC/DC
- Parameters:
reset – Reset the inhibit counter if set to true
- Returns:
true if we need to wait
-
Dcdc(DcBus *high, DcBus *low, DcdcOperationMode mode)