DLD Lab 6
DLD Lab 6
Group No.: 7
Mehreen 462557
Ans-Ur-Rehman 473914
In first part you are required to design and implement a binary to gray and gray to binary code
converter. You will be cascading these two converters thus implementing a binary to gray coder
and decoder (gray to binary).
The next part is the Verilog Modeling and Simulation of the Circuit you implemented in you first
lab.
Objectives:
Lab Instructions
This lab activity comprises three parts, namely Pre-lab, Lab tasks, and Post-Lab Viva session.
The lab report will be uploaded on LMS three days before scheduled lab date. The students will get
hard copy of lab report, complete the Pre-lab task before coming to the lab and deposit it with
teacher/lab engineer for necessary evaluation. Alternately each group to upload completed lab
report on LMS for grading.
The students will start lab task and demonstrate design steps separately for step-wise
evaluation( course instructor/lab engineer will sign each step after ascertaining functional
verification)
Remember that a neat logic diagram with pins numbered coupled with nicely patched circuit will
simplify trouble-shooting process.
After the lab, students are expected to unwire the circuit and deposit back components before
leaving.
The students will complete lab task and submit complete report to Lab Engineer before leaving
lab.
The Total duration for the lab is 3 hrs. After lab duration, a deduction of 5 marks per day
will be done for late submission.
A lab with in-complete lab tasks will not be accepted.
There are related questions at the end of this activity. Give complete answers.
1. What do you mean by binary codes for the decimal digits? Give some examples and codes (tables) for
the decimal digits.
A binary number system is one of the four types of number system. In computer applications, where
binary numbers are represented by only two symbols or digits, i.e. 0 (zero) and 1(one). The binary
numbers here are expressed in the base-2 numeral system. For example, (101)2 is a binary number.
Each digit in this system is said to be a bit.
Examples are excess-3 code, BCD code, 8421 code etc.
0 0000
1 0001
2 0010
3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
9 1001
10 1010
If the one's complement of the code is equal to the nine's complement of the code, then it is called a
self complementing code. Such codes have the property that the 9’s complement of a decimal number
is obtained directly by changing 1’s to 0’s and 0’s to 1’s (i.e., by complementing each bit in the pattern).
Examples: The 2421, the excess‐3 and the 8421 codes are examples of self‐complementing codes.
First of all 8421 & 2421 code are "self-complementing code" both (because the necessary condition for
a code to be self-complementing is that the sum of all of its weight must be equal to 9) i.e. 84-2-1(8+4-
2-1=9) and, 2421(2+4+2+1=9).
Decimal 0=0000(in 84-2-1 system) & (9's complement of 0=9) than 9(in 84-2-1) should have 1111.
Hence 0 & its 9's complement i.e. 9 maintain their self-complement relationship.
Decimal 1=0111(in 84-2-1 system) & (9's complement of 1=8 ) that implies (84-2-1) equivalent of 8
should be 1000,hence again the number & its complement preserve their self-complementary relationship.
Advantage:
With self complementing codes, the design of the hardware is easier when it comes to say,
9's complement subtraction. It is a method of subtraction by addition, the negative number is converted
to its 9's complement number. Self complementing codes give an easy way out.
3. In the lab you would be implementing a gray to binary and binary to gray code converter. Make a truth
table for both the codes by filling in the following tables and Simplify the expressions for W,X,Y,Z in terms of
A,B,C,D and vice versa.( Use backside of the page if necessary). Also give some applications in which gray
code could be used.
A
W A
B
X B
C
Y C
D
Z D
Only the following gates are available to you for lab tasks.
Implement the Binary to Gray Code Converter using logic gates. Make the Schematic Diagram. Show the
results to your Teacher/Lab Engr. What and how many gates did you use? Do not dispatch your hardware.
You will need it in lab task 3.
Proteus Simulation:
Realize the Gray to Binary Code Converter using exclusive-OR gates. Make the Schematic Diagram. Show the
results to your Teacher/ Lab Engr. What and how many gates did you use? Do not dispatch your hardware.
You will need it in lab task 3.
Hardware: Apologies Sir, this is cascaded circuit. We forgot to take pictures for grey to binary circuit.
Now cascade the two circuits in series by connecting the outputs of binary-to-gray converter to the inputs of the
gray-to-binary converter. You should be able to get the binary input at output as well. Show the results to your
Teacher/Lab Engr. Use LEDs to show input-output relationship.
Proteus Simulation:
Design and simulate the gate-level model of the circuit you patched in task 3. Give the code in the space
provided below.
GATE-LEVEL MODELING:
DATAFLOW MODELING:
module LAB6(W,X,Y,Z,A,B,C,D);
input A,B,C,D;
output W,X,Y,Z;
wire w1,w2,w3;
xor X1(w1,A,B);
xor X2(w2,B,C);
xor X3(w3,C,D);
assign W=A;
xor X4(X,A,w1);
xor X5(Y,X,w2);
xor X6(Z,Y,w3);
endmodule
module test_LAB;
reg a,b,c,d;
wire w,x,y,z;
LAB6 l6(w,x,y,z,a,b,c,d);
initial
begin
end
endmodule