Ass2sol 162
Ass2sol 162
Assignment# 2 Solution
Q.1. Consider the given FSM that has 6 states, two inputs X and Y, and one output Z,
represented by the following state table:
S1 (3,4), (4,5)
S2 (1,2), (3,5), (0,2), (4,5),
(4,5) (0,1)
S3
S4 (0,1), (0,2),
(4,5)
S5 (0,1), (3,4) (0,1), (3,4),
(1,2), (3,5)
S0 S1 S2 S3 S4
(ii) Reduce the state table into the minimum number of states and show the reduced state
table.
The reduced state table is:
(i) Implement the FSM using the following state assignment: S0=00, S1=10, S2=01,
S3=11.
(ii) Implement the FSM using the following state assignment: S0=10, S1=01, S2=11,
S3=00.
The number of literals using the first state assignment is 6 while it is 14 using the
second state assignment. We could also say that the first assignment uses an
equivalent of 5 2-input primitive gates while the second state assignment uses 10 2-
input primitive gates. Therefore, the first assignment produces a significantly lower
area than the second assignment.
Q.3. It is required to design a sequential circuit using Mealy model that computes the equation
Z=3*X-3, where X is an unsigned number that will be fed serially. Assume that the
circuit has an asynchronous Reset input that resets the machine to the reset state.
(i) Draw the state diagram for your sequential circuit. Make sure that your state machine
is minimal and that it does not have any redundant state.
(ii) Derive minimized equations for the output Z and next state variables.
Since we have 6 states, we need 3 FFs: F2, F1, and F0. We will use the following
encoding: S0=000, S1=001, S2=010, S3=011, S4=100, and S5=101.
Transition Table:
Y = (F0 X)'
F0+ = F1' F0' + F1' X + F1 F0 X' = F1' (F0' + X) + F1 F0 X' = F1 (F0' + X)
F2+ = F2 X + F2 F0 + F1 X
parameter S0 = 3'b000;//B=3
parameter S1 = 3'b001;//B=2
parameter S2 = 3'b010;//B=1
parameter S3 = 3'b011;//B=0 & C=0
parameter S4 = 3'b100;//C=1
parameter S5 = 3'b101;//C=2
always @ (X or CS)
begin
Z = 0;
case (CS)
S0: if (X) NS=S3; else begin Z=1; NS=S1; end
endcase
end
endmodule
(iv) Write a Verilog test bench to test the correctness of your design for the following
input values: {X=1}, {X=3}, {X=5} and {X=4}.
module Y3XM3_TB() ;
initial begin
end
initial begin
//Applying X=1
@(negedge CLK) Reset=1;
@(negedge CLK) Reset=0; X=1;
@(negedge CLK) X=0;
@(negedge CLK) X=0;
@(negedge CLK) X=0;
//Applying X=3
@(negedge CLK) Reset=1;
@(negedge CLK) Reset=0; X=1;
@(negedge CLK) X=1;
@(negedge CLK) X=0;
@(negedge CLK) X=0;
//Applying X=5
@(negedge CLK) Reset=1;
@(negedge CLK) Reset=0; X=1;
@(negedge CLK) X=0;
@(negedge CLK) X=1;
@(negedge CLK) X=0;
//Applying X=4
@(negedge CLK) Reset=1;
@(negedge CLK) Reset=0; X=0;
@(negedge CLK) X=0;
@(negedge CLK) X=1;
@(negedge CLK) X=0;
end
endmodule
The simulation waveform below demonstrates the correct functionality of the designed sequential
circuit: