BMS application

Battery Management System (BMS) common defines and structs.

Defines

BMS_SWITCH_CHG
BMS_SWITCH_DIS
BMS_SWITCH_PDSG
BMS_SWITCH_PCHG
BMS_ERR_CELL_UNDERVOLTAGE

Cell undervoltage flag.

BMS_ERR_CELL_OVERVOLTAGE

Cell overvoltage flag.

BMS_ERR_SHORT_CIRCUIT

Pack short circuit (discharge direction)

BMS_ERR_DIS_OVERCURRENT

Pack overcurrent (discharge direction)

BMS_ERR_CHG_OVERCURRENT

Pack overcurrent (charge direction)

BMS_ERR_OPEN_WIRE

Cell open wire.

BMS_ERR_DIS_UNDERTEMP

Temperature below discharge minimum limit.

BMS_ERR_DIS_OVERTEMP

Temperature above discharge maximum limit.

BMS_ERR_CHG_UNDERTEMP

Temperature below charge maximum limit.

BMS_ERR_CHG_OVERTEMP

Temperature above charge maximum limit.

BMS_ERR_INT_OVERTEMP

Internal temperature above limit (e.g. BMS IC)

BMS_ERR_CELL_FAILURE

Cell failure (too high voltage difference)

BMS_ERR_DIS_OFF

Discharge FET is off even though it should be on.

BMS_ERR_CHG_OFF

Charge FET is off even though it should be on.

BMS_ERR_FET_OVERTEMP

MOSFET temperature above limit.

BMS_ERR_ALL

Battery Management System (BMS) high-level API.

Defines

NUM_OCV_POINTS

Enums

enum bms_state

Possible BMS states

Values:

enumerator BMS_STATE_OFF

Off state (charging and discharging disabled)

enumerator BMS_STATE_CHG

Charging state (discharging disabled)

enumerator BMS_STATE_DIS

Discharging state (charging disabled)

enumerator BMS_STATE_NORMAL

Normal operating mode (both charging and discharging enabled)

enumerator BMS_STATE_SHUTDOWN

BMS starting shutdown sequence.

enum bms_cell_type

Battery cell types

Values:

enumerator CELL_TYPE_LFP

LiFePO4 Li-ion cells (3.3 V nominal)

enumerator CELL_TYPE_NMC

NMC/Graphite Li-ion cells (3.7 V nominal)

enumerator CELL_TYPE_LTO

NMC/Titanate (2.4 V nominal)

Functions

void bms_init_config(struct bms_context *bms, enum bms_cell_type type, float capacity_Ah)

Initialization of struct bms_ic_conf with typical default values for the given cell type.

Parameters:
  • bms – Pointer to BMS object.

  • type – One of enum CellType (defined as int so that it can be set via Kconfig).

  • capacity_Ah – Nominal capacity of the battery pack.

void bms_state_machine(struct bms_context *bms)

Main BMS state machine

Parameters:
  • bms – Pointer to BMS object.

void bms_shutdown(struct bms_context *bms)

Switch off MOSFETs and go into the shutdown state

Parameters:
  • bms – Pointer to BMS object.

void bms_soc_update(struct bms_context *bms)

Update SOC based on most recent current measurement

Function should be called each time after a new current measurement was obtained.

Parameters:
  • bms – Pointer to BMS object.

void bms_soc_reset(struct bms_context *bms, int percent)

Reset SOC to specified value or calculate based on average cell open circuit voltage

Parameters:
  • bms – Pointer to BMS object.

  • percent – 0-100 %, -1 for calculation based on OCV

bool bms_chg_error(uint32_t error_flags)

Charging error flags check

Returns:

true if any charging error flag is set

bool bms_dis_error(uint32_t error_flags)

Discharging error flags check

Returns:

true if any discharging error flag is set

bool bms_chg_allowed(struct bms_context *bms)

Check if charging is allowed

Returns:

true if no charging error flags are set

bool bms_dis_allowed(struct bms_context *bms)

Check if discharging is allowed

Parameters:
  • bms – Pointer to BMS object.

Returns:

true if no discharging error flags are set

struct bms_context
#include <bms.h>

Battery Management System context information

Public Members

enum bms_state state

Current state of the battery

bool chg_enable

Manual enable/disable setting for charging

bool dis_enable

Manual enable/disable setting for discharging

bool full

CV charging to cell_chg_voltage_limit finished

bool empty

Battery is discharged below cell_dis_voltage_limit

float soc

Calculated State of Charge (%)

float nominal_capacity_Ah

Nominal capacity of battery pack (Ah)

float *ocv_points

Pointer to an array containing the Open Circuit Voltage of the cell vs. SOC. The array must be spaced the same as the soc_points.

float *soc_points

Pointer to an array containing the State of Charge points for the OCV.

const struct device *ic_dev

BMS IC device pointer

struct bms_ic_conf ic_conf

BMS IC configuration applied during start-up.

struct bms_ic_data ic_data

BMS IC data read from the device.