Super Step Semantics

By default, Stateflow® charts execute once for each input event or time step. If you are modeling a system that must react quickly to inputs, you can enable super step semantics. Super step semantics are supported only in Stateflow charts in a Simulink® model.

When you enable super step semantics, a Stateflow chart executes multiple times for every active input event or for every time step when the chart has no input events. The chart takes valid transitions until either of these conditions occurs:

  • No more valid transitions exist, that is, the chart is in a stable active state configuration.

  • The number of transitions taken exceeds a user-specified maximum number of iterations.

In a super step, your chart responds faster to inputs but performs more computations in each time step. Therefore, when generating code for an embedded target, make sure that the chart can finish the computation in a single time step. To achieve this behavior, fine-tune super step parameters by setting an upper limit on the number of transitions that the chart takes per time step (see Maximum Number of Iterations).

For simulation targets, specify whether the chart goes to the next time step or generates an error if it reaches the maximum number of transitions prematurely. However, in generated code for embedded targets, the chart always goes to the next time step after taking the maximum number of transitions.

Maximum Number of Iterations

In a super step, your chart always takes at least one transition. Therefore, when you set a maximum number of iterations in each super step, the chart takes that number of transitions plus 1. For example, if you specify 10 as the maximum number of iterations, your chart takes 11 transitions in each super step. To set maximum number of iterations in each super step, see Enable Super Step Semantics.

Enable Super Step Semantics

To enable super step semantics:

  1. Right-click inside the top level of a chart and select Properties from the context menu.

  2. In the Chart properties dialog box, select the Enable super step semantics check box.

    Two additional fields appear below that check box.

  3. Enter a value in the field Maximum iterations in each super step.

    The chart always takes one transition during a super step, so the value N that you specify represents the maximum number of additional transitions (for a total of N+1). Try to choose a number that allows the chart to reach a stable state within the time step, based on the mode logic of your chart. For more information, see Maximum Number of Iterations

  4. Select an action from the drop-down menu in the field Behavior after too many iterations.

    Your selection determines how the chart behaves during simulation if it exceeds the maximum number of iterations in the super step before reaching a stable state.

    BehaviorDescription
    Proceed

    The chart goes back to sleep with the last active state configuration, that is, after updating local data at the last valid transition in the super step.

    Throw Error

    Simulation stops and the chart generates an error, indicating that too many iterations occurred while trying to reach a stable state.

    Note

    Selecting Throw Error can help detect infinite loops in transition cycles (see Detection of Infinite Loops in Transition Cycles.

    Note

    This option is relevant only for simulation targets. For embedded targets, code generation goes to the next time step rather than generating an error.

Super Step Example

The following model shows how super step semantics differs from default semantics:

In this model, a Constant block outputs a constant value of 20 to input u in a Stateflow chart. Because the value of u is always 20, each transition in the chart is valid:

By default, the chart takes only one transition in each simulation step, incrementing y each time.

When you enable super step semantics, the chart takes all valid transitions in each time step, stopping at state C with y = 3.

How Super Step Semantics Works with Multiple Input Events

When you enable super step semantics for a chart with multiple active input events, the chart takes all valid transitions for the first active event before it begins processing the next active event. For example, consider the following model:

In this model, the Sum block produces a 2-by-1 vector signal that goes from [0,0] to [1,1] at time t = 1. As a result, when the model wakes up the chart, events E1 and E2 are both active:

If you enable super step semantics, the chart takes all valid transitions for event E1. The chart takes transitions from state A to B and then from state B to C in a single super step. The scope shows that y = 3 at the end of the super step:

In a super step, this chart never transitions to state D because there is no path from state C to state D.

Detection of Infinite Loops in Transition Cycles

If your chart contains transition cycles, taking multiple transitions in a single time step can cause infinite loops. Consider the following example:

In this example, the transitions between states A and B cycle and produce an infinite loop because the value of x remains constant at 1. One way to detect infinite loops is to configure your chart to generate an error if it reaches a maximum number of iterations in a super step. See Enable Super Step Semantics.