Stateflow User's Guide Previous page   Next Page

Create the Model and Stateflow Diagram

In this topic you create an example model that you use as a debugging example. Use the following steps to create the example model:

  1. Create the following Simulink model and Stateflow diagram:



  2. From the Stateflow diagram editor, add an event Switch with a scope of Input from Simulink. and a Rising Edge trigger.
  3. Also add a data Shift with a scope of Input from Simulink.

The Stateflow diagram has two states at the highest level in the hierarchy, Power_off and Power_on. By default Power_off is active. The event Switch toggles the system between the Power_off and Power_on states. Power_on has three substates, First, Second, and Third. By default, when Power_on becomes active, First also becomes active. When Shift equals 1, the system transitions from First to Second, Second to Third, Third to First, for each occurrence of the event Switch, and then the pattern repeats.

In the Simulink model, there is an event input and a data input. A Sine wave block is used to generate a repeating input event that corresponds with the Stateflow event Switch. The Step block is used to generate a repeating pattern of 1 and 0 that corresponds with the Stateflow data object Shift. Ideally, the Switch event occurs in a frequency that allows at least one cycle through First, Second, and Third.


Previous page  Debugging Run-Time Errors Example Debugging the Stateflow Diagram Next page

© 1994-2005 The MathWorks, Inc.