22cse32 DLD Module V
22cse32 DLD Module V
Finite State Machine (FSM) is a calculation model that can be executed with the help
of hardware otherwise software. FSM is also known as finite state automation.
FSM This is used for creating sequential logic as well as a few computer programs.
FSMs are used to solve the problems in fields like mathematics, games, linguistics,
and artificial intelligence.
In a system where specific inputs can cause specific changes in state that can be
signified with the help of FSMs.
Finite State Machine is having two types of model: Moore Model or Mealy Model.
Moore Model:
• A Moore model is a type of finite state machine (FSM), named after Edward F.
Moore in 1956.
• The Moore state machine block diagram consists of two parts namely
combinational logic as well as memory.
• In this case, the current inputs, as well as current states, will decide the next
states.
• Thus, depending on further states, this machine will generate the outputs. So,
the outputs of this will be applicable simply after the conversion of the state.
• The output is generated only from the current state variables.
• It's widely used in digital circuit design and computer science. The key
characteristic of a Moore model is that its outputs depend only on the current
state of the machine, not on the input.
Page 1 of 34
Module 5
Mealy Model
• Mealy model is a type of finite state machine (FSM) used in the design of digital
circuits and systems.
• It is named after George H. Mealy, who introduced the concept in 1955.
• The Mealy model is characterized by the fact that its outputs depend on both
the current state and the current inputs.
• This is in contrast to the Moore model, where the outputs depend only on the
current state.
• The Mealy model is widely used in digital design because it can lead to more
compact and efficient designs compared to the Moore model, especially when
the output logic is complex.
Page 2 of 34
Module 5
1. From the specification of the statement Identify the number of states and
number of output & inputs. Mention the notation for the input & output.
2. Derive state diagram
• State representation will be like s0, s1…. or a ,b,…
3. Derive the state table
4. Reduce the number of states, if possible, Write reduced state table.
5. Identify the number of bits required to a state. Assign the binary values to each
state.
6. Identify the Flip Flop to be used and number of Flip Flop required. Mention the
notation for the FF.
7. Derive the transition table.
8. Draw the logic circuit using identified FF
No of state = 2; s0 = 0; s1=1
No of states = 3; S0=00; S1=01; S2=10
No of states =4; A=00; B=01; C=10; D=11
No of states are between 5 to 8; use 3 bits
Page 3 of 34
Module 5
Problem 1: Design sequence detector to detect a serial input sequence of110 using
Moore Model.
Solution:
Step 1: State Diagram
b a c 0
c d c 0
d a b 1
Page 4 of 34
Module 5
Step 4: K MAP
Step 5: Circuit
Page 5 of 34
Module 5
Circuit Diagram
Problem 2: Design a sequential circuit whose state tables are specified in the given
Table, using D flip-flops.
00 00 01 0 0
01 00 10 0 0
10 11 10 0 0
11 00 01 0 1
Solution:
Page 6 of 34
Module 5
0 0 0
0 1 1
1 0 0
1 1 1
1. Transition Table
Outpu
Present State Next State Input Flip-flop Inputs
t
Q0 Q1 Q0 Q1 x D0 D1
Z
00 00 0 0 0 0
00 01 1 0 1 0
01 00 0 0 0 0
01 10 1 1 0 0
10 11 0 1 1 0
10 10 1 1 0 0
11 00 0 0 0 0
11 01 1 0 1 1
2. K MAP
Page 7 of 34
Module 5
3. Circuit diagram
Problem 3: Design sequence detector to detect a serial input sequence of 110 using
Mealy Model.
Page 8 of 34
Module 5
Solution:
Step 1: State Diagram
b a c 0 0
c a c 1 0
Page 9 of 34
Module 5
Present
Input Next state Output
state (PS) Jb Kb Ja Ka
Qb Qa X (NS) Y
0 0 0 0 0 0 0 X 0 X
0 0 1 0 1 0 0 X 1 X
0 1 0 0 0 0 0 X X 1
0 1 1 1 0 0 1 X X 1
1 0 0 0 0 1 X 1 0 X
1 0 1 1 0 0 X 0 0 X
Step 4: K MAP
Step 5: Circuit
Page 10 of 34
Module 5
Problem 4: Design the circuit for the given state diagram using D FF.
1. State Table:
Page 11 of 34
Module 5
2. State assignment:
A – 00; B-01; C-10; D-11
3. Excitation Table
Page 12 of 34
Module 5
5. Logic Circuit
Page 13 of 34
Module 5
Solution:
From the state
diagram, we can generate the state table shown in Table 9. Note that there is
no output section for this circuit. Two flip-flops are needed to represent the four
states and are designated Q0Q1. The input variable is labelled as x.
00 00 01
01 10 01
10 10 11
11 11 00
Transition Table:
Page 14 of 34
Module 5
00 00 00 0X 0X
1 00 01 0X 1X
0 01 10 1X X1
1 01 01 0X X0
0 10 10 X0 0X
1 10 11 X0 1X
0 11 11 X0 X0
1 11 00 X1 X1
K MAP
Circuit diagram:
Page 15 of 34
Module 5
Problem 5:
Design a counter that has an Enable input When Enable=1 it increments through the
sequence 0,1,2,3,0,1,… with each clock tick. Enable=0 causes the counter to remain
in its current state.
Page 16 of 34
Module 5
0 0 1
1 1 2
2 2 3
3 3 0
2. A reasonable choice is to use the binary numbering system for each state.
With four states we need two bits. We will let n=n1n0, giving the state table:
Next
Present Enable=0 Enable=1
n1 n0 n1 n0 n1 n0
0 0 0 0 0 1
0 1 0 1 1 0
1 0 1 0 1 1
1 1 1 1 0 0
Page 17 of 34
Module 5
0 0 1 0 1 0 X X 0
0 1 0 1 0 X 0 0 X
0 1 1 1 1 X 0 X 0
1 0 0 0 1 0 X 1 X
1 0 1 1 0 1 X X 1
1 1 0 1 1 X 0 1 X
1 1 1 0 0 X 1 X 1
J1(E,n1,n0)=E⋅n0
K1(E,n1,n0)=E⋅n0
6. The circuit to implement this counter is:
Two methods:
1, Row Elimination Method
2. Implication method
• In this method, we first prepare a state table where at any given state the next
state and present output(s) are written for each combination of input(s).
• In the present problem there are only two possible values of input X = 0 and X
= I.
Page 19 of 34
Module 5
Example 1:
Page 20 of 34
Module 5
Example 2:
Consider the state table of a sequential circuit shown, Reduce the number
of states using row elimination Method
Page 21 of 34
Module 5
A B C 1 0
B F D 0 0
C D E 1 1
D F E 0 1
E A D 0 0
F B C 1 0
Step 1:
• It can be seen from the table that the present state A and F both
have the same next states, B (when x=0) and C (when x=1).
• Therefore, states A and F are equivalent.
• Thus, one of the states, A or F can be removed from the state table.
• We are removing F
• Replace F with A in the table
Output
Next State
Present State
x=0 x=1 x=0 x=1
A B C 1 0
B A D 0 0
C D E 1 1
D A E 0 1
E A D 0 0
Step 2:
Page 22 of 34
Module 5
Output
Next State
Present State
x=0 x=1 x=0 x=1
A B C 1 0
B A D 0 0
C D B 1 1
D A B 0 1
Step 1:
• State e and g are equivalent.
• Remove state g.
• Replace g with e
Page 23 of 34
Module 5
NS Output
PS
X=0 X=1 X=0 X=1
A a b 0 0
B c d 0 0
C a d 0 0
D e f 0 1
E a f 0 1
F e f 0 1
Step 2:
• State d and f are equivalent.
• Remove state f.
• Replace f with d
NS Output
PS
X=0 X=1 X=0 X=1
A a b 0 0
B c d 0 0
C a d 0 0
D e d 0 1
E a d 0 1
Example 4:
Page 24 of 34
Module 5
Step 1:
• State d and e are equivalent.
• Remove state e.
• Replace e with d
NS Output
PS
X=0 X=1 X=0 X=1
a d b 0 0
b d a 0 0
c g f 0 1
d a d 1 0
f c b 0 0
g a d 1 0
Step 2:
• State d and g are equivalent.
• Remove state g.
• Replace g with d
Page 25 of 34
Module 5
NS Output
PS
X=0 X=1 X=0 X=1
a d b 0 0
b d a 0 0
c d f 0 1
d a d 1 0
f c b 0 0
Page 26 of 34
Module 5
• In Step 4, we keep repeating Step 3 and cross or tick (if possible) as many
cross points in the implication table as possible.
• In Step 5, we check pair-wise equivalence starting from rightmost column e of
implication table.
Page 27 of 34
Module 5
Page 28 of 34
Module 5
Verilog Code:
Sequence detector to detect sequence as 1100 using Moore model
Verilog code
parameter A= 3'b 000, B= 3'b 001, C= 3'b 010, D= 3'b 011, E= 3'b
100;
else
Page 29 of 34
Module 5
end
always@( x, crt_state)
case(crt_state)
A: begin
y=0;
if(x==0)
nxt_state <=A;
else
nxt_state <= B;
end
B: begin
y=0;
if(x==0)
nxt_state <=A;
else
nxt_state <= C;
end
C: begin
y=0;
if(x==0)
nxt_state <=D;
else
nxt_state <= C;
end
D: begin
y=0;
if(x==0)
nxt_state <=E;
else
nxt_state <= B;
end
E: begin
y=1;
if(x==0)
Page 30 of 34
Module 5
nxt_state <=A;
else
nxt_state <= B;
end
endmodule
Test Bench:
initial begin
// Initialize Inputs
clk = 0;
x = 0;
rst = 1;
#100;
rst =0;
end
endmodule
Page 31 of 34
Module 5
else
crt_state <= nxt_state;
end
always@( x, crt_state)
case(crt_state)
A: begin
y=0;
if(x==0)
nxt_state <=B;
else
nxt_state <= A;
end
B: begin
y=0;
Page 32 of 34
Module 5
if(x==0)
nxt_state <=C;
else
nxt_state <= A;
end
C: begin
y=0;
if(x==0)
nxt_state <=C;
else
nxt_state <= D;
end
D: begin
if(x==0)
begin
nxt_state <=B;
y=0;
end
else
begin
nxt_state <= A;
y=1;
end
end
endmodule
initial begin
// Initialize Inputs
clk = 0;
x = 0;
rst = 1;
#100;
rst =0;
Page 33 of 34
Module 5
end
endmodule
Page 34 of 34