How to setup a Simscape solution to deploy on a microcontroller running periodic loops

1 Ansicht (letzte 30 Tage)
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 Kommentar
Yifeng Tang
Yifeng Tang am 11 Jun. 2024
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?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Samay Sagar
Samay Sagar am 19 Aug. 2024
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!

Kategorien

Mehr zu Troubleshooting finden Sie in Help Center und File Exchange

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by