Test Rate-Based Model Simulation Using Function-Call Generators

This topic describes how to reference a rate-based model in a test model, and then add periodic function-call event ports to the test model for simulation. Open a completed test harness model.

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 function-call 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 Schedule rates check box.

    Periodic function-call 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 function-call event port rates (sample times specified in the Port discrete rates table).

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