MATLAB Answers

How to choose a solver, Simulation start and stop time for auto-code generation of simulink model??

조회 수: 6(최근 30일)
Hello
Iam doing a SIMULINK model to estimate the State of charge of the battery-pack. I need to generate the autocode to integrate with my real system.
Iam confused with how to choose a solver and how to set start and stop simulation time??
when i run the model i set stop time to 1000 seconds. In Powergui i selected discrete solver with sample time of 50e-6. Will this solver time affects the real-system performance?? Please suggest me how to select solver and sample time to generate the auto-code??

  댓글 수: 0

댓글을 달려면 로그인하십시오.

채택된 답변

Joel Van Sickel
Joel Van Sickel 6 Mar 2020
Hello Dileepa,
if you are generating code for a controller, you should use a model reference. This will allow you to have a simulation where the plant model (power gui model of the battery pack) runs at a smaller time step, in this case 50e-6, while allowing you to generate code for a controller that runs at a slower time step. I would recommend starting here for simulink basics:
Here is a starting link for model references:
If you are targeting a real-time system for the controller, you will need Simulink Coder. If you are targetting an embedded controller, you will need Embedded Coder. On the off chance you are using an FPGA, you will use HLD coder instead.
Your sample time for the controller should be the same rate you want to run your control algorithm at. For a typical battery SOC, this should be slower than 50 e-6, while you should leave your plant model at 50e-6. You can use the rate transition block to control what parts of your model run at different time steps.
Regards,
Joel

추가 답변(1개)

Chirag
Chirag 6 Mar 2020
Hi Dileepa,
This example shows you the concepts Joel Van Sickel talked about. Using Model Referencing, Rate Transition Block etc.
What other electrical components are you simulating in addition to Battery?
Also, what's your final embedded target? We may have example to help you get started.
Sample Time of 50e-6 is very small for Battery Algorithms. You may not want to calculate your SOC at every 50microsecond. You can use Multirate modeling to run your SOC Estimation algorithm at slower rate.
Chirag

Community Treasure Hunt

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

Start Hunting!

Translated by