Sample problems on state machines

Sample problems on state machines
PRACTICE
FIGURE 19-11
Block Diagram for
Dice Game
EXAMPLE O
"бо 7 Md ra E CA ds wl TTA =
Figure 19-11 shows the block diagram for the dice game. Two counters are used to
Display
1-10-6
eta ens
ia
A NA
a ”
aed
ko.
У Бао тж
4, a
LE dr ET
ELENA
MC
ES
FROM ;
Charfes H. Roth, Jr.
"FUNDAMENTALS OF Logic DESIGN"
2/€-
THOMSON BRookS/ COLE
- -
simulate the roll of the dice. Each counter counts in the sequence 1, 2, 3,4,5,6,1,2,....
Thus, after the “roll” of the dice, the sum of the values in the two counters will be in the
range 2 through 12.
The rules of the game are as follows:
1. After the first roll of the dice, the player wins if the sum is 7 or 11. He loses if the
sum is 2, 3, or 12. Otherwise, the sum which he obtained on the first roll is referred
to as his point, and he must roll the dice again. |
2. On the second or subsequent roll of the dice, he wins if the sum equals his point, and
he loses if the sum is 7. Otherwise, he must roll again until he finally wins or loses.
The inputs to the dice game come from two push buttons, Rb (roll button) and Reser.
Reser is used to initiate a new game. When the roll button is pushed, the dice counters
count at a high speed, so the values cannot be read on the display. When the roll button
is released, the values in the two counters are displayed and the game can proceed.
Because the button is released at a random time, this simulates a random roll of the dice.
If the Win light or Lose light is not on, the player must push the roll button again. We will
assume that the push buttons are properly debounced and that the changes in Rb are
properly synchronized with the clock. Methods for debouncing and synchronization were
discussed previously.
Figure 19-12 shows a flowchart for the dice game. After rolling the dice, the sum is
tested. If itis 7 or 11, the player wins; if itis 2, 3, or 12, he loses. Otherwise, the sum is saved
in the point register, and the player rolls again. If the new sum equals the point, he wins; if
it is 7, he loses. Otherwise, he rolls again. After winning or losing, he must push Reset to
begin a new game.
The components for the dice game shown in the block diagram (Figure 19-11) include
an adder which adds the two counter outputs, a register to store the point, test logic to
determine conditions for win or lose, and a control circuit. The input signals to the control
circuit are defined as follows:
D, = 1 if the sum of the dice is 7
D,,, = 1 if the sum of the dice is 7 or 11
Розу = 1 if the sum of the dice is 2, 3, or 12
Ед = 1 if the sum of the dice equals the number stored in the point register
Rb = 1 when the roll button is pressed
Reset = 1 when the reset button is pressed
The outputs from the control circuit are defined as follows:
Roll = 1 enables the dice counters
Sp = 1 causes the sum to be stored in the point register
Win = 1 turns on the win light
Lose = 1 turns on the lose light
FIGURE 19-12
Flowchart for
Dice Game
ria wpa wt phy Ad wf F ul
A
Rol Dice
Store sum in
point register
}
Roll Dice pe
We can now convert the flowchart for the dice game to an SM chart for the control cir-
cuit using the defined control signals. Figure 19-13 shows the resulting SM chart. The con-
trol circuit waits in state Sp until the roll button is pressed (Rb = 1). Then, it goes to state
$, and the roll counters are enabled as long as Rb = 1. As soon as the roll button is released
(Rb = 0), D,,, is tested. If the sum is 7 or 11, the circuit goes to state $, and turns on the
Win light; otherwise, D23,7 is tested. If the sum is 2, 3, or 12, it goes to state $; and turns on
the Lose light; otherwise, the signal Sp becomes 1, and the sum is stored in the point register.
It then enters $, and waits for the player to “roll the dice” again. In Ss, after the roll button
is released, if Eq = |, the sum equals the point and state S, is entered to indicate a win. If
D, = 1, the sum is 7 and 5, is entered to indicate a loss. Otherwise, the control returns to S,
so that the player can roll again. When in 5, or 53, the game is reset to S, when the Reset
button is pressed.
FIGURE 19-13
SM Chart for
Dice Game
Y
Sof
baad
Y
$5/ Win
EXAMPLE 1
Design a state machine to control the tail lights of a 1965 Ford thunderbird, shown in
Fig.1. There are 3 lights on each side, and for turns they operate in sequence to
show the turning direction, as illustrated in fig.2.
The state machine has two input signals, LEFT and RIGHT that carry the driver's
request for a left turn or a right tum. It also has an emergency flasher input HAZ,
that requests the tail lights to be operated in hazard mode - all six lights flashing on
and off in unison. We assume the existence of a free-running clock signal whose
frequency equals the desired flashing rate for the lights.
1) Design a clocked synchronous state machine to control the T-bird lights. Use
state diagrams to describe the behavior of the state machine. Implement a
Moore state machine. Use no more than 8 states |
—
LC LB LA
7
RA R
Fig.1 T-bird tail lights
-
RC
Fig.2 Flashing sequence for T-bird tail lights (a) left turn; (b) right turn.
|
KO
EXAMPLE 2
You are to develop a state diagram for a washing machine. The machine starts when
a coin is deposited. It then sequences through the following stages: soak, wash,
rinse, and spin. There is a “double wash” switch, which, if turned on, causes a
second wash and rinse to occur. There is one timer. You may assume that each
stage should take the same amount of time. The time begins ticking as soon as the
coin is deposited, generates a T signal at the end of the time period, and then resets
itself and starts again. If the lid is raised during the spin cycle, the machine stops
spinning until the lid is closed. You may assume that the timer suspends ticking while
the lid is raised.
1) Identify your inputs and outputs, and draw the ASM chart that implements
this Moore finite state machine. (
— : EX LE 2
прив 1 С = обет T= Times, D= Doubte Wash,
cufpuis - MOL sales: DE, SUM,
WASH RINSE!
Spiw, SPINHOLO,
WASHZ, KINSEZ
—
|
Was this manual useful for you? yes no
Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Download PDF

advertisement