How to simulate a battery pack with a BMS in Simulink to prevent over-charge / over-discharge?

27 views (last 30 days)
I’m designing a multi-cell lithium (or sodium) battery pack model here and want to integrate a BMS (Battery Management System) module to protect against over-charge, over-discharge, over-current, and temperature extremes (as discussed in this article: “Keep Your Batteries and Your Family Safe With a BMS”)
Here’s what I currently have:
  • A set of individual cell models (with voltage, internal resistance, capacity, temperature dynamics)
  • Charging/discharging loads
  • Temperature dynamics (ambient, heat generation)
What I want to implement via Simulink / Simscape:
  1. A BMS logic block that monitors each cell voltage and cuts off charging when any cell exceeds a threshold (e.g. 4.2V), and blocks discharge when any cell drops below a minimum (e.g. 2.5V)
  2. Over-current protection (if current exceeds safe threshold)
  3. Temperature protection (if cell temperature goes beyond safe range)
  4. Cell balancing (active or passive) to keep cell voltages ~equal
Questions:
  • What is best practice for structuring such a BMS logic in Simulink / Simscape? Should the BMS be implemented as a Stateflow chart, or pure Simulink logic blocks, or via Simscape electrical components?
  • How can I simulate cell balancing (both passive and active) realistically? Are there built-in blocks or examples that show how to “shunt” current or redistribute charge across cells?
  • How to integrate thermal coupling between cells and BMS temperature sensing in simulation?
  • Are there example models or toolboxes in MATLAB Central or the File Exchange that already implement a BMS for battery packs I can reuse or adapt?
I can share a minimal reproducible Simulink model but wanted to ask first what approach is recommended in the community.

Answers (1)

Umar
Umar on 9 Oct 2025 at 23:34
Edited: Umar on 9 Oct 2025 at 23:35

Hi @Katie,

First of all, I would like to give you a compliment, this is a Great project! Hopefully, you are already aware of Simscape Battery has extensive built-in BMS blocks that will save you significant development time. After going through your posted comments, let me address your questions:

1. Best Practice for Structuring BMS Logic

Recommended: Hybrid approach with Built-in Blocks + Stateflow

Simscape Battery includes dedicated BMS blocks organized into categories: Cell Balancing, Current Management, Estimators, and Protection

Reference: https://www.mathworks.com/help/simscape-battery/bms-block-libraries.html

Implementation Strategy:

  • Protection algorithms: Use built-in blocks (Battery Voltage Monitoring, Battery Current Monitoring, Battery Temperature Monitoring)
  • Supervisory control: Implement Stateflow chart with states (IDLE, CHARGING, DISCHARGING, BALANCING, FAULT)
  • Signal routing: Simulink logic blocks
  • Power electronics: Simscape Electrical components

Why Stateflow? It provides clear visualization of operating modes and state transitions - industry best practice for BMS design. The built-in protection blocks handle complex algorithms with proven reliability.

See the complete workflow example: Model-Based Design to Build a BMS

2. Cell Balancing Implementation (Passive & Active)

Passive Balancing (Start Here)

Use the Passive Cell Balancing block (Simscape/Battery/BMS/Cell Balancing). This block dissipates excess charge through bleed resistors to equalize cell voltages/SOC.

Key features:

  • Input: Cell voltages or SOC values
  • Output: Command vector [0,1,0,1...] controlling switches
  • The block automatically calculates which cells to discharge

Implementation:

Example: Check out the Battery Passive Cell Balancing

example - it shows a 2-cell series pack with initial SOCs of 0.7 and 0.75 being balanced.

Resistor sizing: * Value: 10-50Ω (balance speed vs heat) * Power: P = V^2/R (e.g., 4.2^2/30 ≈ 0.6W → use 2W resistor) * Current: ~50-200mA per cell

Active Balancing (Advanced) Active balancing transfers energy between cells using DC-DC converters (capacitor or inductor-based). More efficient but significantly more complex.

Implementation requires: * Custom DC-DC converter models (buck-boost/flyback topology) * Control logic to determine charge transfer * Simscape Electrical components for power electronics

Recommendation: Start with passive balancing. Only implement active if energy efficiency is critical (e.g., EV applications).

3. Protection Implementation

Simscape Battery provides dedicated protection blocks:

Voltage Protection Block: Battery Voltage Monitoring * Over-voltage: 4.2V (Li-ion NMC/LCO), 3.65V (LFP) * Under-voltage: 2.5V * Outputs fault signals when any cell exceeds limits

Current Protection Block: Battery Current Monitoring * Set based on C-rate (e.g., 1C charge, 3C discharge) * Example: 50Ah battery → 50A charge limit, 150A discharge limit

Temperature Protection Block: Battery Temperature Monitoring * Charge range: 0-45°C (Li-ion) * Discharge range: -20-60°C * Critical thresholds trigger cooling or shutdown

Fault Management Block: Fault Qualification * Filters transient faults (debouncing) * Prevents false alarms * Connect to Stateflow for coordinated response

Integration: Protection Blocks → Fault Signals → Stateflow → Contactor Control Documentation: Battery Protection Blocks

4. Thermal Coupling & Temperature Sensing

Enable Thermal Modeling When creating your battery pack, enable thermal ports:

     cell = batteryCell(...
    'ThermalBoundaryCondition', 'ConvectiveHeatTransfer');

Connect Temperature Sensors Battery blocks have thermal ports that output temperature: 1. Connect thermal sensors (Simscape Foundation) to these ports 2. Feed signals to Battery Temperature Monitoring block 3. Model thermal resistance between cells (air gaps/TIM)

Thermal Management Blocks Simscape Battery includes: * Battery Coolant Control: Activates cooling when temp exceeds threshold * Battery Heater Control: Prevents charging below 0°C (lithium plating risk)

Example setup:

See example: Charge Discharge Module Assembly with Coolant Control

5. Example Models & Resources

Built-in Examples 1. Battery Passive Cell Balancing - 2-cell series balancing demo 2. Use Model-Based Design to Build a BMS - Complete 27Ah NMC BMS 3. Battery Current Temperature Fault Monitoring - Protection integration

Access via: MATLAB Command Window → simscapebatterylib

Battery Pack Model Builder Use these functions to build complex packs (available R2024a+):

% Create 12S4P pack (12 series, 4 parallel)
cell = batteryCell(...);
parAssembly = batteryParallelAssembly('Cell', cell, 'NumParallelCells', 4);
module = batteryModule('ParallelAssembly', parAssembly, 
'NumSeriesAssemblies', 12);
buildBattery(module, 'MyBatteryPack');
Functions: batteryCell, batteryParallelAssembly, batteryModule, batteryPack, 
buildBattery

Full list: Battery Pack Modeling Functions

Here is my recommendation for implementation steps:

Phase 1: Create battery pack with Battery Builder (enable thermal modeling) Phase 2: Add protection blocks (voltage → current → temperature → fault qualification) Phase 3: Implement passive cell balancing Phase 4: Create Stateflow supervisory controller Phase 5: Add thermal management (coolant control) Phase 6: Test fault scenarios

Use built-in blocks - they're validated and optimized

Start simple - test each protection individually Enable thermal modeling - critical for safety Stateflow for supervisory logic - industry standard Don't skip balancing - cell variations grow over time Don't ignore thermal effects - major safety concern

The next steps would be

1. Review "Battery Passive Cell Balancing" example first 2. Start with small pack (2S2P) to validate approach 3. Share your model if you need specific guidance

Key References:

Hope this helps!

Categories

Find more on Energy Storage in Help Center and File Exchange

Products


Release

R2025b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!