Lecture 12 Ch06-2
Lecture 12 Ch06-2
TJLee
Fall, 2021
Types of FSM
◼ Moore machine ◼ Mealy-type machine (or Mealy machine)
◼ The output values are generated based
Reset
on both the state of the circuit and the
w=1 present values of its input.
w=0 A z = 0 B z = 0
◼ Only two states are needed in this
w=0
example.
w=0 w=1
Reset
w = 1z = 0
C z = 1
w= 0z =0 A B w = 1z = 1
w=1 w = 0z = 0
t0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t 10 t0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t 10
1 1
Clock Clock
0 0
1
w
1 0
w
0 1
y
0
1 1
y1 z
0 0
1
y2
0
1
z
0
Detection of Input Sequence, 11 (Mealy Machine)
◼ Moore machine
Clockcycle: t0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t10
w: 0 1 0 1 1 0 1 1 1 0 1
z: 0 0 0 0 0 1 0 0 1 1 0
Figure 6.2.
◼ Mealy machine
◼ The output z is equal to 1 in the same clock cycle when the second occurence
of w =1 is detected.
Figure 6.23. State diagram of an FSM that Figure 6.24. State table for the
realizes the task in Figure 6.22. FSM in Figure 6.23.
◼ State-assigned table
w D Q y
Clock Q
Resetn
(a) Circuit
t0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t10
1
Clock
0
1
w
0
y 1
0
z 1
0
w D Q Q
y
Clock
Resetn
(a) Circuit
t0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t 10
1
Clock
0
1
w
0
1
y
0 Figure 6.27. Circuit that
1
z implements the specification
0
1
in Figure 6.2.
Z
0
w = 0
A Reset
w = 1 R2 = 1, R 3 = 1
out in
w = 0 R1 = 1, R 2 = 1
w = 1 out in
w = 0 R3 = 1, R 1 = 1 , Done = 1
w = 1 out in
z
1 0 1 1 0 1 1 1 0 0
w D Q
y
Clock Q
Resetn
A change in w will immediately Figure 6.37. Simulation results for the Mealy machine.
reflect itself in the value of z if
the machine is in state B,
which meets the requirements
of the Mealy-type FSM.
1 0 1 1 0
Figure 6.38. Potential problem
with asynchronous inputs to a
Mealy FSM.
An erroneous 50 ns pulse generated, if the input is not
synchronized with positive-edge of clock. Is that alright?
Example: Serial Adder
◼ If speed is not of great importance, then a cost-effective option is to use a serial
adder, in which bits are added a pair at a time.
A
a
Shift register
s
Adder
FSM Shift register
Shift register
b
Sum = A + B
B
Clock
Figure 6.39. Block diagram for the serial adder.
a s
Full
b
adder Y y
D Q
carry-out
Clock Q
Sum bit Y1 y1
a D Q s
Full
b
adder Carry-out
Q
Y2 y2
D Q
Clock Q
Reset
endmodule
// Sequential block
always @(posedge Clock)
if (Reset) y <= G;
else y <= Y;
a7 a0 D3 D2 D1D0
L
E Counter
L
0 w Q3 Q2Q1Q0
1 E
b7 b0 Adder
FSM
Run
L 0 0
0 w
1 E
L
w
E
Clock
Reset
Sum7 Sum0
A B C 1 A B C 1
B D F 1 B A F 1
C F E 0 C F C 0
D B G 1 F C A 0
E F C 0
Figure 6.52. Minimized state table for
F E D 0
Example 6.6.
G F G 0
P3 = (ABD)(CEG)(F)
Figure 6.51. State table for Example 6.6. (ABD) 0-sucessors: (BDB) → in the same block
(ABD) 1-sucessors: (CFG) → not in the same block
(CEG) 0-sucessors: (FFF) → in the same block
(CEG) 1-sucessors: (ECG) → in the same block
P1 = (ABCDEFG) P4 = (AD)(B)(CEG)(F)
P2 = (ABD)(CEFG) P5 = (AD)(B)(CEG)(F)
(ABD) 0-sucessors: (BDB) → in the same block
(ABD) 1-sucessors: (CFG) → in the same block
(CEFG) 0-sucessors: (FFEF) → in the same block
(CEFG) 1-sucessors: (ECDG) → not in the same block
P3 = (ABD)(CEG)(F)
Example 6.7: The Vending Machine
◼ The machine accepts nickels (5 cents) and dimes (10 cents).
◼ It takes 15 cents for a piece of candy to be released from the machine.
◼ If 20 cents is deposited, the machine will not return the change, but it will credit the buyer
with cents and wait for the buyer to make a second purchase.
Clock
senseN
senseD
N
senseN D Q D Q
Clock Q Q
Figure 6.54. State diagram for Example 6.7. Present Next state Output
state DN =00 01 10 11 z
P1 = (S1, S2, S3, S4, S5, S6, S7, S8, S9)
P2 = (S1, S2, S3, S6)(S4, S5, S7, S8, S9) S1 S1 S3 S2 – 0
P3 = (S1)(S3)(S2, S6)(S4, S5, S7, S8, S9) S2 S2 S4 S5 – 0
P4 = (S1)(S3)(S2, S6)(S4, S7, S8)(S5, S9) S3 S3 S2 S4 – 0
P5 = (S1)(S3)(S2, S6)(S4, S7, S8)(S5, S9) S4 S1 – – – 1
S5 S3 – – – 1
Figure 6.56. Minimized state table for
Example 6.7.
Example 6.7: The Vending Machine
DN DN 0
S1 0 S1
N N0 D1
DN
DN 0
S3 0
D
N1 S3 D0
DN N DN
D N0 D1
DN S2 0 S5 1
N S2
D
S4 1
DN 0
Figure 6.57. Minimized state diagram
for Example 6.7. Figure 6.58. Mealy-type FSM for
Example 6.7.
Practice
◼ Problem 6.30 Write Verilog code for the FSM shown in Figure 6.57,
using the style of code in Figure 6.29.
◼ Problem 6.32 Write Verilog code for the FSM shown in Figure 6.58,
using the style of code in Figure 6.29.
Incompletely Specified FSMs
◼ Completely Specified ◼ Incompletely Specified FSM
◼ In Example 6.7, the partitioning
scheme works well.
Present Next state Output ◼ But in general, the partitioning
state w = 0 w = 1 z scheme is less useful when
incompletely specified FSMs are
A B C 1
involved.
B D F 1
C F E 0 Next state
Present Output
D B G 1 state z
DN =00 01 10 11
E F C 0
F E D 0 S1 S1 S3 S2 – 0
S2 S2 S4 S5 – 0
G F G 0
S3 S3 S6 S7 – 0
S4 S1 – – – 1
Figure 6.51. State table for Example 6.6. S5 S3 – – – 1
S6 S6 S8 S9 – 0
S7 S1 – – – 1
S8 S1 – – – 1
S9 S3 – – – 1
Figure 6.55. State table for Example 6.7.
Example 6.8: Incompletely Specified FSM