| Stateflow® |  |
Design Considerations for Continuous-Time Modeling in Stateflow Charts
Rationale for Design Considerations
To guarantee the integrity — or smoothness —
of the results in continuous-time modeling, you must constrain your
charts to a restricted subset of Stateflow chart semantics. The
restricted semantics ensure that inputs do not depend on unpredictable
factors — or side effects — such
as:
By minimizing side effects, a Stateflow chart
can maintain its state at minor time steps and, therefore, update
state only during major time steps when mode changes occur. Using
this heuristic, a Stateflow chart can always compute outputs
based on a constant state for continuous-time.
A Stateflow chart generates informative errors to help
you correct semantic violations.
Back to Top
Summary of Rules for Continuous-Time Modeling
Here are the rules for modeling continuous-time Stateflow charts:
Update local data only in transition, entry,
and exit actions
To maintain precision in continuous-time simulation, you should
update local data (continuous or discrete) only during physical events
at major time steps.
In Stateflow charts, physical events cause state transitions.
Therefore, write to local data only in actions that execute during
transitions, as follows:
State exit actions, which execute
before leaving the state at the beginning of the transition
Transition actions, which execute during the transition
State entry actions, which execute
after entering the new state at the end of the transition
Condition actions on a transition, but only if the
transition directly reaches a state
Consider this Stateflow chart.

In this example, the action {n++} executes
even when conditions c2 and c3 are
false. In this case, n gets updated in a minor
time step because there is no state transition.
Do not write to local continuous data in during actions
because these actions execute in minor time steps.
Do not call Simulink functions in state during actions
or transition conditions
This rule applies to continuous-time charts because you cannot
call functions during minor time steps. You can call Simulink functions
in state entry or exit actions
and transition actions. However, if you try to call Simulink functions
in state during actions or transition conditions,
an error message appears when you simulate your model.
For more information, see Using Simulink Functions in Stateflow Charts.
Compute derivatives only in during actions
A Simulink model reads continuous-time derivatives during
minor time steps. The only part of a Stateflow chart that executes
during minor time steps is the during action. Therefore,
you should compute derivatives in during actions
to give your Simulink model the most current calculation.
Do not read outputs and derivatives in states or transitions
This restriction ensures smooth outputs in a major time step
because it prevents a Stateflow chart from using values that
may no longer be valid in the current minor time step. Instead, a Stateflow chart
always computes outputs from local discrete data, local continuous
data, and chart inputs.
Use discrete variables to govern conditions in during actions
This restriction prevents mode changes from occurring between
major time steps. When placed in during actions,
conditions that affect control flow should be governed by discrete
variables because they do not change between major time steps.
Do not use input events in continuous-time Stateflow charts
The presence of input events makes Stateflow charts behave
like a triggered subsystem and therefore unable to simulate in continuous-time.
For example, the following model generates an error if the Stateflow chart
uses a continuous update method.

To model the equivalent of an input event, pass the input signal
through a Hit Crossing block as an input to the continuous chart,
as in this example.

Do not use inner transitions
When a mode change occurs during continuous-time simulation,
the entry action of the destination state indicates
to the Simulink model that a state transition occurred. If inner
transitions are taken, the entry action is never
executed.
Limit use of temporal logic
Do not use event-based temporal logic. Use only absolute-time
temporal logic for continuous-time simulation. See Operators for Absolute-Time Temporal Logic for details.
Event-based temporal logic has no meaning because there is no
concept of a tick during a continuous-time simulation.
The chart must have at least one substate
In continuous-time simulation, the during action
of a state updates the outputs. A chart with no state produces no
output. To simulate the behavior of a stateless chart in continuous-time,
create a single state which calls a graphical function in its during action.
Do not use change detection operators in continuous charts
To implement change detection, Stateflow software buffers
variables in a way that affects the behavior of charts between a minor
time step and the next major time step.
Back to Top
 | Modeling a Bouncing Ball in Continuous-Time | | Using Fixed-Point Data in Stateflow Charts |  |