Stateflow    

Running a Simulation

These steps show how to run a simulation:

  1. Ensure that the Stateflow diagram and the Scope block are open.

    Double-click on the On_off Stateflow block to display the Stateflow diagram. Double-click on the Scope block to display the output of the Sine wave.

  1. Select Open Simulation Target from the graphics editor Tools menu.

    The Simulation Target Builder dialog box appears.

  1. Select Coder Options on the Simulation Target Builder dialog box.

    The Simulation Coder Options dialog box appears.

  1. Ensure that the check box to Enable Debugging/Animation is checked. Click on the OK button to apply the change. Close the Simulation Coder Options and the Simulation Target Builder dialog boxes.
  2. Select Debug from the graphics editor Tools menu. Ensure that the Enabled radio button under Animation is checked to enable Stateflow diagram animation. Click on the Close button to apply the change and close the window.
  3. Choose Start from the graphics editor Simulation menu to start a simulation of the model.

    By default the S-function is the simulation target for any Stateflow blocks. Stateflow displays code generation status messages in the MATLAB command window. Before starting the simulation, Stateflow temporarily sets the model to read-only to prevent accidental modification while the simulation is running.

    The input from the Sine block is defined as the Input from Simulink event Switch. When the simulation starts the Stateflow diagram is animated reflecting the state changes triggered by the input sine wave. Each input event of Switch toggles the model between the Power_off and Power_on state.

  1. Choose Stop from the graphics editor Simulation menu to stop a simulation. Once the simulation stops, Stateflow resets the model to writable.


 Parsing the Stateflow Diagram Debugging