Skip to Main Content Skip to Search
Product Documentation

Common Modeling Errors the Debugger Can Detect

State Inconsistencies in a Chart

Definition of State Inconsistency

States in a Stateflow chart are inconsistent if they violate any of these rules:

Causes of State Inconsistency

An error occurs at compile time when the following conditions are all true:

You can control the level of diagnostic action that occurs due to omission of a default transition in the Diagnostics > Stateflow pane of the Configuration Parameters dialog box. For more information, see the documentation for the No unconditional default transitions diagnostic.

Detecting State Inconsistency with the Debugger

  1. Open the chart you want to debug.

  2. Open the debugger and select State Inconsistency.

  3. Start the simulation.

State Inconsistency Example

The following chart has a state inconsistency.

In the absence of a default transition indicating which substate is to become active, the chart has a state inconsistency error.

Adding a default transition to one of the substates resolves the state inconsistency.

Conflicting Transitions in a Chart

What Are Conflicting Transitions?

Conflicting transitions are two equally valid paths from the same source in a Stateflow chart during simulation. In the case of a conflict, Stateflow software evaluates equally valid transitions based on ordering mode in the chart: explicit or implicit.

Detecting Conflicting Transitions

To detect conflicting transitions during a simulation:

  1. Build the target with debugging enabled.

  2. Open the debugger and select Transition Conflict.

  3. Start the simulation.

Example of Conflicting Transitions

The following chart has two conflicting transitions:

How the Transition Conflict Occurs.  The default transition to state A assigns data a equal to 1 and data b equal to 10. The during action of state A increments a and decrements b during each time step. The transition from state A to state B is valid if the condition [a > 4] is true. The transition from state A to state C is valid if the condition [b < 7] is true. During simulation, there is a time step where state A is active and both conditions are true. This issue is a transition conflict.

If you select the Transition Conflict check box in the debugger, you get a run-time error. If you do not select the check box, resolution of the transition conflict depends on the ordering you use for evaluation of outgoing transitions.

Conflict Resolution for Explicit Ordering When Check Box Is Not Selected.  For explicit ordering, the chart resolves the conflict by evaluating outgoing transitions in the order that you specify explicitly. For example, if you right-click the transition from state A to state C and select Execution Order > 1 from the context menu, the chart evaluates that transition first. In this case, the transition from state A to state C occurs.

Conflict Resolution for Implicit Ordering When Check Box Is Not Selected.  For implicit ordering, the chart evaluates multiple outgoing transitions with equal label priority in a clockwise progression starting from the twelve o'clock position on the state. In this case, the transition from state A to state B occurs.

Data Range Violations in a Chart

Types of Data Range Violations

The Stateflow debugger detects the following data range violations during simulation:

When you select Saturate on integer overflow for your chart, the debugger does not flag any cases of integer overflow during simulation. However, the debugger continues to flag out-of-range data violations based on minimum-and-maximum range checks. For more information, see Impact of Saturation on Debugger Checks.

Detecting Data Range Violations

To detect data range violations during a simulation:

  1. Build the target with debugging enabled.

  2. Open the debugger and select Data Range.

  3. Start the simulation.

Data Range Violation Example

The following chart has a data range violation.

Assume that the data a has an Initial value and Minimum value of 0 and a Maximum value of 2. Each time an event awakens this chart and state A is active, a increments. The value of a quickly becomes a data range violation.

Cyclic Behavior in a Chart

What Is Cyclic Behavior?

Cyclic behavior is a step or sequence of steps that is repeated indefinitely (recursive). The Stateflow debugger uses cycle detection algorithms to detect a class of infinite recursions caused by event broadcasts.

Detecting Cyclic Behavior During Simulation

To detect cyclic behavior during a simulation:

  1. Build the target with debugging enabled.

  2. Open the debugger and select Detect Cycles.

  3. Start the simulation.

Cyclic Behavior Example

This chart shows how an event broadcast can cause infinite recursive cycles.

When the 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.

Flow Cyclic Behavior Not Detected Example

This chart shows an example of cyclic behavior in a flow graph that the debugger cannot detect.

The data object i is set to 0 in the condition action of the default transition. i increments 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 is never true in this flow graph, resulting in a cycle.

The debugger cannot detect this cycle because it does not involve recursion due to event broadcasts. Although the debugger cannot detect cycles that depend on data values, a separate diagnostic error does appear during simulation, for example:

Junction is part of a cycle and does not have an 
unconditional path leading to termination.

For information on fixing cyclic behavior in flow graphs, type the following at the MATLAB command prompt:

sfhelp('cycle_error');

Noncyclic Behavior Flagged as a Cycle Example

This chart shows an example of noncyclic behavior that the debugger flags as being cyclic.

State A becomes active and i is initialized to 0. When the transition is tested, the condition [i < 5] is true. The condition actions that increment i and broadcast the 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 behavior as a cycle, but the so-called cycle breaks when i becomes greater than 5.

  


Free Stateflow Interactive Kit

Learn how engineers use Stateflow to model state machines in their Simulink models.


Get free kit

Trials Available

Try the latest version of Stateflow.


Get trial software
 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS