This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Debug Run-Time Errors in a State Transition Table

A state transition table is an alternative way of expressing sequential modal logic. Instead of drawing states and transitions graphically in a Stateflow® chart, use state transition tables to express the modal logic in tabular format. State transition tables are supported only as blocks in a Simulink® model. For more information, see State Transition Tables in Stateflow.

Create the Model and the State Transition Table

  1. Create a Simulink model with a new State Transition Table (sfnew -stt).

  2. Add the following states and transitions to your table:

    The table 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, and Third to First, for each occurrence of the event SWITCH. Then the pattern repeats.

  3. Add two inputs from Simulink:

    • An event called SWITCH with a scope of Input from Simulink and a Rising edge trigger.

    • A data called Shift with a scope of Input from Simulink.

  4. In the model view, connect a Sine Wave block as the SWITCH event and a Step block as the Shift data for your State Transition Table.

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

Debug the State Transition Table

To debug the table in Create the Model and the State Transition Table, follow these steps:

  1. Right-click the Power_off state, and select Set Breakpoint > On State Entry.

  2. Start the simulation.

    Because you specified a breakpoint on Power_off, execution stops at that point.

  3. Move to the next step by clicking the Step In button, .

  4. To see the data used and the current values, hover your cursor over the different table cells.

    Continue clicking the Step In button and watching the animating states. After each step, watch the chart animation to see the sequence of execution. Use the tooltips to see the data values.

Single-stepping shows that the loop from First to Second to Third inside the state Power_on does not occur. The transition from Power_on to Power_off takes priority.

Correct the Run-Time Error

In Debug the State Transition Table, you step through a simulation of a state transition table and find an error. The event SWITCH drives the simulation, but the simulation time passes too quickly for the input data object Shift to have an effect.

To correct this error:

  1. Stop the simulation so that you can edit the table.

  2. Add the condition after(20.0, sec) to the transition from Power_on to Power_off.

    Now the transition from Power_on to Power_off does not occur until 20 seconds have passed.

  3. Begin simulation.

  4. Click the Step In button repeatedly to observe the fixed behavior.

Related Topics