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!