5. Important Switches in Code

5.1. System Relevant Switches

In embedded-software\mcu-primary\src\general\config\batterysystem_cfg.h, three important switches are defined.

The switch

#define CURRENT_SENSOR_PRESENT               TRUE

is by default set to TRUE. In this configuration, the SYS statmachine will go into an error state during startup if no current sensor is detected. The switch must be set to FALSE for foxBMS to start without current sensor.

The switch

#define CHECK_CAN_TIMING                     TRUE

is set to TRUE by default. In this configuration, the BMS statemachine will go into an error state if no requests are made periodically per CAN with a period of 100ms. When the switch is set to FALSE, the check is not made.

The switch


is set to TRUE by default. This prevents any balancing. In order for balancing to be possiblem the switch must be set to FALSE.

5.2. Battery Cell Relevant Switches

In embedded-software\mcu-primary\src\general\config\batterycell_cfg.h, the Safe Operating Area for the cells is defined:

  • Upper and lower voltage
  • Upper and lower temperature for charging
  • Upper and lower temperature for discharging
  • Upper current for charging and discharging

The battery cell capacity is also defined with

#define BC_CAPACITY 3500

The unit is mAh.

5.3. Deactivating Cell Tests

In embedded-software\mcu-primary\src\engine\config\diag_cfc.c, the structure

DIAG_CH_CFG_s  diag_ch_cfg[]

allows disabling the checks made by the diag module. Disabling is made by replacing




Important checks are:



Setting the cell limits is safety relevant and must be done with care.


Working without configuring the right battery cell voltage limits is dangerous and should never be done when real batteries are connected, since they may burn and explode when overcharged or shorted.

5.4. Using Current Counter from Current Sensor

Current-counting can now be made using the current sensor. foxBMS will detect automatically if the corresponding data is being sent by the current sensor. If yes, the hardware current-counter from the sensor is used. If not, the software integrator is used.

5.5. Defining the Convention for the Current Direction

Two functions have been defined in embedded-software\mcu-primary\src\general\config\batterycell_cfg.h to test the current direction conveniently.

The first one

BS_CURRENT_DIRECTION_e BS_CheckCurrent_Direction(void);

gets the current from the database and returns BS_CURRENT_DISCHARGE if a discharge current is flowing throug the battery, BS_CURRENT_CHARGE otherwise.

The second one

BS_CURRENT_DIRECTION_e BS_CheckCurrentValue_Direction(void);

functions the same way. The only difference is that is does not get the current value from the database but uses the value passed to the function.

The define POSITIVE_DISCHARGE_CURRENT is used to define the current direction convention:

  • if set to TRUE, discharge currents are positive
  • if set to FALSE, charge currents are positive

This define affect the calculation in the SOX module too.

5.6. Complete List of Switches

A complete list of switches can be found here: