Debug Run-Time Errors in a Truth Table

Truth tables implement combinatorial logic design in a concise, tabular format. Truth tables are supported only in Stateflow® blocks in a Simulink® model. For more information, see Reuse Combinatorial Logic by Defining Truth Tables.

Check Truth Tables for Errors

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.

To check for syntax errors:

  1. Double-click the truth table.

  2. In the truth table, select 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 start simulation of the model with a new or modified truth table. If no errors exist, the diagnostic window does not appear and simulation starts immediately.

Debug a Truth Table During Simulation

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 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.

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.

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. In truth tables that use MATLAB as the action language, you can set a breakpoint on any line of executable code by setting breakpoints in the generated content. See Debugging Generated Truth Table Content.

Action Breakpoints

To set a breakpoint when a 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. In truth tables that use MATLAB as the action language, you can set a breakpoint on any line of executable code by setting breakpoints in the generated content. See Debugging Generated Truth Table Content.

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.

Debugging Generated Truth Table Content

You can use breakpoints on the generated content for truth tables that use MATLAB or C as the action language. For more information about how to generate content for truth tables, see View Generated Content for Stateflow Truth Tables.

For truth tables that use MATLAB as the action language, content is generated as MATLAB code. To set a breakpoint in the code, click the breakpoint alley next to the executable line where you want simulation to pause. See Debug a MATLAB Program (MATLAB). When you add an element to your truth table that changes the generated content, all breakpoints are regenerated.

For truth tables that use C as the action language, content is generated as a graphical function. To set a breakpoint in the graphical function, right-click the transition where you want to set a breakpoint and select Set Breakpoint. When you add an element to your truth table that changes the generated content, all breakpoints are regenerated if you recompile your truth table.

Related Topics