Generate Code Using Embedded Coder
This example shows how to select a system target file for a Simulink® model, configure model parameters, generate C code for embedded systems, and view generated files.
The model represents an 8-bit counter that feeds a triggered subsystem that is parameterized by constant blocks
Output represent I/O for the model. The
Amplifier subsystem amplifies the input signal by gain factor
K, which updates when signal
1. Open the model.
2. Open the Model Configuration Parameters dialog box.
cs = getActiveConfigSet(model); openDialog(cs);
3. Select the Code Generation tab.
4. To select a system target file, in the Target Selection pane, click Browse You can generate code for a specific target environment or purpose. Some built-in targeting options are provided by system target files, which control the code generation process for a target environment.
5. Select the Embedded Real-Time (ERT) system target file and click Apply.
The ERT system target file supports a utility that you can use to specify and prioritize code generation settings based on your application objectives.
6. In the Code Generation Advisor pane, click Set Objectives.
You can set and prioritize objectives for the generated code. For example, while code traceability might be a very important criterion for your application, you might not want to prioritize it at the cost of code execution efficiency.
7. In the Set Objectives pane, select Execution efficiency and Traceability. Click OK.
You can select and prioritize a combination of objectives before generating code.
8. In the model window, initiate code generation and the build process for the model by using one of these options:
Click the Build Model button.
slbuildcommand from the MATLAB® command line.
9. View the code generation report.
The report includes
rtwdemo_rtwecintro.c, associated utility and header files, and traceability and validation reports.
This figure contains a portion of
10. Close the model.