You are on page 1of 13

Da Nang University of Technology

REPORT

ECE-351:
Lab1: Binary to Gray Code Conversion

Name: L Trung Hiu
Class: 10ES

Instructor: Mr Vo Tuan Minh








ECE-351:
Lab1: Binary to Gray Code Conversion


This Lab has been divided into two parts.
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).
Pre-Lab Tasks:
1. What do you mean by binary codes for the decimal digits? Give some examples and codes (tables) for
the decimal digits.

Binary coded decimal (BCD) is a system of writing numerals that assigns a four-digit binary code to
each digit 0 through 9 in a decimal (base-10) numeral.

Example:
Decimal BCD code
0 0000
1 0001
2 0010
3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
9 1001
10 0001 0000
25 0010 0101
37 0011 0111


2. What is a self-complementary code? Name any two of them and show their complementary nature
with examples.

A self complementary code is one thats 9's complement in decimal is the 1's complement in binary.
Ex: The 9's complement of 7 is 2 in decimal. In 2421 code,7 = 1101 and 2=0010

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. Also give some applications in which gray code could be used.
Decimal Binary Gray
HINT:Our inputs and outputs are of 4-bit each. You will have to make 4 K-Maps (Consider W as
independent function of A,B,C,D, Make K-Map and simplify it). Arrive at the simplest expression for
each output.











Decimal Binary Gray
A B C D W X Y Z
0 0 0 0 0 0 0 0 0
1 0 0 0 1 0 0 0 1
2 0 0 1 0 0 0 1 1
3 0 0 1 1 0 0 1 0
4 0 1 0 0 0 1 1 0
5 0 1 0 1 0 1 1 1
6 0 1 1 0 0 1 0 1
7 0 1 1 1 0 1 0 0
8 1 0 0 0 1 1 0 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

From the table, we have the K-map:
CD
AB 00 01 11 10
00 0 0 0 0
01 0 0 0 0
11 1 1 1 1
10 1 1 1 1

W = A
CD
AB 00 01 11 10
00 0 0 0 0
01 1 1 1 1
11 0 0 0 0
10 1 1 1 1

X= A.B + A.B

CD
AB 00 01 11 10
00 0 0 1 1
01 1 1 0 0
11 1 1 0 0
10 0 0 1 1

Y= B.C + B.C

CD
AB 00 01 11 10
00 0 1 0 1
01 0 1 0 1
11 0 1 0 1
10 0 1 0 1

Z= C.D + C.D


We have the simplest expression for each output.
W = A
X= A.B + A.B
Y= B.C + B.C
Z= C.D + C.D





Decimal Gray Binary
HINT:Our inputs and outputs are of 4-bit each. You will have to make 4 K-Maps (Consider A as
independent function of W,X,Y,Z. Make K-Map and simplify it). Arrive at the simplest expression for
each output.


Decimal Gray Binary
W X Y Z A B C D
0 0 0 0 0 0 0 0 0
1 0 0 0 1 0 0 0 1
2 0 0 1 1 0 0 1 0
3 0 0 1 0 0 0 1 1
4 0 1 1 0 0 1 0 0
5 0 1 1 1 0 1 0 1
6 0 1 0 1 0 1 1 0
7 0 1 0 0 0 1 1 1
8 1 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







We have the K-map:
YZ
WX 00 01 11 10
00 0 0 0 0
01 0 0 0 0
11 1 1 1 1
10 1 1 1 1

A = W
YZ
WX 00 01 11 10
00 0 0 0 0
01 1 1 1 1
11 0 0 0 0
10 1 1 1 1

B= W.X + W.X

YZ
WX 00 01 11 10
00 0 0 1 1
01 1 1 0 0
11 0 0 1 1
10 1 1 0 0

C=( W.X + W.X).Y + (W.X + W.X).Y

YZ
WX 00 01 11 10
00 0 1 0 1
01 1 0 1 0
11 0 1 0 1
10 1 0 1 0

D =(( W.X + W.X).Y + (W.X + W.X).Y). Z +( ( W.X + W.X).Y + (W.X + W.X).Y). Z



We have the simplest expression for each output.

A = W
B= W.X + W.X

C=( W.X + W.X).Y + (W.X + W.X).Y

D =(( W.X + W.X).Y + (W.X + W.X).Y). Z +( ( W.X + W.X).Y + (W.X + W.X).Y). Z



4.Draw the logic diagram for the above codes in the space provided below.













Lab 3: Digital Logic Design Page 4






A=
B=
C=
D=




4. Draw the logic diagram for the above codes in the space provided below. (2 Marks)







Lab Tasks:













W
X
Y
Z
A
B
C
D
A
B
C
D
HINT:
Our inputs and outputs are of 4-bit each.
You will have to make 4 K-Maps (Consider
A as independent function of W,X,Y,Z.
Make K-Map and simplify it). Arrive at the
simplest expression for each output.
Binary
Gray
Binary

docsity.com

Lab Tasks:
Only the following gates are available to you for lab tasks.
- 2-input NAND
- 2-input NOR
- Inverter
- 2-input AND
- 3-input NAND
- 4-input NAND
- 2-input OR
- 2-input XOR

Lab Task 1:
Implement the Binary to Gray Code Converter. Make the Schematic Diagram. Show the results to your
Lab Assistant. What and how many gates did you use?
Schematic Diagram:

I use 3 XOR gates





Lab Task 2:
Implement the Gray to Binary Code Converter. Make the Schematic Diagram. Show the results to your
Lab Assistant. What and how many gates did you use?

I use 3 XOR gates

Lab Task 3:
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 Lab Assistant.
Schematic Diagram

Lab Task4:
Design and simulate the gate-level model of the circuit you patched. Give the code to your Lab
Assistant.

1.Binary to gray converter:
a. Code
module binarytogray(A,B,C,D,W,X,Y,Z);
input A,B,C,D;
output W,X,Y,Z;
assign W=A;
xor xo(X,A,B);
xor xo1(Y,B,C);
xor xo2(Z,C,D);
endmodule

module tb;
parameter DELAY = 10;
reg A,B,C,D;
wire W,X,Y,Z;
binarytogray dut(A,B,C,D,W,X,Y,Z);
initial begin
#10 A=0;B=0;C=0;D=0;
#10 A=0;B=0;C=0;D=1;
#10 A=0;B=0;C=1;D=0;
#10 A=0;B=0;C=1;D=1;
#10 A=0;B=1;C=0;D=0;
#10 A=0;B=1;C=0;D=1;
#10 A=0;B=1;C=1;D=0;
#10 A=0;B=1;C=1;D=1;
#10 A=1;B=0;C=0;D=0;
#10 A=1;B=0;C=0;D=1;
#10 A=1;B=0;C=1;D=0;
#10 A=1;B=0;C=1;D=1;
#10 A=1;B=1;C=0;D=0;
#10 A=1;B=1;C=0;D=1;
#10 A=1;B=1;C=1;D=0;
#10 A=1;B=1;C=1;D=1;
$finish;
end
endmodule









b.Simulate



2. Gray to binary converter:
a. Code
module graytobinary(W,X,Y,Z,A,B,C,D);
input W,X,Y,Z;
output A,B,C,D;
assign A=W;
xor xo(B,W,X);
xor xo1(C,B,Y);
xor xo2(D,C,Z);
endmodule

module tb;
parameter DELAY = 10;
reg W,X,Y,Z;
wire A,B,C,D;
graytobinary dut(W,X,Y,Z,A,B,C,D);
initial begin
#10 W=0;X=0;Y=0;Z=0;
#10 W=0;X=0;Y=0;Z=1;
#10 W=0;X=0;Y=1;Z=1;
#10 W=0;X=0;Y=1;Z=0;
#10 W=0;X=1;Y=1;Z=0;
#10 W=0;X=1;Y=1;Z=1;
#10 W=0;X=1;Y=0;Z=1;
#10 W=0;X=1;Y=0;Z=0;
#10 W=1;X=1;Y=0;Z=0;
#10 W=1;X=1;Y=0;Z=1;
#10 W=1;X=1;Y=1;Z=1;
#10 W=1;X=1;Y=1;Z=0;
#10 W=1;X=0;Y=1;Z=0;
#10 W=1;X=0;Y=1;Z=1;
#10 W=1;X=0;Y=0;Z=1;
#10 W=1;X=0;Y=0;Z=0;

$finish;
end
endmodule
b.Simulate

3. Connecting the outputs of binary to gray converter to the inputs of the gray to binary
converter
a. Code
module binarytograytobinary(A,B,C,D,A1,B1,C1,D1);
input A,B,C,D;
output A1,B1,C1,D1;
wire X,Y,Z;
assign A1=A;
xor xo(X,A,B);
xor xo1(Y,B,C);
xor xo2(Z,C,D);
xor xo3(B1,A,X);
xor xo4(C1,B1,Y);
xor xo5(D1,C1,Z);
endmodule

module tb;
parameter DELAY = 10;
reg A,B,C,D;
wire A1,B1,C1,D1;
binarytograytobinary dut(A,B,C,D,A1,B1,C1,D1);
initial begin
#10 A=0;B=0;C=0;D=0;
#10 A=0;B=0;C=0;D=1;
#10 A=0;B=0;C=1;D=0;
#10 A=0;B=0;C=1;D=1;
#10 A=0;B=1;C=0;D=0;
#10 A=0;B=1;C=0;D=1;
#10 A=0;B=1;C=1;D=0;
#10 A=0;B=1;C=1;D=1;
#10 A=1;B=0;C=0;D=0;
#10 A=1;B=0;C=0;D=1;
#10 A=1;B=0;C=1;D=0;
#10 A=1;B=0;C=1;D=1;
#10 A=1;B=1;C=0;D=0;
#10 A=1;B=1;C=0;D=1;
#10 A=1;B=1;C=1;D=0;
#10 A=1;B=1;C=1;D=1;
$finish;
end
endmodule

b.Simulate



Observations/Comments:
For the Binary to gray converter and the Gray to binary converter, the simulation based on data in the
truth table.
In the last simulation, the input and output are the same. This does not surprise because we connect
the outputs of binary to gray converter to the inputs of the gray to binary converter so the input is
binary code and the output is binary code also.

You might also like