- Open Simulink model
- Open Configuration Parameter window, go to Code Generation
- System target file: ert.tlc (Embedded Coder)
- Language: C
- In Simulink APPS menu, click on Embedded Coder, A C CODE tabs appears to the right of APPS menu
- Find the signal line you want the generate code for and double click on it, give it a name, e.g. "mySignal"
- Single click on signal line, a pop up will appear, click on the left-most item, "Add selected signals to code mappings"
- Under C CODE tab, click on Code Interface and then click Default Code Mappings
- A Code Mappings panel will appear at the bottom of model
- Click on right most tab, Signals/States
- Under Signals, find mySignal
- Click to the right of mySignal (Store Class column), change Auto to Model Default.
- Generate code by pressing ctrl + b
- If your model name was MyModel, the generated code will have a file called MyModel_ert_rtw/MyModel.h containing the data structure MyModel_B which has mySignal as a field that you can access from your own C/C++ code.
- If your code is C++, dont forget to use include in C wrapper: extern "C" {#include "MyModel_ert_rtw/MyModel.h"}
C++ and MATLAB Simulink tips for HWIL simulation software engineers
Friday, November 3, 2023
Simulink signal
After generating code from a Simulink model, if you want to read the value of a parameter inside the model which is not an output port, you can use signals. In Matlab R2022b, signal definition is different from R2019a. The following R2022b method (assuming you have Embedded Coder) is only valid if you generate C code, I have not been able to find a way to generate signal code for C++:
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment