Lab 5
Lab 5
Lab 5
Spring 2021
Lab Report 5
DESIGN AND IMPLEMENTATION USING GATE-LEVEL
MODELING.
Prepared By:
Shahzaib Ahmad Qureshi: F2016019065
Digital System Design LAB 5
Objectives:
Design and Implement the digital circuits using gate level modeling.
Implement and create scalar and wide combinatorial circuits using gate-level molding such as
Multiplexers, Decoders. Encoders on FPGA.
Implement the combinational circuits using Multiplexers on FPGA.
Task 1:
Write the Verilog code from the given circuit diagram of two to four line decoder and verify its truth
table by implementing it on FPGA.
Verilog File:
module Task1(D, A, B, enable);
output [0: 3] D;
input A, B;
input enable;
wire A_not,B_not, enable_not;
not N1 (A_not, A);
not N2 (B_not, B);
not N3 (enable_not, enable);
nand N4 (D[0], A_not, B_not, enable_not);
nand N5 (D[1], A_not, B, enable_not);
Digital System Design LAB 5
endmodule
Test-Bench File:
module Task1_tb;
// Inputs
reg A;
reg B;
reg enable;
// Outputs
wire [0:3] D;
initial begin
// Initialize Inputs
A = 0; B = 0; enable = 1; #100;
A = 0; B = 0; enable = 0; #100;
A = 1; B = 0; enable = 0; #100;
A = 0; B = 1; enable = 0; #100;
A = 1; B = 1; enable = 0; #100;
end
endmodule
Digital System Design LAB 5
OUTPUT:
Task 2:
Write the Verilog code for given two to one line multiplexer and implement on FPGA
Digital System Design LAB 5
Verilog Code:
endmodule
Test-bench File:
module Task2_tb;
// Inputs
reg A;
reg B;
reg select;
// Outputs
wire m_out;
Task2 uut (
.m_out(m_out),
.A(A), .B(B), .select(select)
);
initial begin
A = 0; B = 1; select = 0; #100;
A = 1; B = 1; select = 0; #100;
A = 0; B = 1; select = 0; #100;
A = 1; B = 0; select = 1; #100;
A = 0; B = 1; select = 1; #100;
A = 1; B = 0; select = 1; #100;
Digital System Design LAB 5
end
endmodule
OUTPUT:
Task 3:
Implement the given circuit of two bit by two bit binary multiplier on FPGA.
Digital System Design LAB 5
Verilog Code:
module Task3(C,A,B );
output [3:0] C;
input [1:0] A,B;
wire w1,w2,w3,w4;
and A1(C[0],A[0],B[0]);
and A2(w1,A[0],B[1]);
and A3(w2,A[1],B[0]);
and A4(w3,A[1],B[1]);
half_Adder H1(C[1],w4,w1,w2);
half_Adder H2(C[2],C[3],w4,w3);
endmodule
TestBench File:
module Task3_tb;
// Inputs
reg [1:0] A;
reg [1:0] B;
// Outputs
wire [3:0] C;
initial begin
Digital System Design LAB 5
// Initialize Inputs
end
endmodule
OUTPUT:
Digital System Design LAB 5
Design Problem 1:
Design and implement 4X1 multiplexer using three 2X1 multiplexers developed in task2.
Verilog Code:
module mux_4x1(m_out, A, B, C, D, S0, S1);
output m_out;
input A, B, C, D, S0, S1;
wire w1,w2;
mux_2x1 M1(w1,A,B,S0);
mux_2x1 M2(w2,C,D,S0);
mux_2x1 M3(m_out,w1,w2,S1);
endmodule
Test-bench file:
module mux_4x1_tb;
reg A; reg B; reg C; reg D; reg S0; reg S1;
wire m_out;
mux_4x1 uut ( .m_out(m_out), .A(A), .B(B), .C(C), .D(D), .S0(S0), .S1(S1) );
initial begin
A = 1; B = 0; C = 0; D = 0; S0 = 0; S1 = 0; #100;
A = 0; B = 1; C = 0; D = 0; S0 = 1; S1 = 0; #100;
A = 0; B = 0; C = 1; D = 0; S0 = 0; S1 = 1; #100;
A = 0; B = 0; C = 0; D = 1; S0 = 1; S1 = 1; #100;
A = 0; B = 1; C = 1; D = 1; S0 = 0; S1 = 0; #100;
end
endmodule
Digital System Design LAB 5
OUTPUT:
Design Problem 2:
Design and implement digital circuit which executes the Boolean function formed by from following min
terms using Mux and Logic gates.
Circuit Diagram:
Digital System Design LAB 5
Test-bench File:
module Funtion_Mux_tb;
// Inputs
reg A;
reg B;
reg C;
reg D;
// Outputs
wire F;
// Instantiate the Unit Under Test (UUT)
Funtion_Mux uut (.F(F), .A(A), .B(B), .C(C), .D(D) );
initial begin
// Initialize Inputs
A = 0; B = 0; C = 0; D = 0; #100;
A = 0; B = 0; C = 0; D = 1; #100;
A = 0; B = 0; C = 1; D = 0; #100;
A = 0; B = 0; C = 1; D = 1; #100;
A = 0; B = 1; C = 0; D = 0; #100;
A = 0; B = 1; C = 0; D = 1; #100;
A = 0; B = 1; C = 1; D = 0; #100;
A = 0; B = 1; C = 1; D = 1; #100;
A = 1; B = 0; C = 0; D = 0; #100;
A = 1; B = 0; C = 0; D = 1; #100;
A = 1; B = 0; C = 1; D = 0; #100;
A = 1; B = 0; C = 1; D = 1; #100;
A = 1; B = 1; C = 0; D = 0; #100;
A = 1; B = 1; C = 0; D = 1; #100;
A = 1; B = 1; C = 1; D = 0; #100;
A = 1; B = 1; C = 1; D = 1; #100;
// Add stimulus here
end
Digital System Design LAB 5
endmodule
OUTPUT: