Simcenter Amesim Cosimulation between Simulink & AMESim (AME2SLCosim) using MinGW-w64 (gcc 64 bit) compiler - Example of Battery Management Control

Simcenter Amesim Automation Connect Simcenter System Simulation Client for Git Simcenter Amesim Teamcenter Share



By using this Article & Video, we will learn
  • How to install the MinGW-w64 compiler to use MATLAB?
  • How to use the MinGW-w64 compiler for Co-simulation?
  • How to do Co-simulation between AMESim & Simulink (AME2SLCosim – Simulink as Master)
For more details, please watch the above video till the end

Short description of Demo –

The electrical vehicle is gaining popularity and it is seeing as a technology of the future. Battery pack design is playing very important from the safety and performance point of view. Generally, a separate Battery management control unit is used to manage the performance of the battery. MIL, SIL, HIL, etc method is generally used to verify the algorithm and logic of the Battery management control unit. Simulink is generally used as a graphical language for coding of most of the electronic control units.  In this demo, a simplified BMC for battery cell balancing control algorithm is developed in Simulink; the model of the battery pack is implemented in Simcenter AMESim. By coupling between AMESim and Simulink, one can verify the effectiveness of code in the design stage. AMESim can be coupled with Simulink in several ways. In this demo, we will see “How AMESim can be coupled with Simulink to verify your control unit logic”. AMESim model is giving voltages of various cells as an output. This output is sent to the Simulink model. At every time step Simulink processes this output and give the optimum command to each cell so that cell balancing can be achieved.

Configuration of MinGW64 compiler: -
To configure the MinGW64 compiler in MATLAB, please follow the procedure below:
  • In MATLAB, install the Add-On for the support of MinGW64.
  • Execute a mex -setup command and select the MinGW64 compiler.
  • Make sure an environment variable called MW_MINGW64_LOC has been set on your PC; if not, then create it and set it to the value obtained when executing a getenv('MW_MINGW64_LOC') command under MATLAB.
  • Restart your machine and select the GNU GCC (64-bit) compiler in Simcenter AMESim.
Co-simulation between AMESim & Simulink (AME2SLCosim): -
: -
  • AMESim along with Simulink interface as an add-on to generate the S function.
  • MATLAB Simulink license
After generation of S-function, you do not require an AMESim license, but you will at least require the AMERun license to run the model. Please note that the AMESim model uses AMESim Solver and Simulink Model will use Simulink Solver. Co-simulation always works with a Fixed step solver.

Step to be followed for Co-simulation [Watch Video for More Details]:
We will use S05_CoSim_Amesim_Simulink_Cell_balancing.ame demo to understand this process.  
In this demo, Simulink is Master and AMESim is Slave. You can manage everything from the Simulink interface itself. While simulating, the AMESim model is using AMESim Solver and Simulink Model is using the Simulink solver. This demo is represented by


This demo illustrates a Model-In-the-Loop (MIL) simulation for a battery management system (BMS) by using the co-simulation between Simulink and Simcenter AMESim. The Model-In-the-Loop (MIL) simulation is a tool to validate a closed-loop controller algorithm. It consists of running the control algorithm (e.g., the control algorithm of the BMS) linked to a model of the component to be controlled and its environment (e.g., the model of a battery pack). In this demo, a simplified BMS for the battery cell balancing control algorithm is developed in Simulink; the model of the battery pack is implemented in Simcenter AMESim. With the co-simulation, the performance of the BMS developed in Simulink can be evaluated.

In this demo, Simulink Receives the Voltages at all cells and current, SOC data. The simulink control algorithm process this data and send the command to the AMESim model to control the optimum voltage in order to balance the cell.

To run this demo, follow the below step.
  • Set the compiler to MinGW64. Follow the above step.
  • Open the .ame file.
  • Ensure that, gcc64 compiler is set as your active compiler.
  • Similarly, ensure that, the same compiler is used in MATLAB. (Use mex -setup command to check)
  • Compile the model in AMESim
  • Right-click on the Interface icon and click on the launch interface. It will launch the Simulink with all added pre-requisite paths in MATLAB. (Ensure that MATLAB environmental variable is pointed out to MATLAB installation folder. For more detail, please check the help manual)
  • Open the Simulink Model file. Understand “how the variable is exchanged between this two software”.
  • Click on the Run button to start the co-simulation.
  • You can see the results in AMESim as well as Simulink.
CLICK HERE to download the demo files.

If you are interested to know the other method of cosimulation with Simulink, then please visit below VIDEO articles.

CLICK HERE to know about “Model exchange (AME2SL) between MATLAB Simulink and AMESim with MinGw 64bit compiler
CLICK HERE to know about “Import MATLAB Simulink Model to AMESim (SL2AMECOSIM) using MinGW 64-bit compiler”.
CLICK HERE to know about “Export the AMESim model Blackbox to MATLAB Simulink using GNU MinGW gcc x64 bit compiler.
CLICK HERE to know about “FMU/FMI - Export a cosimulation FMU from the AMESim & Import it in the Simulink
CLICK HERE to know about “FMU/FMI - Export a Model Exchange FMU from the AMESim & import in the Simulink
CLICK HERE to know about “Import MATLAB Simulink FMU to AMESim

If you still need support or clarification, then click here to raise the case on the support portal.

KB Article ID# KB000046148_EN_US



Associated Components

Amesim Automation Connect