Lab6-Code Conversion Binary-to-Gray and Gray-to-Binary
Lab6-Code Conversion Binary-to-Gray and Gray-to-Binary
Group No.:
Name Reg. No Viva / Lab Analysis Modern Ethics and Individual Total
Performanc of data in Tool Usage Safety and Team marks
e Lab Report Work Obtained
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.
WHAT DO YOU MEAN BY BINARY CODES FOR THE DECIMAL DIGITS? GIVE SOME EXAMPLES AND CODES (TABLES)
FOR THE DECIMAL DIGITS.
ANSWER
In the coding, when numbers, letters or words are represented by a specific group of symbols, it is said that
the number, letter, or word is being encoded. The group of symbols is called as a code. The digital data is
represented, stored, and transmitted as group of binary bits. This group is also called as binary code. The
binary code is represented by the number as well as alphanumeric letter.
WHAT IS A SELF-COMPLEMENTING CODE? NAME ANY TWO OF THEM; SHOW THEIR COMPLEMENTING NATURE
WITH EXAMPLES AND DESCRIBE ADVANTAGES.
ANSWER
Self-Complementing Codes are those codes which have the property that 9’s complement of decimal number is directly obtained by
replacing 1 by 0’s and 0’s by 1’s. This means complementing each bit of the pattern. The example self-complementing codes are: The
2421, the excess‐3 and the 84-2-1 codes are examples of self‐complementing codes.
DECIMAL
2421 EXCESS-3
0 0000 0011
1 0001 0100
2 0010 or 1000 0101
3 0011 or 1001 0110
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.
TABLE:
3 0 0 1 1 0 0 1 0
9 1 0 0 1 1 1 0 1
10 1 0 1 0 1 1 1 1
11 1 0 1 1 1 1 1 0
12 1 1 0 0 1 0 1 0
13 1 1 0 1 1 0 1 1
14 1 1 1 0 1 0 0 1
15 1 1 1 1 1 0 0 0
EE-221: Digital Logic Design Page 4
GRAY TO BINARY CODE CONVERTER:
TABLE:
2 0 0 1 1 0 0 1 0
3 0 0 1 0 0 0 1 1
Final Boolean Equation after using K-
4 0 1 1 0 0 1 0 0 map:
A= W
5 0 1 1 1 0 1 0 1
B= W’X + WX’ or B= W xor X
6 0 1 0 1 0 1 1 0
C= Y’B+YB’ or C= Y xor B
7 0 1 0 0 0 1 1 1 D= Z’C + Z’C or D= Z xor C
8 0 1 0 0 1 0 0 0
9 1 1 0 1 1 0 0 1
10 1 1 1 1 1 0 1 0
11 1 1 1 0 1 0 1 1
12 1 0 1 0 1 1 0 0
13 1 0 1 1 1 1 0 1
14 1 0 0 1 1 1 1 0
15 1 0 0 0 1 1 1 1
A
W A
B
X B
C
Y C
D
Z D
Only the following gates are available to you for lab tasks.
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.
Lab Task 2:
Design and simulate the gate-level model of the circuit you patched in task 3. Give the code in the space provided below.
Code:
module BGB(OutputA, OutputB, OutputC, OutputD, W, X, Y, Z, A, B, C, D);
input A, B, C, D;
output OutputA, OutputB, OutputC, OutputD, W, X, Y, Z;
endmodule
module testbench();
reg A, B, C, D;
wire OutputA, OutputB, OutputC, OutputD, W, X, Y, Z;
initial begin
#100ns A = 0; B = 0; C = 0; D = 0;
#100ns A = 0; B = 0; C = 0; D = 1;
#100ns A = 0; B = 0; C = 1; D = 0;
#100ns A = 0; B = 0; C = 1; D = 1;
#100ns A = 0; B = 1; C = 0; D = 0;
#100ns A = 0; B = 1; C = 0; D = 1;
#100ns A = 0; B = 1; C = 1; D = 0;
#100ns A = 0; B = 1; C = 1; D = 1;
#100ns A = 1; B = 0; C = 0; D = 0;
#100ns A = 1; B = 0; C = 0; D = 1;
#100ns A = 1; B = 0; C = 1; D = 0;
#100ns A = 1; B = 0; C = 1; D = 1;
#100ns A = 1; B = 1; C = 0; D = 0;
#100ns A = 1; B = 1; C = 0; D = 1;
#100ns A = 1; B = 1; C = 1; D = 0;
#100ns A = 1; B = 1; C = 1; D = 1;
end
endmodule
Output: