Stateflow | ![]() ![]() |
Debugging Cyclic Behavior
When a step or sequence of steps is indefinitely repeated (recursive), this is called cyclic behavior. The Debugger cycle detection algorithms detect a class of infinite recursions caused by event broadcasts.
Detecting Cyclic Behavior
To detect cyclic behavior during a simulation:
Example: Cyclic Behavior
This Stateflow diagram shows a typical example of a cycle created by infinite recursions caused by an event broadcast.
When state C
during
action executes event E1
is broadcast. The transition from state A.A1
to state A.A2
becomes valid when event E1
is broadcast. Event E2
is broadcast as a condition action of that transition. The transition from state B.B1
to state B.B2
becomes valid when event E2
is broadcast. Event E1
is broadcast as a condition action of the transition from state B.B1
to state B.B2
. Because these event broadcasts of E1
and E2
are in condition actions, a recursive event broadcast situation occurs. Neither transition can complete.
Example: Flow Cyclic Behavior Not Detected
This Stateflow diagram shows an example of cyclic behavior in a flow diagram that is not detected by the Debugger.
The data object i
is set to zero in the condition action of the default transition. i
is incremented in the next transition segment condition action. The transition to the third connective junction is valid only when the condition [i < 0]
is true. This condition will never be true in this flow diagram and there is a cycle.
This cycle is not detected by the Debugger because it does not involve event broadcast recursion. Detecting cycles that are involved with data values is not currently supported.
Example: Noncyclic Behavior Flagged as a Cycle
This Stateflow diagram shows an example of noncyclic behavior that the Debugger flags as being cyclic.
State A
becomes active and i
is initialized to zero. When the transition is tested, the condition [i < 5]
is true. The condition actions, increment i
and broadcast event E
, are executed. The broadcast of E
when state A
is active causes a repetitive testing (and incrementing of i
) until the condition is no longer true. The Debugger flags this as a cycle when in reality the apparent cycle is broken when i
becomes greater than 5.
![]() | Debugging Data Range Violations | Function Reference | ![]() |