DC Bus and Power Port

Definition of charge controller terminals and internal DC buses.

class DcBus
#include <power_port.h>

DC bus class

Stores measurement data and settings necessary for voltage control

Public Functions

inline float src_control_voltage(float voltage_zero_current = 0)

Calculate current-compensated src control voltage, considering droop and series multiplier

Parameters:

voltage_zero_current – Voltage at zero current (without droop). If this parameter is left empty, the src_voltage_intercept is considered.

inline float sink_control_voltage(float voltage_zero_current = 0)

Calculate current-compensated sink control voltage, considering droop and series multiplier

Parameters:

voltage_zero_current – Voltage at zero current (without droop). If this parameter is left empty, the sink_voltage_intercept is considered.

inline float series_voltage(float single_voltage)

Calculate voltage for series connected batteries based on setpoint for single battery

Parameters:

single_voltage – Voltage for single battery

Returns:

Total voltage

Public Members

float voltage = 0

Measured bus voltage

float voltage_filtered = 0

Filtered bus voltage

Suitable filter time constants depend on type of DC bus. This filtering is applied in addition to the raw ADC value filtering.

int16_t series_multiplier = 1

Multiplier for series connection of batteries

Used for automatic 12V/24V battery detection at start-up (can be 1 or 2 only)

This factor must be applied to all voltage setpoints

float sink_voltage_intercept = 0

Upper voltage boundary where this bus may be used to sink current.

This value is the voltage at zero current. Values for other currents are calculated using the droop resistance.

float src_voltage_intercept = 0

Lower voltage boundary where this bus may be used to source current.

This value is the voltage at zero current. Values for other currents are calculated using the droop resistance.

float src_droop_res = 0

Droop resistance to adjust voltage bounds for current in sourcing direction

control voltage = nominal voltage - droop_res * current

float sink_droop_res = 0

Droop resistance to adjust voltage bounds for current in sinking direction

control voltage = nominal voltage - droop_res * current

float *ref_current = NULL

Pointer to current measurement that is used to determine the droop. This is typically the battery or nanogrid terminal.

float sink_current_margin = 0

Available additional current towards the DC bus until limits of the connected ports are reached

float src_current_margin = 0

Available additional current from the DC bus until limits of the connected ports are reached (has a negative sign)

If for example a battery connected to the bus is not allowed to be discharged anymore, but we still get power via solar, current up to the amount of solar input can be diverted into the load (until the margin gets 0 and the battery would be discharged).

class PowerPort
#include <power_port.h>

Power Port class

Stores current measurements and limits for external terminals or internal ports

The signs follow the passive sign convention. Current or power from the considered system or circuit towards an external device connected to the port has a positive sign. For all terminals, the entire charge controller is considered as the system boundary and acts as a source or a sink. For internal sub-circuits, e.g. the DC/DC converter circuit defines the sub-system boundaries.

| | >> positive current/power direction | o-&#8212;>-&#8212; | | + | | considered | | | external device: battery / solar panel / load / DC grid | system or | | | | sub-circuit | | | (the port should be named after the external device) | | - | | o——&#8212;

Subclassed by LoadOutput, PwmSwitch

Public Functions

inline PowerPort(DcBus *dc_bus, bool assign_ref_current = false)

Constructor assigning the port to a DC bus

Parameters:
  • dc_bus – The DC bus this port is assigned to

  • assign_ref_current – defines if the bus ref_current should point to the current of this port (must be true for at least one port)

void init_solar()

Initialize power port for solar panel connection

void init_nanogrid()

Initialize power port for nanogrid connection

void energy_balance()

Energy balance calculation for power port

Must be called exactly once per second, otherwise energy calculation gets wrong.

void update_bus_current_margins() const

Sets current limits for control of the bus voltage

This function has to be called using the port defining the bus control targets, i.e. the battery, the solar panel or the DC grid.

Public Members

DcBus *bus = NULL

Each power port is connected to a DC bus, containing relevant voltage information

float current = 0

Measured current through this port (positive sign = current into the external device)

float current_filtered = 0

Filtered port current

Suitable filter time constants depend on type of port. This filtering is applied in addition to the raw ADC value filtering.

float power = 0

Product of port current and bus voltage

float pos_current_limit = 0

Maximum positive current (valid values >= 0.0)

float neg_current_limit = 0

Maximum negative current (valid values <= 0.0)

float pos_energy_Wh = 0

Cumulated energy in positive current direction since last counter reset (Wh)

float neg_energy_Wh = 0

Cumulated energy in negative current direction since last counter reset (Wh)