You are on page 1of 51

Developing Battery Management

System using Simulink


Chirag Patel
Application Engineer
MathWorks

© 2015 The MathWorks, Inc.


1
Agenda

▪ What is BMS and what engineers worry about?


▪ Start with single battery cell and build a pack
▪ Design BMS algorithms
▪ Generate code and deploy
▪ Model V&V
▪ Hardware-in-Loop testing
▪ Summary

2
What is BMS?

Software Electronics Battery Pack

Supervisory tasks
SOC estimation
Contactor management
Isolation monitoring
Fault detection and recovery
Thermal Management
Current & Power Limits Block Voltage,
Temperature Measurement
Cell Diagnostic
Cell Balancing 3
Motivation

Collaboration Gap Long Iteration Cycles Safety Critical System

Multi-Domain Modeling Simulations and Code Model V&V and Hardware-In-


Environment Generation Loop Testing

4
Where do we start?

Gain insight into cell behavior and model it

5
Equivalent Circuit Model

Transient
Dynamics
Cn Terminal
C1
Im R0 Resistance
I1 R1 In Rn
Open-Circuit
Voltage Ip
+
V
Em Zp
+ Parasitic
Ep Losses

[Ex Rx Cx] = f(SOC, Temperature…)

6
Battery Cell Blocks in Simscape

▪ Chose block for fidelity and simulation speed


▪ Parameterize as function of SOC &
Temperature
▪ Add thermal and fade effects
▪ Create custom battery blocks using
Simscape language or Simulink

7
Parameter Estimation

R1 Goal:
Model should match real data as closely as possible
R0

Em C1

model (Em,R1,R0,C1) out 


in =

experiment out ☺

8
Parameter Estimation
Before

After

9
Look-up Tables

Repeat parameter estimation for each


Temperature break-point in LUT

Em SOC SOC SOC SOC



(Volts) 1 0.9 0.8 0

5°C

20°C

40°C

11
Start with Simulation
Battery Cell → Large Battery Pack

Pack System

Cell Dynamics

Thermal Model
Demo
12
Evaluate System Behavior

Demo
13
Discharge + Charge

Cell Voltages Temperatures

Pack Current SOC

14
Discharge Only

Cell Voltages Temperatures

Pack Current SOC

15
Charge Only

Cell Voltages Temperatures

Pack Current SOC

16
Evaluate SOC Estimation

Coulomb counting EKF


UKF

true

17
Generate C/C++ Code From BMS Algorithm Models

Demo

18
Did we generate code too early?
Is this ready to ship?

What if there are bugs?

Where are they? How do we find them?


Let’s
Find
Out
19
Why Testing, Verification and Validation

Safety Critical System Functional Safety Certification

20
Typical Development Workflow

Unit test finds some Errors found during


Most errors introduced
errors integration or in field

Requirements Specification
C/C++/HDL

21
Challenge: Errors introduced early but found late

Unit test finds some Errors found during


Most errors introduced
errors integration or in field

Requirements Specification
C/C++/HDL

22
Validate Design via Desktop Simulation

Unit test finds some Errors found during


errors integration or in field

Design
Requirements C/C++/HDL
Model

23
Model-Based Design Workflow

Simulink Models
Model used for
Design
Requirements production code C/C++/HDL
Model
generation
Generated code

Code
Generation
24
Model-Based Design Verification Workflow

Model Verification Code Verification


Discover design errors at design time Gain confidence in the code

Review and
Component static analysis Equivalence
and system testing
testing
Equivalence
checking
Simulink Models
Model used for
Design
Requirements production code C/C++/HDL
Model
generation
Generated code
✓ Faster development ✓ Reduced cost

✓ Less hassle ✓ More Engineering Code


Generation
25
How do we test?

Is it functioning
correctly?

Simulink Models
Model used for
Design
Requirements production code C/C++/HDL
Model
generation
Generated code

26
Systematic Functional Testing with Simulink Test
Test Case Model Sim through SIL, PIL and HIL
Scale with PCT and CI

Inputs Assessments

MAT file (input) MAT file (baseline)

Signal Editor MATLAB Unit Test


Test Harness

Test Sequence Assessments

Excel file (input) Excel file (baseline)

and more! Main Model and more!

27
Create Test Harnesses

28
Systematic Functional Testing with Simulink Test

Use Test Manager to:


• Author, execute, manage test cases
• Review, export, report

29
Manage and Organize TestCases

30
How do we know we have enough test?

Does the Is it functioning Is it


design meet all correctly? completely
requirements? tested?

Simulink Models
Model used for
Design
Requirements production code C/C++/HDL
Model
generation
Generated code

31
How do we know we have enough test?

Does the Is it functioning Is it


design meet all correctly? completely
requirements? tested?

Simulink Models
Model used for
Design
Requirements production code C/C++/HDL
Model
generation
Generated code

32
Integrate with requirements tools and author requirements

External
Requirements Simulink Requirements • Import from:
• Word / Excel
External Requirements • IBM® Rational® DOORS®
Import • ReqIF™ standard

• Update synchronizes
Update
changes from source

• Edit and add further details to


import
Authored Requirements
• Author requirements

Requirements • Export ReqIF


Managements • Enables roundtrip with
Export external tools
Tools

33
Import External Requirements & Author New Requirements

34
SW Requirements - Implementation Status

35
Track Implementation and Verification

Implementation Status Verification Status

Implemented Passed
Failed
Justified
Unexecuted
Missing
Missing
36
Requirements Verification with Simulink
Requirements Simulink / Stateflow

Implemented
By

Verified
By
Test Case

Inputs Assessments
Test Harness

Signal Editor
MAT / Excel Test
MAT / Excel File (baseline) Assessments
file (input)

Simulink Test
Test Sequence
MATLAB Unit Test
37
Link Tests to Requirements

38
How do we know we have enough test?

Does the Is it functioning Is it


design meet all correctly? completely
requirements? tested?

Simulink Models
Model used for
Executable
Requirements production code C/C++/HDL
Specification
generation
Generated code

40
Coverage Analysis to Measure Testing

Simulink
• Identify testing gaps

• Missing requirements
Stateflow
• Unintended Functionality
Generated Code

• Design Errors

Coverage Reports

41
Measure Model Coverage

42
Addressing Missing Coverage

Partial Coverage

Test Cases from


Functional Requirements

Test
Generator

Simulink Design Verifier

43
Addressing Missing Coverage

Full Coverage
New Test Cases

Test Cases

44
Automatic Test Generation

45
Systematic Simulation Testing

Does the Is it functioning Is it


design meet all correctly? completely
requirements? tested?

Simulink Models
Model used for
Design
Requirements production code C/C++/HDL
Model
generation
Generated code

46
Real-Time Testing of Battery Management System

Testing BMS with Battery Cells


– Longer test cycles
– Difficult to reproduce results
– Difficult to test fault conditions
– Limited test automation

Measurement &
Battery Pack Main Controller47
Diagnostics
Hardware-In-Loop Testing of Battery Management System

Testing BMS with Emulated Battery Cells


– Reduce testing time
– Test fault conditions safely
– Automate testing

Automatic
Code Generation

Wiring and Signal Conditioning


Measurement &
Battery Emulation Diagnostics Main Controller
48
Challenges in setting up HIL testing for BMS

Execute Large Battery Models in Real-time


– Cell Voltages: ~100Hz
– Current: ~1kHz (Accurate Coulomb Counting & current derating
calculations)
– Cell / Pack Temperatures: ~1 to 10Hz (Large time constant for
thermal system)

Sensor and Fault Emulation


– Produce Isolated Voltages
– Sink and Source Current
– Support Series and Parallel Configuration
– Temperature simulation

49
Execute Large Battery Models in Real-time

Prepare Model for Real-time Simulation (if using Webinar on “Real-Time Simulation of
Simscape) Physical Systems Using Simscape”
– Use Simscape Local Solver
– Configure fixed-cost simulations
– Try “Partitioning” option for non-linear systems*

Reducing model complexity


– Select right variant of battery block to match 2-3x
desired model fidelity

5x

5x
– Reduce order of charge dynamics by
selecting fewer number of time-constants
2-3x

50
Sensor and Fault Emulation

Battery Emulation (IO991-06)


– 6 independent isolated channels
– Architecture allows series and parallel stack combinations
– Voltage range of 0-7 V with 14-bit resolution
– Source 300mA and sink 100 mA

Temperature Sensor Emulation


– RTD (PT100, PT1000) – low resolution 6 channel module
– Thermocouple – accurate 32 channels
– High precision resistor simulation modules

Fault Insertion
– 1A to 40A current handling; Up to 4 fault buses
– Electromechanical or MOSFET switches

51
Conclusion

Leverage models to Test your design iterations Gain confidence in design


communicate technical every step of the way and work towards safety
specifications, design through simulations and certification
implementation, results Hardware-In-Loop testing
and maintain traceability

52
Learn More about Battery Management System

Download Link to
File Exchange

For more info:


Chirag Patel
cpatel@mathworks.com

THANK YOU

53

You might also like