This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Types of Chart Execution

Life Cycle of a Stateflow Chart

Stateflow® charts go through several stages of execution:

StageDescription
InactiveChart has no active states
ActiveChart has active states
SleepingChart has active states, but no events to process

When a Simulink® model first triggers a Stateflow chart, the chart is inactive and has no active states. After the chart executes and completely processes its initial trigger event from the Simulink model, it transfers control back to the model and goes to sleep. At the next Simulink trigger event, the chart changes from the sleeping to active stage.

See How Events Drive Chart Execution.

Execution of an Inactive Chart

When a chart is inactive and first triggered by an event from a Simulink model, it first executes its set of default flow charts (see Order of Execution for a Set of Flow Charts). If this action does not cause an entry into a state and the chart has parallel decomposition, then each parallel state becomes active (see Enter a Chart or State).

If executing the default flow paths does not cause state entry, a state inconsistency error occurs.

Execution of an Active Chart

After a chart has been triggered the first time by the Simulink model, it is an active chart. When the chart receives another event from the model, it executes again as an active chart. If the chart has no states, each execution is equivalent to initializing a chart. Otherwise, the active substates execute. Parallel states execute in the same order that they become active.

Execution of a Chart at Initialization

By default, the first time a chart wakes up, it executes the default transition paths. At this time, the chart can access inputs, write to outputs, and broadcast events.

If you want your chart to begin executing from a known configuration, you can enable the Execute (enter) Chart At Initialization chart property. When you turn on this option, the state configuration of a chart initializes at time 0 instead of the first occurrence of an input event. The default transition paths of the chart execute during the model initialization phase at time 0, corresponding to the mdlInitializeConditions() phase for S-functions. For more information, see Execute (Enter) Chart at Initialization.

Note

If an output of this chart connects to a SimEvents® block, do not select this check box. To learn more about using Stateflow charts and SimEvents blocks together in a model, see the SimEvents documentation.

Due to the transient nature of the initialization phase, do not perform certain actions in the default transition paths of the chart — and associated state entry actions — which execute at initialization. Follow these guidelines:

  • Do not access chart input data, because blocks connected to chart input ports might not have initialized their outputs yet.

  • Do not call exported graphical functions from other charts, because those charts might not have initialized yet.

  • Do not broadcast function-call output events, because the triggered subsystems might not have initialized yet.

You can control the level of diagnostic action for invalid access to chart input data in the Diagnostics > Stateflow pane of the Configuration Parameters dialog box. For more information, see the documentation for the Invalid input data access in chart initialization (Simulink) diagnostic.

Execute at initialization is ignored in Stateflow charts that do not contain states.

Related Topics