├── .gitignore ├── Demo ├── Charge.PNG ├── ChargeFault.PNG ├── Discharge.PNG ├── DischargeFault.PNG └── Idle.PNG ├── LICENSE ├── MiniBMS ├── BMSLib.slx ├── MiniBMS.slx └── MiniBMSVariables.m └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows default autosave extension 2 | *.asv 3 | 4 | # OSX / *nix default autosave extension 5 | *.m~ 6 | 7 | # Compiled MEX binaries (all platforms) 8 | *.mex* 9 | 10 | # Packaged app and toolbox files 11 | *.mlappinstall 12 | *.mltbx 13 | 14 | # Generated helpsearch folders 15 | helpsearch*/ 16 | 17 | # Simulink code generation folders 18 | slprj/ 19 | sccprj/ 20 | 21 | # Matlab code generation folders 22 | codegen/ 23 | 24 | # Simulink autosave extension 25 | *.autosave 26 | 27 | # Simulink cache files 28 | *.slxc 29 | 30 | # Octave session info 31 | octave-workspace 32 | -------------------------------------------------------------------------------- /Demo/Charge.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ks-santosh/MiniBMS/fbda9756f5bc5f09817a3c9a47bc2967ef0c4fb5/Demo/Charge.PNG -------------------------------------------------------------------------------- /Demo/ChargeFault.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ks-santosh/MiniBMS/fbda9756f5bc5f09817a3c9a47bc2967ef0c4fb5/Demo/ChargeFault.PNG -------------------------------------------------------------------------------- /Demo/Discharge.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ks-santosh/MiniBMS/fbda9756f5bc5f09817a3c9a47bc2967ef0c4fb5/Demo/Discharge.PNG -------------------------------------------------------------------------------- /Demo/DischargeFault.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ks-santosh/MiniBMS/fbda9756f5bc5f09817a3c9a47bc2967ef0c4fb5/Demo/DischargeFault.PNG -------------------------------------------------------------------------------- /Demo/Idle.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ks-santosh/MiniBMS/fbda9756f5bc5f09817a3c9a47bc2967ef0c4fb5/Demo/Idle.PNG -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 ks-santosh 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /MiniBMS/BMSLib.slx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ks-santosh/MiniBMS/fbda9756f5bc5f09817a3c9a47bc2967ef0c4fb5/MiniBMS/BMSLib.slx -------------------------------------------------------------------------------- /MiniBMS/MiniBMS.slx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ks-santosh/MiniBMS/fbda9756f5bc5f09817a3c9a47bc2967ef0c4fb5/MiniBMS/MiniBMS.slx -------------------------------------------------------------------------------- /MiniBMS/MiniBMSVariables.m: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % MiniBMS Variables 3 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 4 | %% BATTERY 5 | 6 | % Number of module temperature sensors 7 | NrTMdulSnsr_C = uint8(3); 8 | 9 | % Number of cells 10 | NrCells_C = uint8(3); 11 | 12 | % Battery table data 13 | Em = [2.8 3.228 3.284 3.361 3.408 3.427 3.472 3.477 3.493 3.504 3.516 3.528 3.537 3.545 3.555 3.561 3.566 3.576 3.587 3.589 3.594 3.6 3.608 3.61 3.616 3.619 3.626 3.632 3.637 3.64 3.645 3.646 3.652 3.655 3.658 3.661 3.664 3.668 3.673 3.678 3.68 3.681 3.686 3.692 3.699 3.702 3.705 3.71 3.717 3.723 3.728 3.733 3.735 3.742 3.749 3.755 3.761 3.768 3.773 3.78 3.791 3.798 3.798 3.814 3.818 3.825 3.841 3.846 3.855 3.863 3.877 3.885 3.894 3.907 3.919 3.926 3.935 3.944 3.954 3.964 3.974 3.988 3.998 4.014 4.029 4.034 4.047 4.065 4.074 4.086 4.097 4.131 4.126 4.138 4.15 4.18 4.174 4.187 4.207 4.231 4.221]; 14 | CapLUTBp = [0 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09 0.1 0.11 0.12 0.13 0.14 0.15 0.16 0.17 0.18 0.19 0.2 0.21 0.22 0.23 0.24 0.25 0.26 0.27 0.28 0.29 0.3 0.31 0.32 0.33 0.34 0.35 0.36 0.37 0.38 0.39 0.4 0.41 0.42 0.43 0.44 0.45 0.46 0.47 0.48 0.49 0.5 0.51 0.52 0.53 0.54 0.55 0.56 0.57 0.58 0.59 0.6 0.61 0.62 0.63 0.64 0.65 0.66 0.67 0.68 0.69 0.7 0.71 0.72 0.73 0.74 0.75 0.76 0.77 0.78 0.79 0.8 0.81 0.82 0.83 0.84 0.85 0.86 0.87 0.88 0.89 0.9 0.91 0.92 0.93 0.94 0.95 0.96 0.97 0.98 0.99 1]; 15 | RInt = [0.008846 0.009319 0.009027 0.00847 0.01032 0.01314;0.006389 0.006554 0.005553 0.005525 0.006043 0.007805;0.004364 0.004101 0.00406 0.003452 0.003846 0.004517;0.002031 0.002563 0.002532 0.00246 0.002716 0.003047;0.001443 0.001825 0.001795 0.001778 0.001924 0.002234;0.0005603 0.0007192 0.0006887 0.0007557 0.0007355 0.001014;0.001028 0.001338 0.001 0.001536 0.001546 0.002789]; 16 | BattTempBp = [243.1 253.1 263.1 273.1 283.1 298.1 313.1]*0.1; 17 | CapSOCBp = [0 0.2 0.4 0.6 0.8 1]; 18 | 19 | %% BMS 20 | 21 | % Sample time 22 | BMS_TiSample_C = single(0.1); 23 | 24 | % Fault enable table 25 | BMS_ModeEnaFltChk = [0 100 110 111 115 120 130 140 200 211 220 230 255]; 26 | BMS_EnaFltSts = [1 1 1 1 1 1 1 1 0 0 0 0 0]; 27 | %% CELL VOLTAGE MONITORING 28 | 29 | % Cell under-voltage fault thresholds 30 | CVM_VCellMinCutoffTh_P = single(3.26); 31 | CVM_VCellMinDrtdTh_P = single(3); 32 | CVM_VCellMinWarnTh_P = single(2.8); 33 | 34 | % Cell under-voltage fault debouncer max and min counter values 35 | CVM_DMaxVCellMinCutoff_P = int16(0.5/BMS_TiSample_C); 36 | CVM_DMinVCellMinCutoff_P = -int16(0.5/BMS_TiSample_C); 37 | CVM_DMaxVCellMinDrtd_P = int16(0.5/BMS_TiSample_C); 38 | CVM_DMinVCellMinDrtd_P = -int16(0.5/BMS_TiSample_C); 39 | CVM_DMaxVCellMinWarn_P = int16(0.5/BMS_TiSample_C); 40 | CVM_DMinVCellMinWarn_P = -int16(0.5/BMS_TiSample_C); 41 | 42 | % Cell over-voltage fault thresholds 43 | CVM_VCellMaxCutoffTh_P = single(4.22); 44 | CVM_VCellMaxDrtdTh_P = single(4.15); 45 | CVM_VCellMaxWarnTh_P = single(4.1); 46 | 47 | % Cell over-voltage fault debouncer max and min counter values 48 | CVM_DMaxVCellMaxCutoff_P = int16(0.5/BMS_TiSample_C); 49 | CVM_DMinVCellMaxCutoff_P = -int16(0.5/BMS_TiSample_C); 50 | CVM_DMaxVCellMaxDrtd_P = int16(0.5/BMS_TiSample_C); 51 | CVM_DMinVCellMaxDrtd_P = -int16(0.5/BMS_TiSample_C); 52 | CVM_DMaxVCellMaxWarn_P = int16(0.5/BMS_TiSample_C); 53 | CVM_DMinVCellMaxWarn_P = -int16(0.5/BMS_TiSample_C); 54 | 55 | %% MODULE TEMPERATURE MONITORING 56 | 57 | % Module under-temperature fault thresholds 58 | MTM_TMdulMinCutoffTh_P = single(-20); 59 | MTM_TMdulMinDrtdTh_P = single(0); 60 | MTM_TMdulMinWarnTh_P = single(5); 61 | 62 | % Module under-temperature fault debouncer max and min counter values 63 | MTM_DMaxTMdulMinCutoff_P = int16(0.5/BMS_TiSample_C); 64 | MTM_DMinTMdulMinCutoff_P = -int16(0.5/BMS_TiSample_C); 65 | MTM_DMaxTMdulMinDrtd_P = int16(0.5/BMS_TiSample_C); 66 | MTM_DMinTMdulMinDrtd_P = -int16(0.5/BMS_TiSample_C); 67 | MTM_DMaxTMdulMinWarn_P = int16(0.5/BMS_TiSample_C); 68 | MTM_DMinTMdulMinWarn_P = -int16(0.5/BMS_TiSample_C); 69 | 70 | % Module over-temperature fault thresholds 71 | MTM_TMdulMaxCutoffTh_P = single(55); 72 | MTM_TMdulMaxDrtdTh_P = single(52.5); 73 | MTM_TMdulMaxWarnTh_P = single(50); 74 | 75 | % Module over-temperature fault debouncer max and min counter values 76 | MTM_DMaxTMdulMaxCutoff_P = int16(0.5/BMS_TiSample_C); 77 | MTM_DMinTMdulMaxCutoff_P = -int16(0.5/BMS_TiSample_C); 78 | MTM_DMaxTMdulMaxDrtd_P = int16(0.5/BMS_TiSample_C); 79 | MTM_DMinTMdulMaxDrtd_P = -int16(0.5/BMS_TiSample_C); 80 | MTM_DMaxTMdulMaxWarn_P = int16(0.5/BMS_TiSample_C); 81 | MTM_DMinTMdulMaxWarn_P = -int16(0.5/BMS_TiSample_C); 82 | 83 | %% BATTERY OPERATION MODE 84 | 85 | % Contactor connect and disconnect wait times 86 | BM_TiCtctrCnct_P = single(1)/BMS_TiSample_C; 87 | BM_TiCtctrDCnct_P = single(1)/BMS_TiSample_C; 88 | 89 | %% BATTERY PARAMETER CALCULATION 90 | 91 | % Total charge in battery 92 | BPC_BattTotalCharge_P = single(48); 93 | 94 | % Total energy in battery 95 | BPC_BattTotalEnergy_P = BPC_BattTotalCharge_P * single(NrCells_C) * CVM_VCellMaxCutoffTh_P; 96 | 97 | %% FAULT CODES 98 | 99 | NrCutoff_C = uint8(3); 100 | NrDrtd_C = uint8(2); 101 | NrWarn_C = uint8(1); 102 | NrNoFlt_C = uint8(0); 103 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MiniBMS 2 | 3 | MiniBMS is a Simulink model designed to simulate a simple battery management system (BMS) for electric vehicles. The model incorporates a range of functionalities essential for efficient battery management, ensuring the safety and reliability of electric vehicle operations. 4 | 5 | ## Project Components 6 | | File | Purpose | 7 | | --- | --- | 8 | |MiniBMS.slx|The main model containing the battery and BMS simulation.| 9 | |BMSLib.slx|Library used in MiniBMS.slx.| 10 | |MiniBMSVariables.m|Script containing the definitions of various parameters used in MiniBMS.slx.| 11 | 12 | ## Features 13 | 14 | 1. **State of Charge (SoC) Calculation**: Uses coulomb counting to accurately determine the battery's state of charge. 15 | 2. **Battery Capacity and Energy Calculation**: Computes the total capacity and energy available in the battery pack. 16 | 3. **Fault Detection**: Identifies faults in the system, including temperature, voltage, and contactor issues. 17 | 4. **Voltage Monitoring**: Continuously tracks the voltage levels of the battery cells. 18 | 5. **Temperature Monitoring**: Monitors the temperature of the battery cells to prevent overheating and ensure optimal performance. 19 | 6. **BMS State Management**: Manages the various states of the BMS, ensuring proper operation and response to different conditions. 20 | 7. **Contactor Control**: Controls the contactors to manage the connection and disconnection of the battery pack. 21 | 22 | ## Model Specifications 23 | 24 | - **Battery Configuration**: The BMS is designed for a battery pack consisting of 3 Li-Ion cells connected in series. 25 | - **Battery Modelling**: Utilizes tables of open circuit voltage (OCV) vs. SoC data and internal resistance vs. temperature data to simulate the battery behavior. 26 | 27 | ## Usage 28 | 29 | To use MiniBMS, add the BMSLib.slx library to your MATLAB path and load the MiniBMS.slx model. The MiniBMSVariables.m script provides necessary parameter definitions and should be run before starting the simulation. The model was developed in MATLAB version R2018b and thus may not work in earlier versions. 30 | 31 | ## User Interaction 32 | 33 | - **Ignition and Charger Control**: Users can turn on the ignition or connect the charger using interactive switches during the simulation run. 34 | - **Current and Temperature Control**: Users can adjust the current and temperature settings using sliders, which influence the simulated battery voltage monitored by the BMS. 35 | 36 | ## Demo 37 | 38 | ### Idle Mode 39 | 40 | The BMS starts in IDLE mode. 41 | 42 | ![Idle](/Demo/Idle.PNG) 43 | 44 | ### Discharge Mode 45 | 46 | If the ignition is switched on and there are no faults, the BMS transitions to DISCHARGE mode. 47 | 48 | ![Discharge](/Demo/Discharge.PNG) 49 | 50 | ### Fault During Discharge 51 | 52 | If a fault occurs during discharge, the BMS reverts to IDLE mode. It won't restart until the fault is resolved and the ignition is switched off and then on. 53 | During discharge if there is a fault the BMS falls back to IDLE mode and won't restart until the fault is healed and the ignition is switched off and then on. 54 | 55 | ![Fault in discharge](/Demo/DischargeFault.PNG) 56 | 57 | ### Charge Mode 58 | When the charge plug is connected, the BMS transitions to CHARGE mode, even if the ignition is on. Ensure the current value is set to negative; otherwise, the battery will discharge. 59 | ![Charge](/Demo/Charge.PNG) 60 | 61 | ### Fault During Charge 62 | If a fault occurs during charging, the BMS stops operation. It will only resume if the fault is resolved and the plug is reconnected. 63 | 64 | ![Fault in charge](/Demo/ChargeFault.PNG) 65 | --------------------------------------------------------------------------------