Load Output

Load/USB output functions and data types.

Enums

enum LoadState

Load/USB output states

Values:

enumerator LOAD_STATE_OFF

Actively disabled.

enumerator LOAD_STATE_ON

Normal state: On.

enum LoadErrorFlag

Load error flags

When adding new flags, please make sure to use only up to 32 errors Each enum must represent a unique power of 2 number

Values:

enumerator ERR_LOAD_SHEDDING

Available energy or power too low

Switching off the load can be triggered either by a low battery voltage or by low state of charge (SOC) in case of more advanced battery management.

Set in LoadOutput::control() and cleared after reconnect delay passed and voltage is above reconnect threshold again.

enumerator ERR_LOAD_OVERVOLTAGE

Too high voltage for load

Set and cleared in LoadOutput::control()

enumerator ERR_LOAD_OVERCURRENT

Long-term overcurrent at load port

Set in LoadOutput::control() and cleared after configurable delay.

enumerator ERR_LOAD_SHORT_CIRCUIT

Short circuit detected at load port

Set by LoadOutput::control() after overcurrent comparator triggered, cleared only if load output is manually disabled and enabled again.

enumerator ERR_LOAD_VOLTAGE_DIP

Overcurrent identified via voltage dip (may be caused by too small battery)

Set and cleared in LoadOutput::control(). Treated same as load overcurrent.

enumerator ERR_LOAD_BUS_SRC_CURRENT

The bus the load is connected to disabled sourcing current from it

Reasons can be that battery temperature limits were exceeded. Voltage limits should be covered by the load directly.

Functions

void load_out_init()
void usb_out_init()
void load_out_set(bool)
void usb_out_set(bool)
void load_short_circuit_stop()
bool pgood_check()
class LoadOutput : public PowerPort
#include <load.h>

Load output type

Stores status of load output incl. 5V USB output (if existing on PCB)

Public Functions

LoadOutput(DcBus *dc_bus, void (*switch_fn)(bool), void (*init_fn)(), bool (*pgood_fn)())

Initialize LoadOutput struct and overcurrent / short circuit protection comparator (if existing)

Parameters:
  • dc_bus – DC bus the load is connected to

  • switch_fn – Pointer to function for enabling/disabling load switch

  • init_fn – Pointer to function for load driver initialization

  • pgood_fn – Pointer to pgood check

void control()

Main load control function, should be called by control timer

This function includes the load state machine

void stop(uint32_t error_flag = 0)

Fast emergency stop function

May be called from an ISR which detected overvoltage / overcurrent conditions

Parameters:

error_flag – Optional error flag that should be set

void set_voltage_limits(float lvd, float lvr, float ov)

Update of load voltage limits (typically based on battery configuration)

Parameters:
  • lvd – Low voltage disconnect setpoint

  • lvr – Low voltage reconnect setpoint

  • ov – Overvoltage setpoint

Public Members

uint32_t state

Current state of load output switch.

uint32_t error_flags = 0

Stores error flags as bits according to LoadErrorFlag enum.

int32_t info

Contains either the state or negative value of error_flags in case of error_flags > 0. This allows to have a single variable for load state diagnosis.

bool enable = false

Target on state set via communication port (overruled if battery is empty or any errors occured)

time_t oc_timestamp

Time when last overcurrent event occured.

uint32_t oc_recovery_delay

Seconds before we attempt to re-enable the load after an overcurrent event

float disconnect_voltage = 0

Low voltage disconnect (LVD) setpoint.

float reconnect_voltage = 0

Low voltage reconnect (LVD) setpoint.

time_t lvd_timestamp

Time when last low voltage disconnect happened.

uint32_t lvd_recovery_delay

Seconds before we re-enable the load after a low voltage disconnect

float junction_temperature

calculated using thermal model based on current and ambient temperature measurement (unit: °C)

float overvoltage = 0

Upper voltage limit.

float ov_hysteresis

Hysteresis to switch back on after an overvoltage event.

Private Members

void (*switch_set)(bool)

Pointer to the load switch function

bool (*pgood_check)(void)

Pointer to the function to check the power output status

int uv_debounce_counter = 0

Used to prevent switching of because of very short voltage dip

int ov_debounce_counter = 0

Used to prevent switching off because of short voltage spike