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 个)

Samay Sagar
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:
  1. 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!

类别

Help CenterFile Exchange 中查找有关 Troubleshooting 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by