This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Explicitly Schedule Execution of Model Components

You can control the execution of model components (Subsystem and Model blocks) by using export-function models or rate-based models. Benefits of scheduling components are:

  • Full control over scheduling of model components rather than letting Simulink® implicitly schedule the components.

  • No need to deal with data dependency issues between components. That is, there are only data transfers.

This topic describes how to create a rate-based model with explicitly scheduled subsystems, reference the model in a test model, and then add periodic event ports to the test model for simulation. For information about using export-function models, see Export-Function Models.

Create Rate-Based Model

Consider a model with two subsystems. Subsystem1 multiplies its input by 2 while Subsystem2 multiplies its input by 4.

Note

Using Continuous time blocks such as Integrator blocks are not allowed. Instead use discrete time equivalent blocks

  1. Open the Inport 1 dialog box. On the Signal Attributes tab, set the Sample time to 0.2.

  2. Open the Inport 2 dialog box. On the Signal Attributes tab, set the Sample time to 0.4.

  3. If a rate-based model has multiple rates, single tasking is not allowed. Select the Configuration Parameter check box for Treat each discrete rate as a separate task.

Create Test Model That References a Rate-Based Model

Testing a rate-based model includes referencing the model from a Model block in a test model, adding periodic event ports to the Model block, and then connecting function-calls to the ports.

  1. Create a new Simulink model.

  2. Add a Model block and open the block parameters dialog box.

  3. In the Model name box, enter the file name for the rate-based model.

  4. Select the Show model periodic event ports check box.

    Periodic event ports are added to the Model block with the Sample times you specified for the Inport blocks connected to the Subsystem blocks.

  5. Specify the execution rate using function-call initiators (Function-Call Generator blocks or Stateflow® charts). The function-call events and scheduling of the events are located outside of the Model block referencing the rate-based model.

    In this example, add Function-Call Generator blocks. Open the block dialog box for the blocks and specify Sample time.

    Subsystems or referenced models in a rate-based model with the same sample time must have a common rate initiator. This requirement includes periodic scheduled subsystems and event driven Function-Call Subsystem blocks with the same rate.

  6. Use a fixed-step solver for simulation. Set the Configuration Parameters Type to Fixed-step, Solver to auto, and Fixed-step size to auto.

Simulate Rate-Based Model

Simulate the behavior of a rate-based model from the test model.

  1. Run a simulation. Some common compile and run-time errors are cause by:

    • A periodic event port that is not connected to a function-call initiator with the same specified sample time.

    • A scheduled Inport block (Sample time parameter set to a value) in the referenced component model that does not specify one of the periodic event port rates (sample times specified in the Port discrete rates table).

  2. Observe the behavior of the component model. Open the Scope block.

Generate Code from Rate-Based Model

Generate code from the rate-based model, not from the model test harness. For scheduled subsystems with different discrete rates, multi-tasking is required and the resulting code has separate entry points.

  1. Generate code for the component model. From the menu, select Code > C/C++ Code > Build Model.

  2. Open the code generation report. From the menu, select Code > C/C++ Code > Code Generation Report > Open Model Report.

Related Topics