Main Content

Modeling a CD Player/Radio Using State Transition Tables

This example shows a simple model of a CD Player/Radio logic that uses State Transition Tables in Stateflow®.

The heart of the logic for controlling the CD Player/Radio is in the CdPlayerModeManager chart, which is designed using a State Transition Table. The table is used to represent modal logic in tabular form. It allows us to define various states and their hierarchical structure along with the transitions between the states.

State Cells

The left most column represents all the states in the table. Notice that states can be nested hierarchically. You can choose one of the states to be the default state at any given level. This is represented by a default transition drawn to the left of the state. You can also add a default transition row if there is logic involved in choosing the first state to enter.

You can add a history junction to a given state by right-clicking the state and selecting Add history junction. This enables the state to remember the last active state when it is re-entered instead of choosing the default state. For example, states ModeManager and ON have history junctions. A Stateflow chart can be automatically generated from this table view.

Transition Cells

The next set of columns represent the outer transitions from a state. Each row represents the outer transitions from a given state. Each of the transition cells is sub-divided into three sub-cells:

  1. Condition cell: to specify a boolean condition which specifies when the transition is active

  2. Condition Action cell: to specify the action to be taken when the transition is active

  3. Destination cell: to specify the destination state for the transition. Notice that you can use special keywords such as $NEXT, $PREV to specify the destination relative to the current state.

This chart receives user inputs, such as whether a disk has been inserted and the choice for the radio mode (FM, AM, or CD). Then the chart determines the mechanical command to output. The data types of input and output data are defined as enumerated data types in the MATLAB® files CdRequestMode.m and RadioRequestMode.m.

The output command from the CdPlayerModeManager chart is processed by the chart CdPlayerBehaviorModel which models the behavior of the CD Player mechanism. This logic is also implemented using a State Transition Table.

A MATLAB UI is used to set the various CD/Radio modes.

See Also


Related Topics