File Exchange

image thumbnail

Design and Test Lithium Ion Battery Management Algorithms

version 1.0.6 (18 MB) by Chirag
This example project can be used as a reference design to get started with designing Battery Management System with MATLAB and Simulink.

380 Downloads

Updated 15 Jan 2021

View Version History

View License

This example project can be used as a reference design to get started with designing Lithium Ion Battery Management System (BMS) with MATLAB and Simulink.

Project includes Simulink models for BMS Algorithms such as:

1. State of Charge estimation using Extended Kalman Filter, Unscented Kalman Filter
2. Passive Battery Cell Balancing
3. State Machine for Pre-charging and Contactor Management
4. Fault Management - Over/Under Voltage, Over Current, Over Temperature etc.
5. Charge and Discharge Current Limit Calculations

To design and test these algorithms, project also includes files for
1. Li-ion Battery Cell Parameter Estimation
2. Battery Pack with 6 cells in series and 96 cells in series
3. Simulink Test files with test cases to test State Machine Logic
4. Linking requirements to Models

Cite As

Chirag (2021). Design and Test Lithium Ion Battery Management Algorithms (https://www.mathworks.com/matlabcentral/fileexchange/72865-design-and-test-lithium-ion-battery-management-algorithms), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (59)

ayushi

Hi Chirag! Thank you so much for helping with BMS modelling. Actually I am trying to run it on R2020a but when I run, I am getting following error. Can you please guide me on how to resolve this error. It is really important for me to run this module for my project submission. TIA.
Error:-
cannot open output file "C:\Users\jaina\Dropbox\MYPC(L~1\DOWNLO~1\BMS_SA~1\R2020A\work\Battery_Model_msf.mexw64":
Component:Simulink | Category:Model error
Error while bringing model references of model BMS_ClosedLoop up to date: see errors reported above for details.
Component:Simulink | Category:Model error

UTHARA BALRAJ

@aakash borse The three line show SoC values calculated from three different methods - coulomb counting, EKF and UKF. EKF gives the better value. Refer to this - https://www.youtube.com/watch?v=5L2ki33tkpg

Shubham Raut

When we run the simulation in final stage i.e Design and test BMS Algorithm then there are six output graphs, but i have doubt regarding SOC graph, why there is 3 lines to represent SoC? What they indicate? Thanks in advance!

RKS

Hi Chirag,
Thanks for providing this excellent example on BMS. I need one information. Could you please share the detail requirements on the
1. Main State Machine
2. Current Power Limits Calculation
Because in your provided Requirement Word Document, only very high level requirements are mentioned.

Thanks for your support !!

Regards,
Rajesh

Alaa Selim

Hello Chirag, I have a problem with editing the block parameters of SOCInit and I am getting this error message
" Unable to update models referenced by 'BMS_ClosedLoop'.
Caused by:
Error evaluating parameter 'rep_seq_t' in 'Battery_Model/Charger_Load/DriveLoad/BattCurrent From DriveCycle'
Unable to resolve the name BattCrnt.Time"

Error evaluating parameter 'stateOfCharge' in 'Battery_Model/Battery_Pack/Battery_Pack_16Modules/Cell_Module_16/Battery_Cell1'
Reference to non-existent field 'SOCInit'.

Thanks

Harun KACIR

Can you guys update this for 2020b?

li shizhuang

Abdul Kalam.A

how to open this files??

Chirag

Hi Aakash, You can change values of Cell Parameters in battery block through data dictionary. In Data Dictionary file, there is a structure named "battery" which contains all cell parameters and lookup tables. Please let me know if you have any other questions. -Chirag

Shubham Raut

Hey Chirag, can we change the value of the cell parameters like Cell_Voltage, Cell_Current, Cell_Temperature. if yes, then how can i edit? Thanks in advance.

Chirag

Dear Habeeb and Shehan, the below error is related to building documentation search data base function as a result of compatibility issue in R2020a. I will upload a new file for R2020a.

But for now, you can comment out line 9 in setup_project.m file and rest should work.

Thanks for trying this out.
Chirag

Habeeb Valappil

I also got the same warning message as @Shehan Gunathilake.
I'm also using R2020a version.
@Chirag, please advise
--------------------------------------------
Warning: Error using builddocsearchdb (line 32)
There is no installed product with this help location.
Documentation that is not associated with a product will not be displayed in the help browser.

Error in setup_project (line 9)
builddocsearchdb(fullfile(proj.RootFolder,'Doc','HTML'))

Error in matlab.internal.project.util.runMATLABCodeInBase

Error in matlab.internal.project.util.runMATLABCodeInBase

Error in matlab.internal.project.util.runMATLABCodeInBase

Error in matlab.internal.project.util.runMATLABCodeInBase

Error in matlab.internal.project.util.runMATLABScriptDuringStartup

Error in slproject.loadProject

Error in slproject.loadProject

Error in simulinkproject

Error in simulinkproject

Error in SLStudio.Utils.openModelWithProjectCheck (line 97)
simulinkproject(projectMapper.ProjectRoot);

Error in openmdl (line 17)
evalin('base', cmd);

Error in openslx (line 9)
out = openmdl(filename);

Error in open (line 142)
feval(openAction,fullpath);

Error in uiopen (line 159)
open(fn);
> In matlab.internal.project.util.runMATLABScriptDuringStartup
In slproject.loadProject
In slproject.loadProject
In simulinkproject
In simulinkproject
In SLStudio.Utils.openModelWithProjectCheck (line 97)
In openmdl (line 17)
In openslx (line 9)
In open (line 142)
In uiopen (line 159)
Warning: Unable to locate Requirement Set ../../../Requirements/untitled.slreqx (referrer
State_Machine.slx).
>>

Shehan Gunathilake

Warning: Error using builddocsearchdb (line 32)
There is no installed product with this help location.
Documentation that is not associated with a product will not be displayed in the help browser.

Error in setup_project (line 9)
builddocsearchdb(fullfile(proj.RootFolder,'Doc','HTML'))

Error in matlab.internal.project.util.runMATLABCodeInBase

Error in matlab.internal.project.util.runMATLABCodeInBase

Error in matlab.internal.project.util.runMATLABCodeInBase

Error in matlab.internal.project.util.runMATLABCodeInBase

Error in matlab.internal.project.util.runMATLABScriptDuringStartup

Error in matlab.project.loadProject

Error in matlab.project.loadProject

Error in matlab.internal.project.util.PathUtils.loadProjectForOpenPRJ

Error in openprj>i_openMATLABProject (line 88)
valid = matlab.internal.project.util.PathUtils.loadProjectForOpenPRJ(filename);

Error in openprj (line 37)
valid = i_openMATLABProject(filename);

Error in open (line 142)
feval(openAction,fullpath);

Error in uiopen (line 159)
open(fn);
> In matlab.internal.project.util.runMATLABScriptDuringStartup
In matlab.project.loadProject
In matlab.project.loadProject
In matlab.internal.project.util/PathUtils/loadProjectForOpenPRJ
In openprj>i_openMATLABProject (line 88)
In openprj (line 37)
In open (line 142)
In uiopen (line 159)
>>

@Chirag
Sir I'm getting this error. I'm using R2020a version

Guoliang Zhang

Chirag, thanks for the work putting this together.. question: can you list all the toolboxes necessary to run this demo? thanks

Ivan Ukhov

Hi! Please explain how the BMS must work between two currents: continuous and 30 sec peak current (which both are declared by battery manufacturer). How BMS switches between these values? And how I can make logics of this switch? How to set rest between pulses of peak current (whats this rest value?)

Thanks a lot and best regards, Ivan.
(ivan-uhov@mail.ru)

Sergey Senkevich

Junyu Jiang

feng feng

Hi Chirag,

So excellent model! while, my Matlab version is old 2018, could you kindly share a low version file?
Also, I see it is very "hot" and so many guys have different questions, so there may have some small hidden bugs, could you fix them as well?
Many thanks in advance!

Swapnil Kanvinde

Warning: Error using builddocsearchdb (line 32)
There is no installed product with this help location.
Documentation that is not associated with a product will not be displayed in the help browser.

Error in setup_project (line 9)
builddocsearchdb(fullfile(proj.RootFolder,'Doc','HTML'))

Error in matlab.internal.project.util.runMATLABCodeInBase

Error in matlab.internal.project.util.runMATLABCodeInBase

Error in matlab.internal.project.util.runMATLABCodeInBase

Error in matlab.internal.project.util.runMATLABCodeInBase

Error in matlab.internal.project.util.runMATLABScriptDuringStartup

Error in matlab.project.loadProject

Error in matlab.project.loadProject

Error in matlab.internal.project.util.PathUtils.loadProjectForOpenPRJ

Error in openprj>i_openMATLABProject (line 88)
valid = matlab.internal.project.util.PathUtils.loadProjectForOpenPRJ(filename);

Error in openprj (line 37)
valid = i_openMATLABProject(filename);

Error in open (line 142)
feval(openAction,fullpath);

Error in uiopen (line 159)
open(fn);
> In matlab.internal.project.util.runMATLABScriptDuringStartup
In matlab.project.loadProject
In matlab.project.loadProject
In matlab.internal.project.util/PathUtils/loadProjectForOpenPRJ
In openprj>i_openMATLABProject (line 88)
In openprj (line 37)
In open (line 142)
In uiopen (line 159)
>>

These are the errors when trying to open the project in Matlab R2020a. Let me know whether i am doing something wrong or a solution is being worked on or needs to be worked on

AHMED FAKHRI

There are too many errors when openning the project, can you please explain the procesdure to open it? there are too many files to be loaded

puneeth mv

Ivan Ukhov

puneeth mv

Hello Sir can please help me out to solve "Build procedure for Battery_Model aborted due to an error"

XINHUI XIA

How to solve "The function'Balancing_Logic_sfun' corresponding to the input parameter of type'int16' is not defined."

XINHUI XIA

Hello, I encountered many errors in the automatic code generation. How did you solve it?

jien bruce

Hello, Sir. May I ask which part of the program should be clicked in the interface of the last simulation result in the video? I haven't found it yet.Please give me some guidance. Thank you

jien bruce

Chirag

@tain qi: Thank you so much. If you are not comfortable asking questions here, please feel free to contact support@mathworks.com

tian qi

You have done an excellent job. I feel happy for you. I also have a lot of confusion, can I get your guidance?

kavuri poornesh

@chirag thanks for the support, its working fine now :)

Chirag

@Kavuri, what is your final embedded target processor? For code generation, you need to change your System Target File to "ert.tlc" and then select right toolchain.

Make sure you have installed required tools for selected toolchain. If you are generating code for:

Texas Instruments: Make sure you have installed supported version of Code Composer Studio (C2000). and Target Support Package for C2000.

ARM Processor: Make sure you select "GNU Tools for ARM Embedded Processors" and have all the tools installed.

kavuri poornesh

@Chirag, iam getting error while generating the code. But i installed the ARM toolbox but still getting the same error

Den Dmi'"btest555

'"><b>test</b>

Jerry Gu

Hi @Chirag, thank you for developing this model. Currently, the model cannot find the variable 'BattCrnt,' claiming that it does not exist. Do you have any tips on what I can do to fix this?

Chirag

@Kavuri, Are you getting this error while simulation this model or generating c code? If you are getting this error while simulating, please change code generation setting, System Target File to "grt.tlc". >>set_param('modelname','SystemTargetFile','grt.tlc')

kavuri poornesh

Iam getting this error even after adding ARM toolbox
"The selected toolchain ('TI ARM Code Generation Tools | gmake') is not registered. It must be in the Toolchain registry in order to be valid. Check if this toolchain is supported".

Chirag

@SIVA, thanks for the question. Yes, SOC Algorithm (as implemented in the example) only calculates soc for single cell. To perform this calculation for each cell, this becomes expensive in microcontrollers. Do you want to estimate SOC using EKF/UKF for each cell? How many cells do you have in your applications? For smaller pack size, this can be done.

SIVA

@Chirag The model has 96 cells, for SoC computation, the EKF/UKF model has considered only the first cell voltage (via indexing). Does this mean that the model is computing SoC only for the first cell? Else is there any internal index incrementing code which can lead to computation of Individual SoC for all cells.

Raman Nain

Chirag

Hi Kavuri, the download files are packaged as Simulink Project. For future releases, I can package the project as Toolbox if preferred.

kavuri poornesh

iam not able add this model to my add-on tool box

Ian Alferez

Raman Nain

@Chirag, In HIL testing you showed in the video, Does the "FaultPresent" lamp work in real-time(external mode)? I mean to say that does it take the input from the main controller?

apei zou

代码生成的时候谁解决了这个错误啊: The selected toolchain ('TI ARM Code Generation Tools | gmake') is not registered. It must be in the Toolchain registry in order to be valid. Check if this toolchain is supported. For a list of supported factory toolchains refer to https://www.mathworks.com/support/compilers.html

Chirag

Hi Apei Zou, what are you trying to debug?

apei zou

@Chirag Is there debug this model's video?

DIKKO ABUBAKAR

Please, if there is somebody out there with R2019b should load this project and export to previous versions and then upload here. I need 2019a version please.

Afsher P A

hello sir

Vivian D'Souza

@Chirag... would be great if you can export the model to a previous version. Thanks.

Prasanna Deshpande

@Rajeev: You will have access to 2019b. Kindly let me know if you have any challenge.

Chirag

Hi Rajeev, Hi Vikram, This project has more than 100 files to cover all aspects of Model Based Design and different steps of designing BMS. Due to number of models involved, it is difficult for me to export each model to previous release and make sure it works. You can always reach out to your MathWorks Account Manager to get trail for latest release if you don't have access to it.

Rajeev G

Hi Chirag, I am encountering the same problem as @Vikram, I have a R2018a version and I am unable to open the .mlproj file, is there a way to open it in earlier versions?

Vikram Jain

@Aldo/Chirag, in this case since I don't have te license for 2019b version how can I use this ? can you post the same files for 2018b version ?

Aldo Caraceto

@Chirag , I have no problem to open the MATLAB project file and extract all the contained files. Thanks for the submission!
@Vikram, remember MATLAB Projects, files with .mlproj extension, were introduced in release R2019a.
See here for more information.
https://www.mathworks.com/help/matlab/release-notes.html

Vikram Jain

I am using 2018b

Chirag

@Vikram, Which MATLAB version are you using? The example is developed in R2019b, most recent.

Vikram Jain

Hi Chirag, I was trying to open this in MATLAB but it doesn't seems to open, it opens as garbage file. Can you help me figure out how to load/open this file in MATLAB ?

Prasanna Deshpande

MATLAB Release Compatibility
Created with R2019b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!