How to setup a Simscape solution to deploy on a microcontroller running periodic loops
28 次查看(过去 30 天)
显示 更早的评论
Would like to implement a simple thermal model on a target microcontroller. Simulink is setup to exectute various loops based on function calls at periodic rates. Is there a way to embed a Simscape model inside a 20ms function call? Can't seem to find a way to set the sample time to inherited in the solver configuration without error. Using Matlab 2021b.
1 个评论
Yifeng Tang
2024-6-11
Are you trying to execute a Simulink model (start to finish) every 20ms or to have the model/simulation advance one time step of 20ms?
回答(1 个)
Samay Sagar
2024-8-19,8:19
Hi Steven,
I understand that you are trying to embed a Simscape model within a specific function call at a periodic rate on a target microcontroller. This can be challenging due to the continuous nature of Simscape simulations. However, you can follow these steps to achieve your goal:
- Discretize the Simscape Model:
- Simscape models are inherently continuous and need to be discretized to run at fixed time steps. Use the “Simulink-PS Converter” and “PS-Simulink Converter” blocks to interface between Simulink and Simscape components.
- Set the “Solver Configuration”block to use a fixed-step solver. You cannot set the sample time to "inherited," but you can choose a fixed-step solver and specify the sample time.
2. Configure the Solver
- Open the Solver Configuration block and set the solver type to "Fixed-step."
- Choose an appropriate fixed-step solver, such as "ode3" or "ode4," which are suitable for real-time applications
3. Function-Call Subsystem
- Use a “Function-Call Subsystem” to encapsulate your Simscape model. This allows you to trigger the subsystem at specific intervals
- Use a “Function-Call Generator” block to generate function calls at the desired rate (20ms).
Ensure that the model is compatible for code generation by checking any unsupported blocks or configurations. Simulate the model to verify that it behaves correctly and deploy the code to your target microcontroller.
For more information about “Function-Call Subsystem”, you can refer the following documentation:
Hope this helps!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Troubleshooting 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!