Battery Management System
This example models different aspects of a battery management system (BMS), and leverages Stateflow® capabilities to implement system controls. Specifically, Stateflow controls battery safety, implements fault detection, controls the state of a battery, and balances the cells in a battery.
The model includes two main subsystems: BMS Algorithms
and Plant Model
. The BMS Algorithms
subsystem contains the Power System Control area for managing contactors and detecting faults, and the Battery Management area to ensure that the battery uses and charges power safely. Both of these areas rely heavily on Stateflow to function effectively. The Plant Model
subsystem simulates the physical aspects of the battery, including charging, discharging, and precharge circuits to manage current flow safely. The Signal Editor block includes three different scenarios for this system: Discharging, Charging, and Standby.
Managing Battery Safety, Efficiency, and Performance
The BMS Algorithms
subsystem is crucial for managing the safety, efficiency, and performance of the battery.
This subsystem houses two areas that work together to monitor and control various aspects of the battery system, Power System Control and Battery Management System.
Battery Integration
The Power Control System area represents an electronic control unit (ECU) that integrates the battery with its outer environment, such as an automotive engine. Inside this area are two Stateflow charts: Contactor_Management
and FaultDetection
.
The Contactor_Management
chart manages the opening and closing of contactors to ensure safe operation. Within this chart there are two parallel states: ChargerContactState
and InverterContactState
that control charging and discharging, respectively.
When the chart first becomes active, it starts in the two parallel fail-safe states: OpenChargerContacts
and OpenInverterContacts
. Both parellel states have a similar child state layout. When there is a charge or discharge request, the controller checks that there are no faults before transitioning to the CloseChargerContacts
or CloseInverterContacts
states. Before closing the charger or inverter contacts, the controller closes the pre-charge circuit, which uses a capacitor to ensure equal voltage between the battery and the load. Finally, the controller throws a fault if the voltages are not equal within a certain time.
By using Stateflow to create this control system, you can ensure that the battery safely enters its charging and discharging states.
Detect Faults in the Battery
The FaultDetection
chart detects and categorizes faults, including contactor faults, temperature faults, voltage faults, and sensor faults. Within this chart there are four parallel states: MonitorContacts
, OvercurrentDetection
, MonitorCellTemperature
, and MonitorCellVoltage
. Each state monitors a different aspect of the battery, and within each parallel state there is a linked atomic subchart to monitor specific faults. Some faults require maturation before triggering, and sensor faults compare measured pack voltage with the sum of cell voltages to ensure accurate detection.
For example, the ContactFaultMonitoring
state monitors the faults in the battery contacts. The system defaults to the NoFault
state. However, if a fault is detected for a length of time greater than QualTime
, Stateflow transitions to one of the two fault states, Fault1
or Fault2
. Once in the fault state, the chart checks if the fault is critical or not. If the fault is critical, the Critical
state becomes active and Stateflow sets CriticalFault
to true
. If not, then the NotCritical
state becomes active. When Stateflow detects a fault, the output for the parallel state MonitorContacts
becomes true
.
The Current Power Limits Calculation
subsystem calculates safe operational limits based on cell voltages and temperatures. The subsystem also ensures no single cell is in overvoltage or undervoltage and determines current limits based on the weakest cell. The process utilizes supplier-provided tables for maximum current based on voltage and temperature.
Manage Battery Operations
The Battery Management System area represents an ECU that manages the states of operation for the battery. This area also contains two Stateflow charts: Battery Control
and Cell Balancing
. The SOC Estimation
subsystem estimates the state of charge (SOC) for the battery.
The Battery Control
chart manages the initial state and transitions of the BMS.
When the Battery Control
chart becomes active, it starts in the Standby
state. Initially, the chart checks for any critical faults. If a fault is detected, Fault
becomes the active state, and BMS_State
is set to BMS_State_Enum.BMS_Fault
. If a fault is not detected, Stateflow then checks to see if there is a request for first for discharging, and then for charging. If either request exists, then Stateflow transitions to the corresponding state.
The Cell Balancing
state ensures that there is even voltage distribution across cells to maintain battery health. This state also calculates the difference between the highest and lowest cell voltages and generates a command vector for the desired voltage differences. In this chart, the BalancingOFF
state is first active. When the conditions for balancing are all true
, the chart transitions to the BalancingON
state. As the default child state, BalActive
becomes active.
When the value of BalancingCompleteFlag
becomes true
, the BalNotActive
state becomes active. The BalNotActive
state uses an exit port to return to the BalancingOFF
state.
The SOC Estimation
subsystem estimates the State of Charge (SOC) using coulomb counting, integrating current over time to provide an accurate estimation of the charge state of the battery. During discharging, it integrates current over time to estimate the charge state.
Simulate Battery Behavior
The Plant Model
subsytem simulates the physical aspects of the battery system, providing a realistic representation of the battery behavior under various conditions.
This subsystem includes several key components:
Charger and Load:
This subsystem simulates the current demands placed on the battery, whether for charging or discharging. It helps in understanding how the battery responds to different charging rates and load conditions.Battery Pack
: The battery is modeled after an RC equivalent circuit to estimate the voltage and current, It uses lumped thermal capacity model to estimate the temperature change during charge or discharge. These models help simulate the dynamic behavior of the battery, including voltage changes and internal resistance.Pre Charge Circui
t: This critical subsystem prevents a massive rush of current when connecting the battery to a load or charger. It uses a large resistor to gradually equalize the voltage, ensuring a safe connection. The precharge circuit includes an enabled subsystem with an integrator that holds its value, charging a capacitor when the circuit is opened. The resistor charges until its voltage matches the battery's voltage, at which point the full circuit connects, preventing potential damage from high inrush currents.
Overall, the Plant Model subsystem provides a dynamic simulation of the physical properties of the battery system, enabling accurate testing and validation of the BMS algorithms and ensuring safe and efficient battery operation.
Results
When you simulate this model, the system goes through three different scenarios that are defined in the Signal Editor block: Discharging, Charging, and Standby.
The pack current, pack voltage, and cell temperature are all visibly affected by the change in scenario.
Additionally, you can see where the PackOverCurrentFault was detected.