In this topic, you create a model with a Stateflow® chart to debug. Follow these steps:
Create the following Simulink® model:
Add the following states and transitions to your chart:
In your chart, add an event
a scope of Input from Simulink and
a Rising edge trigger.
Add a data
a scope of Input from Simulink.
The chart has two states at the highest level in the hierarchy,
Power_off is active. The event
the system between the
Third. By default, when
First also becomes active. When
1, the system transitions from
for each occurrence of the event
Switch, and then
the pattern repeats.
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
Shift. Ideally, the
occurs at a frequency that allows at least one cycle through
To debug the chart in Create the Model and the Stateflow Chart, follow these steps:
Right-click in the chart, and select Set Breakpoint on Chart Entry.
Start the simulation.
Because you specified a breakpoint on chart entry, execution stops at that point.
Click the Step In button, .
The Step In button executes the next step and stops.
Continue clicking the Step In button and watching the animating chart.
After each step, watch the chart animation to see the sequence of execution.
Single-stepping shows that the chart does not exhibit the desired
behavior. The transitions from
Power_on are not occurring because the
priority. The output display of code coverage also confirms this observation.
In Debug the Stateflow Chart, you step through a simulation
of a chart and find an error: the event
the simulation but the simulation time passes too quickly for the
input data object
Shift to have an effect.
Correct this error as follows:
Stop the simulation so that you can edit the chart.
Add the condition
20.0] to the transition from
Now the transition from
not occur until simulation time is greater than 20.0.
Begin simulation again.
Click the Step In button repeatedly to observe the new behavior.