Create Export-Function Model

The first step for creating independent functions in the generated code from a Simulink® model is to define the functions in the context of an export-function model. See Export-Function Models Overview.

Create Model Algorithms

At the top-level of an export-function model, functions are modeled within Function-Call Subsystem, function-call Model, Simulink Function, and S-Function blocks. This example uses Function-Call Subsystem blocks to model two functions.

  1. Add two Function-Call Subsystem blocks.

  2. In the first subsystem, model a unit delay that increments by 0.05 at each time step.

  3. In the second subsystem, model the square of an input signal.

  4. Add Inport and Outport blocks.

Add Function-Call Inputs

Inport blocks configured to output function-call signals control the execution of Function-Call Subsystem blocks during a simulation. The function-call Inport blocks also create an entry point function in the generated code.

  1. Attach Inport blocks to the function()input ports on the Function-Call Subsystem blocks.

  2. Specify sample times. Open the Inport block dialogs and select the Signal Attributes tab. Select the Output function call check box. Set Sample time for the delay function to 0.1 (100 ms), and the square function to 0.01 (10 ms).

    Setting the sample time is only for simulation testing. Sample time values do not affect the generated code. However, comments are added in the code identifying the rate you should call the functions.

    You could set the sample times to -1 and allow any function-call rate (periodic or aperiodic) during simulation. By setting sample times, Simulink checks the calling rate with the specified rate and displays an error if there is a mismatch.

  3. Rename blocks. The names help to identify signals in the generated code.

  4. Update the model (Ctrl-D). Dotted-and-dashed lines identify function-call signals.

Satisfy Export-Function Model Requirements

  1. Open the Configuration Parameters dialog box. On the Modeling tab and from the Setup section, select Model Settings .

  2. In the Solver pane, set Solver selection Type to Fixed-step, Solver to auto, and Fixed-step size to auto.

  3. In the Code generation pane, set System target file to ert.tlc. This step requires an Embedded Coder® license.

After you create an export-function model, you can test it with simulations. Choose one of the following simulation testing methods: Test Export-Function Model Simulation Using Input Matrix, Test Export-Function Model Simulation Using Function-Call Generators, and Test Export-Function Model Simulation Using Stateflow Chart.

See Also

Blocks

Related Topics