Products & Services Industries Academia Support User Community Company

Learn more about Stateflow   

Debugging a Truth Table

Checking 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 Correcting Overspecified and Underspecified Truth Tables.

To check for syntax errors, follow these steps:

  1. Double-click the truth table to open its editor.

  2. In the Truth Table Editor toolbar, click the Run Diagnostics button .

    If there are no errors or warnings, the Builder window appears and reports a message of success. If errors exist, the Builder window lists them. For example, if you change the action for decision column D4 to an action that does not exist, the Builder window appears.

    Each error appears with a red button, and each warning appears with a gray button. The first error message appears highlighted in the top pane, and the diagnostic message appears in the bottom pane.

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

Debugging a Truth Table During Simulation

Ways to debug truth tables during simulation include:

MethodUse WithHow To Do It
Use Stateflow debugging tools to step through each condition and action, and monitor data values during simulation.Stateflow Classic truth table and Embedded MATLAB truth tableSee Using Stateflow Debugging Tools.
Use Embedded MATLAB debugging tools to step through Embedded MATLAB code generated by the truth table.Embedded MATLAB truth table onlySee Using Embedded MATLAB Debugging Tools.

Using Stateflow Debugging Tools

When you use Stateflow debugging tools to debug truth tables, you must perform these tasks:

  1. Specify a breakpoint for the call to the truth table.

  2. Step through the conditions and actions.

Specifying a Breakpoint for the Call to a Truth Table.   Before you debug the truth table during simulation, you must set a breakpoint for the truth table in its properties dialog box. This breakpoint pauses execution during simulation so that you can debug each execution step of a truth table using the Stateflow Debugger.

Follow these steps:

  1. In the Stateflow Editor, right-click the truth table.

  2. In the context menu, select Properties.

    The Truth Table properties dialog box appears.

  3. For Breakpoints, select Function Call.

    This check box sets a breakpoint to occur when the Stateflow chart calls this truth table function during simulation.

  4. Select OK to save settings and close the Truth Table properties dialog box.

Stepping Through Conditions and Actions of a Truth Table.   After setting a breakpoint for the truth table function call, you can step through conditions and actions by following these steps:

  1. Click the Debug button in the Stateflow Editor toolbar to open the Stateflow Debugging window.

  2. From the Stateflow Debugging window, click Start to begin simulation of your model.

    If you made any changes to the truth tables since the last simulation, the debugger checks automatically for syntax errors. If you receive errors or warnings, make corrections before you try to simulate again.

    If no syntax errors exist in the truth table, simulation of your model begins.

  3. Wait until the breakpoint for the call to the truth table occurs.

    When this breakpoint occurs, the Truth Table Editor appears and the Start button in the Stateflow Debugging window changes to Continue.

  4. In the Stateflow Debugging window, from the Browse Data pull-down, select All Data (Current Chart).

    An updated display appears in the bottom pane.

    You can use this display to monitor Stateflow data during simulation.

  5. In the Stateflow Debugging window, click Step four times to advance simulation through the call to the truth table.

    The INIT action of the truth table highlights prior to execution.

  6. Click Step twice to execute the INIT action and advance truth table execution to the first condition.

  7. Click Step twice to evaluate the first condition and advance truth table execution to the second condition.

  8. Click Step twice to evaluate the second condition and advance truth table execution to the third condition.

  9. Click Step twice to evaluate the third condition and advance truth table execution to the first decision.

  10. Click Step twice.

    Because the first decision is true, truth table execution advances to its action A1.

  11. Click Step eight times to execute action A1 and advance to the FINAL action.

  12. In the Stateflow Debugging window, click Stop Simulation.

    This step executes the final action and exits the truth table. The Display block in the Simulink window displays the number 1.

Using Embedded MATLAB Debugging Tools

Embedded MATLAB truth tables generate content as Embedded MATLAB code, a format that offers advantages for debugging. You can set breakpoints on any line of generated code (whereas you cannot set breakpoints directly on a truth table). You can debug code generated by Embedded MATLAB truth tables the same way you debug an Embedded MATLAB function, as described in Debugging an Embedded MATLAB Function Block.

For more information about how to generate content for truth tables, see How Stateflow Software Implements Truth Tables.

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS