Documentation

Schedule One Subsystem in a Single Step

With the loop scheduler design pattern, you can schedule one Simulink® subsystem to execute multiple times in a single time step. The model sf_loop_scheduler illustrates this design pattern.

The Looping Scheduler chart contains the following logic:

Key Behaviors of Loop Scheduler

The key behaviors of the loop scheduler are:

Function-Call Output Event Triggers Subsystem Multiple Times

In a given time step, the Stateflow® chart broadcasts a function-call output event to trigger the execution of the function-call subsystem A1 multiple times in the Simulink model. Here is the sequence of activities during each time step:

  1. The Simulink model activates the Stateflow chart Edge to Function at a rising edge of the 1-millisecond pulse generator.

  2. The Edge to Function chart broadcasts the function-call output event call to activate the Stateflow chart Looping Scheduler.

  3. The Looping Scheduler chart broadcasts a function-call output event from a for loop to trigger the function-call subsystem A1 multiple times (see Flow Chart Implements For Loop).

Flow Chart Implements For Loop

The Looping Scheduler chart uses Stateflow flow charting capabilities to implement a for loop for broadcasting an event multiple times in a single time step. The chart contains a Stateflow flow chart that uses a local data variable i to control the loop. At each iteration, the chart updates output y and issues the send action to broadcast a function-call output event that executes subsystem A1. Subsystem A1 uses the value of y to recompute its output and send the value back to the Looping Scheduler chart.

Run the Loop Scheduler

To run the sf_loop_scheduler model, follow these steps:

  1. Open the model by clicking sf_loop_scheduler or typing sf_loop_scheduler at the MATLAB® command prompt.

  2. Open the Scope block.

  3. Start simulation.

    The scope displays the value of y at each time step.

In this example, the Looping Scheduler chart executes the for loop 10 times in each time step. During each iteration:

  1. The chart increments y by 1 (the constant value of input u1).

  2. The chart broadcasts a function-call output event that executes subsystem A1.

  3. Subsystem A1 multiplies y by a gain of 1.

  4. Control returns to the chart.

Was this topic helpful?