Model CD Player Using Enumerated Data

Overview of CD Player Model

This Simulink® model implements a basic CD player using enumerated data in three C charts.

Model ComponentDescriptionDetails
UserRequest chartReads and stores user inputsHow the UserRequest Chart Works
CdPlayerModeManager chartDetermines whether the CD player operates in CD or radio modeHow the CdPlayerModeManager Chart Works
CdPlayerBehaviorModel chartDescribes behavior of the CD player mechanismHow the CdPlayerBehaviorModel Chart Works

Benefits of Using Enumerated Types in This Model

This model uses two enumerated data types: RadioRequestMode and CdRequestMode.

Enumerated Data TypeEnumerated Values
RadioRequestMode
  • OFF(0)

  • CD(1)

  • FM(2)

  • AM(3)

CdRequestMode
  • EMPTY(-2)

  • DISCINSERT(-1)

  • STOP(0)

  • PLAY(1)

  • REW(3)

  • FF(4)

  • EJECT(5)

By grouping related values into separate data types, you get these benefits:

  • Enhance readability of data values in each chart.

  • Avoid defining a long list of constants, which reduces the amount of data in your model.

Run the CD Player Model

Follow these steps to run the model:

  1. Type sf_cdplayer at the MATLAB® command prompt.

  2. Start simulation of the model.

    The CD Player Helper GUI appears.

    The Display blocks in the model show the default settings of the CD player.

  3. In the CD Player Helper GUI, click CD in the Radio Request section.

    The Display blocks for enumerated data RR and CurrentRadioMode change from OFF to CD.

  4. In the CD Player Helper GUI, click Insert Disc.

    The Display block for enumerated data CdStatus changes from EMPTY to DISCINSERT to STOP.

  5. In the CD Player Helper GUI, click PLAY in the CD Request section.

    The Display blocks for enumerated data CR, MechCmd, and CdStatus change from STOP to PLAY.

    Note:   To see other changes in the Display blocks, you can select other operating modes for the CD player, such as FM or AM radio.

How the UserRequest Chart Works

Key features of the UserRequest chart include:

This chart reads user inputs from the CD Player Helper GUI and stores the information as output data.

Output Data NameData TypeDescription
RREnumeratedOperating mode of the radio component
CREnumeratedOperating mode of the CD component
DiscInsertBooleanSetting for CD insertion
DiscEjectBooleanSetting for CD ejection

How the CdPlayerModeManager Chart Works

Key features of the CdPlayerModeManager chart include:

Behavior of the CdPlayerModeManager Chart

  1. When the chart wakes up, the ModeManager state is entered.

  2. The previously active substate recorded by the history junction becomes active: Standby or ON.

      Note:   Transitions between the Standby and ON substates occur as follows.

      • If the enumerated data RadioReq is OFF, the Standby substate is entered.

      • If the enumerated data RadioReq is not OFF, the ON substate is entered. (For details, see Control of CD Player Operating Mode.)

  3. If the Boolean data DiscEject is 1 (or true), a transition to the Eject state occurs, followed by a transition back to the ModeManager state.

  4. Steps 2 and 3 repeat until the chart goes to sleep.

Control of CD Player Operating Mode

In the ON substate, three subcharts represent the operating modes of a CD player: CD, AM radio, and FM radio. Each subchart corresponds to a different value of enumerated data RadioReq.

Value of Enumerated Data RadioReqActive SubchartPurpose of Subchart
CDCDModeOutputs play, rewind, fast forward, and stop commands to the CdPlayerBehaviorModel chart
AMAMModeSets the CD player to AM radio mode
FMFMModeSets the CD player to FM radio mode

The hasChanged operator detects changes in the value of RadioReq with an inner transition.

How the CdPlayerBehaviorModel Chart Works

Key features of the CdPlayerBehaviorModel chart include:

Behavior of the CdPlayerBehaviorModel Chart

  1. When the chart wakes up, the Empty state is entered.

  2. If the Boolean data DiscInsert is 1 (or true), a transition to the Inserting state occurs.

  3. After a short time delay, a transition to the DiscPresent state occurs.

  4. The DiscPresent state remains active until the data CMD becomes EJECT.

  5. If the enumerated data CMD is EJECT, a transition to the Ejecting state occurs.

  6. After a short time delay, a transition to the Empty state occurs.

  7. Steps 2 through 6 repeat until the chart goes to sleep.

Update of CD Player Behavior

Whenever a state transition occurs, the enumerated data CdStatus changes value to reflect the behavior of the CD player.

Active StateValue of Enumerated Data CdStatusBehavior of CD Player
EmptyEMPTYCD player is empty.
InsertingDISCINSERTCD is being inserted into the player.
DiscPresent.STOPSTOPCD is present and stopped.
DiscPresent.PLAYPLAYCD is present and playing.
DiscPresent.REWREWCD is present and rewinding.
DiscPresent.FFFFCD is present and fast forwarding.
EjectingEJECTCD is being ejected from the player.

Was this topic helpful?