Main Content

Schedule a Subsystem Multiple Times in a Single Step

This example shows how to design a loop scheduler in Stateflow®. The loop scheduler design pattern allows you to execute a Simulink® subsystem multiple times in a single time step. Stateflow schedulers extend control of subsystem execution in a Simulink model, which determines order of execution implicitly based on block connectivity and sample time propagation.

Key Behavior of the Loop Scheduler

In this example, the Loop Scheduler chart broadcasts a function-call output event to execute the function-call subsystem A1 multiple times every time step. During each time step:

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

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

  3. The Loop Scheduler chart calls the send operator to broadcast the function-call output event A1 multiple times.

Each broadcast of the event A1 executes the subsystem A1. The subsystem computes its output and returns control back to the Loop Scheduler chart.

Run the Loop Scheduler

When you simulate the model, the scope displays the value of y at each time step.

During each time step, the value of y increases by 25 because:

  • The flow chart in the Loop Scheduler implements a for loop that iterates 10 times.

  • In each iteration of the for loop, the chart increments y by 1 (the constant value of input u1).

  • Each time that the chart broadcasts the output event to subsystem A1, the subsystem increments y by 1.5.

See Also

Related Topics