dld-lab-report
dld-lab-report
ALI IJAZ
Group Member AZKA MALIK
Names
HUZAIFAH GOHAR
SP20-BSE-007
Registration SP20-BSE-022
Numbers SP20-BSE-037
Class BSE 2A
Table of Contents
LAB # 01 Introduction to Basic Logic Gate ICs on Digital Logic Trainer and Proteus Simulation........................3
Lab #02 Boolean Function Implementation using Universal Gates.....................................................................8
LAB #03 Introduction to Verilog and Simulation using XILINX ISE....................................................................18
LAB #04 Design and Implementation of Boolean Functions by Standard Forms using ICs/Verilog...................29
Lab #05 Logic Minimization of Complex Functions using Automated Tools.......................................................34
Lab #06 Xilinx ISE Design Flow with FPGA......................................................................................................39
LAB #07 Design and Implementation n-bit adder/subtractor on FPGA..............................................................44
LAB #08 Design and Implementation of n-bit Binary Multiplier on FPGA..........................................................49
Lab #09 Design and Implementation of BCD to 7-Segment Decoder on FPGA................................................54
Lab # 10 Design and implementation of a sequence detector using Mealy/Moore Machine.............................60
In Lab Tasks
Task 1)
Verify all gates using their ICs on KL-31001 Digital Logic Lab Trainer
INPUTS OUTPUTS
0 0 0 0 0 1 1 1
0 1 0 1 1 1 0 0
1 0 0 1 1 1 0 0
1 1 1 1 0 0 0 1
INPUT OUTPUT
A B
0 1
1 0
Task 2)
Verify all gates using their ICs on KL-31001 Digital Logic Lab Trainer
INPUTS OUTPUTS
0 0 0 0 0 1 1 1
0 1 0 1 1 1 0 0
1 0 0 1 1 1 0 0
1 1 1 1 0 0 0 1
INPUT OUTPUT
A B
0 1
1 0
2) Make a list of logic gate of ICs of TTL and CMOS family along with ICs
name.
Simulation Results
NOT Gate:
Different Gates:
Conclusion:
In Lab Tasks
Part 1: Implementing any logic expression by using only NAND gates
TASK 1.1) Verification of NOT Function:
F = A’
INPUT OUTPUT
A F
0 1
1 0
F = AB
INPUTS OUTPUTS
A B F
0 0 0
0 1 0
1 0 0
1 1 1
F=A+B
INPUTS OUTPUTS
A B F
0 0 0
0 1 1
1 0 1
1 1 1
F = A’B + AB’
INPUTS OUTPUTS
A B F
0 0 0
0 1 1
1 0 1
1 1 0
F = AB+ A’B’
INPUTS OUTPUTS
A B F
0 0 1
0 1 0
1 0 0
1 1 1
F = AB
INPUTS OUTPUTS
A B FC FO
0 0 0 0
0 1 0 0
1 0 0 0
1 1 1 1
INPUT OUTPUT
A F
0 1
1 0
INPUTS OUTPUTS
A B F
0 0 0
0 1 0
1 0 0
1 1 1
INPUTS OUTPUTS
A B F
0 0 0
0 1 1
1 0 1
1 1 1
Conclusion
In-Lab Task 2:
Task 1:
Write a Verilog code (Gate-Level) for NOT, OR, NOR, NAND, XOR and XNOR.
Answer:
Verilog code for NOT:
module NOT_gate (Y, A);
input A;
output Y;
not (Y,A);
endmodule
Task 2:
Write a stimulus/test bench for Task 01 and show the simulation results.
Answer:
NOT:
Testbench:
module NOT_Testbench;
// Inputs
reg A;
// Outputs
wire Y;
// Instantiate the Unit Under Test (UUT)
NOT_Gateuut (
.A(A),
.Y(Y)
);
initial begin
// Initialize Inputs
A = 0;
// Wait 100 ns for global reset to finish
#100;A=1;
// Add stimulus here
end
endmodule
OR:
Testbench:
module OR_testbench;
// Inputs
reg A;
reg B;
// Outputs
wire Y;
// Instantiate the Unit Under Test (UUT)
OR_gateuut (
.A(A),
.B(B),
.Y(Y)
);
initial begin
// Initialize Inputs
A = 0;
B = 0;
// Wait 100 ns for global reset to finish
#100;A=1;B=1;
// Add stimulus here
end
endmodule
NOR:
Testbench:
module NOR_testbench;
// Inputs
reg A;
reg B;
// Outputs
wire Y;
// Instantiate the Unit Under Test (UUT)
NOR_gateuut (
.A(A),
.B(B),
.Y(Y)
);
initial begin
// Initialize Inputs
A = 0;
B = 0;
NAND:
Test bench:
module NAND_testbench;
// Inputs
reg A;
reg B;
// Outputs
wire Y;
initial begin
// Initialize Inputs
A = 0;
B = 0;
end
endmodule
XOR:
Test bench:
module XNOR_testbench;
// Inputs
reg A;
reg B;
// Outputs
wire Y;
initial begin
// Initialize Inputs
A = 0;
B = 0;
end
endmodule
XNOR:
Testbench:
module XNOR_testbench;
// Inputs
reg A;
reg B;
// Outputs
wire Y;
initial begin
// Initialize Inputs
A = 0;
B = 0;
end
endmodule
Post-Lab:
Task 1:
Write a Verilog code for the given Boolean function* (e.g.F = x + x’y + yz’)
a) Using Gate-Level model (Provide Gate Level diagram and Truth Table)
Answer:
a) Gate level:
Verilog Code:
module Boolean_Function(
input x,
input y,
input z,
output F
);
wire w1, w2, w3, w4;
not g1(w1, x);
and g2(w2, w1, y);
not g3(w3, z);
and g4(w4, y, w3);
or g5(F, x, w2, w4);
endmodule
Dataflow Model:
Assign F = (x) | (~x & y) | (y & ~z)
Task 2:
Write a stimulus/test bench for Task 01 and show the simulation results.
Answer:
Testbench:
module Boolean_Function_Testbench;
// Inputs
reg x;
reg y;
reg z;
// Outputs
wire F;
initial begin
// Initialize Inputs
x = 0;
y = 0;
z = 0;
end
endmodule
Conclusion:
In-Lab Tasks
Implement the circuit for the given function “F”. Function’s output is given in
Table 4.5. Finds its Boolean expression in SoP and PoS forms.
Answer:
Implementation of circuit:
Boolean Expressions:
F = Σ(3, 7, 8, 13, 14, 15)
SoPForm=(A+B+C+D).(A+B+C+D’).(A+B+C’+D).(A+B’+C+D).(A+B’+C+D’)+(A+B’+C’+D).
(A’+B+C+D’).(A’+B+C’+D).(A’+B+C’+D’).(A’+B’+C+D)
Verilog Code:
module F1(
input A,
input B,
input C,
input D,
output F
);
wire w1, w2, w3, w4, w5, w6, w7, w8;
not g1(w, A);
and g2(w2, w1, C, D);
and g3(w3, A, B, C);
and g4(w4, A, B, D);
not g5(w5, B);
not g6(w6, C);
not g7(w7, D);
and g8(w8, A, w5, w6, w7);
or g9(F, w2, w3, w5, w8);
endmodule
2. Write a Verilog code for the reduced SoP circuit, �2, (Structural Level).
Answer:
Verilog Code:
module F2(
input A,
input B,
input C,
input D,
output F
);
wire w1, w2, w3, w4, w5, w6, w7, w8, w9, w10, w11, w12, w13, w14, w15, w16, w17, w18,
w19, w20, w21, w22, w23, w24, w25, w26, w27, w28, w29, w30;
nand g1(w1, A, C);
nand g2(w2, C, A);
nand g3(w3, w1, w2);
nand g4(w5, A, D);
3. Simulate and verify the outputs by making an appropriate stimulus for the
above modules.
Answer:
F1:
module F1_Testbench;
// Inputs
reg A;
reg B;
reg C;
reg D;
// Outputs
wire F;
initial begin
// Initialize Inputs
A = 0;
B = 0;
C = 0;
D = 0;
end
Conclusion
= AˊBD + BˊCD
Truth Table:
A B C D F Observed Outputs
F1 F2
0 0 0 0 0 0 0
0 0 0 1 0 0 0
0 0 1 0 0 0 0
0 0 1 1 1 1 1
0 1 0 0 0 0 0
0 1 0 1 1 1 1
0 1 1 0 0 0 0
0 1 1 1 1 1 1
1 0 0 0 0 0 0
1 0 0 1 0 0 0
1 0 1 0 0 0 0
1 0 1 1 1 1 1
1 1 0 0 0 0 0
1 1 0 1 0 0 0
1 1 1 0 0 0 0
1 1 1 1 0 0 0
In-Lab Task 2:
Using Structural Model, write a Verilog description for the 8-variables function ‘F’.
Verilog Code:
module main;
wire F;
reg a,b,c,d,e,f,g,h;
initial
begin
$monitor("a=%d,b=%d,c=%d,d=%d,e=%d,f=%d,g=%d,h=%d,F=%d",a,b,c,d,e,f,g,h,F);
a=0;b=0;c=0;d=0;e=1;f=0;g=1;h=1;
#100 a=1;b=0;c=1;d=1;e=1;f=0;g=1;h=0;
end
GL Z(F,a,b,c,d,e,f,g,h);
endmodule
module GL(F,a,b,c,d,e,f,g,h);
input a,b,c,d,e,f,g,h;
output F;
or g1(F,w25,w26,w27);
and g2(w26,w17,w18,w19,w20,w21,w22,w23,w24);
and g3(w27,w9,w10,w11,w12,w13,w14,w15,w16);
not g4(w7,a,a);
not g5(w8,b);
not g6(w1,c);
not g7(w2,d);
not g8(w13,e);
not g9(w4,f);
not g10(g);
not g11(h);
endmodule
Pre-lab Task:
K-Map Minimization
w= A
x= A’B+AB’
y= B’C+BC’
z= C’D+CD’
Step B
Gate level circuit diagram:
In-lab Task:
Q1: using Gate level model, write a verilog description of binary to gray
conversion.
module gray_code(w,x,y,z,a,b,c,d);
input a,b,c,d;
output w,x,y,z;
wire w1, w2, w3, w4,w5,w6,w7,w8,w9.w10,w11,w12,w13;
not g1(w1, a);
not g2(w,w1);
not g3(w2,a);
and g4(w4,w2,b);
not g5(w3,b);
and g6(w5,w3,a);
or g7(x,w4,w5);
not g8(w6,b);
and g9(w7,w6,c);
not g10(w8,c);
and g11(w9,w8,b);
or g12(y,w7,w9);
not g13(w10,c);
and g14(w12,w10,d);
not g15(w11,d);
and g16(w13,w11,c);
or g17(z,w12,w13);
endmodule
Post-lab Task:
Timing table:
Critical Analysis/Conclusion:
Pre-lab task:
Half adder by Gate Level:
module half_adder(s, c, a, b);
input a, b;
output s, c;
wire w1, w2, w3;
and g0(c, a, b);
nand g1(w2, a, b);
nand g2(w1, a, w2);
nand g3(w3, w2, b);
nand g4(s, w1, w3);
endmodule
In-lab Task:
Part 01:
4-bit binarry Adder by Gate level along with test bench:
module main;
reg [3:0]a, b;
reg cin;
wire [3:0]s;
wire c;
initial
begin
$monitor("a=%b, b= %b, cin=%b, s=%b, c=%b", a, b, cin, s, c);
a=0; b=0; cin=0;
#100 a=1; b=0; cin=0;
#100 a=1; b=1; cin=0;
#100 a=15; b=15;cin=0;
end
Fourbit_Adder g1(s, c, a, b, cin);
endmodule
input [3:0]a, b;
input cin;
output [3:0]s;
output c;
wire c1, c2, c3;
full_Adder g1(s[0], c1, cin, a[0], b[0]);
full_Adder g2(s[1], c2, c1, a[1], b[1]);
full_Adder g3(s[2], c3, c2, a[2], b[2]);
full_Adder g4(s[3], c, c3, a[3], b[3]);
endmodule
Part 02:
Comparator Verilog Code along with test bench:
module main;
reg [3:0] a,b;
wire x,y,z;
initial
begin
$monitor("a=%b, b=%b, x=%b, y=%b, z=%b", a, b, x, y, z);
a=0;b=0;
#10;a=8; b=8;
#10;a=2;b=6;
#10; a=5;b=3;
end
comparator s1(a,b,x,y,z);
endmodule
Post-lab Task:
Behavioral implementation of n-bit adder/subtractor:
Test Bench:
Critical Analysis/Conclusion:
Test bench:
In Lab Task 1
Implement 4-bit by 2-bit Binary Multiplier Using ICs
In Lab Task 2
Test bench:
Critical Analysis:
IN-LAB TASK 1
Test the functionality Of a BCD to 7-Segment decoder IC (CD4511) with
common cathode 7-Segment display
On Proteus:
IN-LAB TASK 2
Test bench:
Post-lab Tasks
Test bench:
State Diagram:
State Table:
Equations
Reduced from K-Maps:
Equation from Y:
AB~C
Circuit Diagram:
In-lab+Post-lab
Moore FSM for Sequence Detection:
Timing Table
Test Bench:
In this lab, we knew about Mealy and Moore model. But we used
Mealy machine model in this report. In lab task we converted
decimal number (22) into binary number then we used that binary
number to implement the state diagram using mealy model. The
state diagram of mealy machine associates an output value with each
transition edge, in contrast to the state diagram for a Moore
machine, which associates an output value with each state. In Mealy
model, we observed in state diagram that the next state depends on
the input and present state. We also observed that number of states
can become unmanageable if they are too many.