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:
The Simulink model activates the Edge to Function chart at the rising edge of the 1-millisecond pulse generator.
The Edge to Function chart broadcasts the function-call output event
call
to activate the Loop Scheduler chart.The Loop Scheduler chart calls the
send
operator to broadcast the function-call output eventA1
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 incrementsy
by 1 (the constant value of inputu1
).Each time that the chart broadcasts the output event to subsystem A1, the subsystem increments
y
by 1.5.