Stateflow User's Guide Previous page   Next Page

Using the Debug Tool During Simulation

In Simulating a Stateflow Diagram, Stateflow highlights executing transitions and active states. You can enhance normal Stateflow simulation with the Stateflow Debugging tool. This tool lets you step through individual Stateflow actions that are not identified to you in normal simulation. By identifying all Stateflow diagram actions, the Debugging tool gives you insight into Stateflow behavior, and helps eliminate any doubts you may have about how your Stateflow diagrams work.

The following steps show you how to step through a simulation of the Controller Stateflow diagram using the Stateflow Debugging tool:

  1. In the Stateflow diagram editor, from the Tools menu, select Debug.
  1. The Stateflow Debugging window appears as shown.

  1. Select the Chart Entry breakpoint.
  1. This pauses execution when the diagram is entered after it is triggered by an event from the Manual Switch.

  1. Position the Stateflow Debugging window so that you can see it, the Simulink model window, and the Controller Stateflow diagram window at the same time.
  2. In the Stateflow Debugging window, click Start to start the simulation.
  1. When simulation begins, the Start button is relabeled to a Continue button and both the Continue and Step buttons are disabled. This means that the Controller diagram is inactive (asleep) and waiting for an event.

    Simulation running....
    This message appears in the top pane of the Debugging window. It indicates that the simulation is running, but there are no events to process. The Controller diagram is active, but asleep.

  1. In the Simulink window, double-click the Manual Switch block to send an event to the Controller diagram.
  1. The Debugging window now displays information in its top pane with the following labels:

    For now, pay attention only to the Stopped message. This message indicates what is taking place in the current simulation step. It is included with the examples that follow.

    Stopped: Entry: Chart Controller
    Indicates that this step is taking place while the Controller diagram is active and ready to respond to events.

  1. In the Stateflow Debugging window, click Step to advance simulation by a step.

    Stopped: After activation of Transition ?
    The Controller diagram is processing its default transition. The Debugging window refers to the identity of the current transition by its label. Because the Default Transition has no label, its label is referred to with a question mark character (?).

  2. Click Step to advance simulation by a step.

    Stopped: Just after activation of State Off.
    State Off is entered and is now active.

  3. Click Step to advance simulation by a step.

    Stopped: After broadcast of Input event event.
    All response activity to the event event is finished. The event has been consumed.

  4. Click Step to advance simulation by a step.

    Simulation running....
    The Controller diagram is active but asleep. In this phase, it is waiting for an event to wake it and be processed. The Continue and Step buttons are disabled until another event occurs.

  5. In the Simulink model, continue indefinitely to double-click the Manual Switch block to send another event to the Controller diagram and advance simulation to the next active state with the Step button.
  6. When you are finished debugging, in the Debugging window, click Stop Simulation to stop the simulation.
  1. Once the simulation stops, the model becomes editable.

  1. In the Debugging window, click Close to close it.

The Stateflow Debugging window is an important tool for studying Stateflow semantics, the description of the behavior of Stateflow objects in Stateflow diagrams. Even though the Stateflow Debugging window is not used throughout the remainder of this guide, you are encouraged to use it whenever you want to clarify Stateflow semantics in your models.


Previous page  Simulating a Stateflow Diagram Guarding Transitions with Event Triggers Next page

© 1994-2005 The MathWorks, Inc.