Main Content

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 blocksINC,LIMIT, andRESET.InputandOutputrepresent I/O for the model. TheAmplifiersubsystem amplifies the input signal by gain factorK, which updates when signalequal_to_countistrue.

1.Open the model.

model='rtwdemo_rtwecintro'; open_system(model)

2.Open the Model Configuration Parameters dialog box.

cs = getActiveConfigSet(model); openDialog(cs);

3.Select theCode Generationtab.

4.To select a system target file, in theTarget Selectionpane, clickBrowseYou 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 theEmbedded Real-Time (ERT)system target file and clickApply.

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 theCode Generation Advisorpane, clickSet 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 theSet Objectivespane, selectExecution efficiencyandTraceability. ClickOK.

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.

  • PressCtrl+B.

  • Invoke theslbuildcommand from the MATLAB command line.

  • Invoke theslbuildcommand from the MATLAB command line.

9.View the code generation report.

The report includesrtwdemo_rtwecintro.c, associated utility and header files, and traceability and validation reports.

This figure contains a portion ofrtwdemo_rtwecintro.c

10.Close the model.

bdclose(model) rtwdemoclean;

相关的话题