Simulink Automatic Code Generation for Motor Control: Optimization of Model Simulation Speed

Table of contents

 Method one Simulationmode

 Method 2 Multi-core Parallel

 Method 3Performance Advisor

 Summarize


Method one Simulationmode

Execute the following command to obtain the real-time Simulink simulation. Here, the Hall FOC model is taken as an example. When the switching mode is Accelerator, the form of calling the sub-model cannot be used, and the sub-model needs to be copied to the main model to run directly.

The simulation mode adopts normal

 out=sim('PMSM_FOC_PowerGUI_Model','simulationmode','normal'); %以normal模式运行仿真

 out.SimulationMetadata.TimingInfo;%获取仿真时长

You can see that the execution time is 31s. 

Emulation mode uses accelerator

 out=sim('PMSM_FOC_PowerGUI_Model','simulationmode','accelerator');

 out.SimulationMetadata.TimingInfo

 

 The execution time only takes about 11s

Simulation mode uses Rapid accelerator

 out=sim('PMSM_FOC_PowerGUI_Model','simulationmode','rapid-accelerator');
 out.SimulationMetadata.TimingInfo

The execution time is about 3s. It can be seen that the speed is already very fast, but in this way, the waveform cannot be seen in the scope, only the waveform can be seen in the data inspector.

 It is faster to call the rapid-accelerator in the command window, but if it is run on the Simulink interface, the speed is not so fast. You can choose the method according to your needs.

 Method 2 Multi-core Parallel

Here I will not specifically introduce how to put the Simulink model module on the computer's multi-core to run in parallel. After a short operation, there is little effect. After checking the information, Simulink automatically calls multi-threading, and the operating system multi-threading automatically calls multi-core. Try it The time did not change for a moment. Moreover, to configure the multi-core parallel computing method, the models of different rates need to be called by the model, and a lot of adjustments need to be made to the model. As follows, the motor bench model is placed on one core, and the algorithm is on one core. The amount of control given is placed on a core.

By default, Simulink configures all models to run on multiple threads 

 Method 3Performance Advisor

 Use Performance Advisor to analyze inefficient conditions and settings in your model and automatically speed up simulations. Performance Advisor can inspect the model, identify conditions and settings that may slow down the simulation and generate model optimization recommendations.

Enter the following command in the command window to directly get the optimization suggestion options as shown in the figure below:

Check the option you want to check, and then run it, and you will get optimization suggestions and reports.

performanceadvisor('PMSM_FOC_PowerGUI_Model')

 Summarize

I have tried the above methods to optimize the simulation speed, and some methods are not written here.

1. For example, adjust the simulation step size appropriately, but the adjustment step size needs to be within a reasonable range. If the step size is too large, it may cause simulation distortion and poor control efficiency.

2. Select a reasonable simulation model according to the needs. For example, the motor control only considers the control algorithm and does not need to look at the waveform of the switching stage. It is faster to choose the average value inverter instead of the general inverter.

3. Reasonably reduce the simulation time. Sometimes it is not necessary to simulate for a long time. Reducing the simulation time can save a lot of time on the premise that the debugging purpose can be achieved.

This is roughly summed up here, and there will be new discoveries to make supplements later.

Guess you like

Origin blog.csdn.net/weixin_42665184/article/details/130699284