Main Content

Debug Errors in a Truth Table

Once you completely specify your truth tables, you begin the process of debugging them. The first step is to run diagnostics to check truth tables for syntax errors including overspecification and underspecification, as described in Correct Overspecified and Underspecified Truth Tables. Additionally, you can add breakpoints directly into your truth table to debug during simulation.

Truth tables are not supported in standalone Stateflow® charts in MATLAB®. For more information, see Use Truth Tables to Model Combinatorial Logic.

Find Syntax Errors by Running Diagnostics

To check for syntax errors:

  1. Double-click the truth table.

  2. In the truth table, click Run Diagnostics .

    For example, if you change the action for decision column D4 to an action that does not exist, you get an error message in the Diagnostic Viewer.

Truth table diagnostics run automatically when you simulate a model with a new or modified truth table. If no errors exist, the diagnostic window does not appear and simulation starts immediately.

Debug Logic by Using Breakpoints

You can use breakpoints in a Stateflow truth table to pause simulation and debug your logic. Once a breakpoint causes the simulation to pause, you can step through the actions and examine the data values at that specific point in the simulation.

With truth tables, you can set these different breakpoint types:

  • Condition tested

  • Decision tested

  • Decision valid

  • Action executed

After simulation stops at a breakpoint, you can continue chart execution on the Stateflow Editor toolbar, at the MATLAB command prompt, or by selecting a keyboard shortcut.

Toolbar IconOptionCommandDescriptionKeyboard Shortcut

Continuedbcont

Continue the simulation to the next breakpoint.

Ctrl+T

Step Overdbstep

Advance to the next step in the truth table execution.

F10

Step Indbstep in

From a state or transition action that calls a function, advance to the first executable statement in the function.

From a statement in a function containing another function call, advance to the first executable statement in the second function.

Otherwise, advance to the next step in the truth table execution. (See Step Over.)

F11

Step Outdbstep out

From a function call, return to the statement calling the function.

Otherwise, continue simulation to the next breakpoint. (See Continue.)

Shift+F11

Step Forward  

Exit debug mode and pause simulation before next time step.

 

Stop dbquit

Exit debug mode and stop simulation.

Ctrl+Shift+T

Condition Breakpoints

To set a breakpoint when a condition is tested, right-click the condition cell and select Set Breakpoint (Condition Tested). A red badge appears on the far left of the table next to the number of the condition. When you run the model, the simulation pauses when the condition is tested. Stateflow highlights the condition row being tested. Place your cursor over the data in the truth table to see its current value.

Truth table that is paused at a breakpoint when a condition is tested.

Decision Breakpoints

To set a breakpoint when a decision is tested, right-click the top of the decision column and select Set Breakpoint (Decision Tested). A red badge appears on the top of the decision column next to the number of the decision. When you run the model, the simulation pauses when the decision is tested. Stateflow highlights the decision column being tested. Place your cursor over the data in the truth table to see its current value.

Truth table that is paused at a breakpoint when a decision is tested.

To set a breakpoint when a decision is valid, right-click the action cell at the bottom of the decision column and select Set Breakpoint (Decision Valid). A red badge appears on the top of the cell next to the action number. When you run the model, the simulation pauses when the action is valid. Stateflow highlights the valid decision. Place your cursor over the data in the truth table to see its current value.

If there is more than one action to take when a decision is valid, the breakpoint is set for the first executable.

Truth table that is paused at a breakpoint when a decision is valid.

Action Breakpoints

To set a breakpoint when an action is executed, right-click the action cell and select Set Breakpoint (Action Executed). A red badge appears on the far left of the table next to the number of the action. When you run the model, the simulation pauses when the action is executed. Stateflow highlights the action row being tested. Place your cursor over the data in the truth table to see its current value.

If there is more than one action within the action cell, the breakpoint is set for the first action.

Truth table that is paused at a breakpoint when an action is executed.

Edit Breakpoints

Click the breakpoint to open the Edit Breakpoint dialog box. From this window you can disable the breakpoint by clearing the Enable Breakpoint check box.

When you add a condition to a breakpoint, the breakpoint pauses the simulation only when its associated condition is true.

Related Topics