How to Generate C code of Continuous time blocks?

3 views (last 30 days)
Hey Everyone, I want to know how should i generate C code from models that are utilizing continuous time blocks such as transformers?

Answers (1)

SRance
SRance on 17 Nov 2020
Each Simulink block or MATLAB functions defines whether or not it can be generated to C/C++ code, which can be checked against the general list of MATLAB supported functions for code generation or with each block, listed at the bottom of the help page for that function of block. I.e. even if you wrote a MATLAB function for Simulink, it doens't neccessarily mean the function can be converted to C code.
For C code it is good to avoid continuous states as much as possible so that you can control the discrete time steps of your model when it is deployed to hardware, else you are likely to run into overflow quite quickly.
Use the Debug tab in Simulink to check the discrete and continous parts of your model, noting that for most continuous blocks there is a discrete alternative.
Once your are happy with you model, simply set-up your model to generate code for your specific hardware, noting you will need the Embedded or Simulink coder, or relevant support package for Arduino or Raspberry Pi.

Community Treasure Hunt

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

Start Hunting!