Stateflow    

Run a Simulation

These steps show how to run a simulation:

  1. Double-click the On_off Stateflow block to display the Stateflow diagram.
  2. Double-click the Scope block to display the output of the Sine Wave block in Simulink.
  3. Select Open Simulation Target from the graphics editor Tools menu.
  1. The Simulation Target Builder dialog box appears.

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

  1. Ensure that the check box to Enable Debugging/Animation is selected. Select OK 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 selected, to enable Stateflow diagram animation. Select Close to apply the change and close the window.
  3. Choose Start from the graphics editor Simulation menu to start a simulation of the model.
  1. By default the S-function sfun 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. This is displayed as "Ready (ICED)" where the term "ICED" is an internal Stateflow designation.

    The input from the Sine Wave 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 states.

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

Where Stateflow Generates Code for Simulation

When you simulate a Simulink model containing Stateflow charts (as you did in the previous section), Stateflow generates a Simulink S-function (sfun) target that enables Simulink to simulate the Stateflow blocks. The sfun target can be used only with Simulink.

Before generating code, Stateflow creates a directory called sfprj in the current MATLAB directory if the directory does not already exist. Stateflow uses the sfprj directory during code generation to store generated files. See the section Generated Files.

If you have the Stateflow Coder, you can generate stand-alone code suitable for a particular processor. See Building a Target for more information on code generation.


  Parse the Stateflow Diagram Debug the Model During Simulation