letrunghieu 10es ece351 lab1report
Post on 02-Jun-2018
219 Views
Preview:
TRANSCRIPT
-
8/11/2019 LeTrungHieu 10ES ECE351 Lab1report
1/13
Da Nang University of Technology
REPORTECE-351:
Lab1: Binary to Gray Code Conversion
Name: L Trung HiuClass: 10ES
Instructor: Mr Vo Tuan Minh
-
8/11/2019 LeTrungHieu 10ES ECE351 Lab1report
2/13
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 codeconverter. You will be cascading these two converters thus implementing a binary to gray coder anddecoder (gray to binary).
Pre-Lab Tasks:
What do you mean by binary codes for the decimal digits? Give some examples and codes (tables) forthe decimal digits.
Binary coded decimal (BCD) is a system of writing numerals that assigns a four-digit binary code toeach digit 0 through 9 in a decimal (base-10) numeral.
Example:
Decimal BCD code
0 0000
1 00012 0010
3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
9 1001
10 0001 0000
25 0010 0101
37 0011 0111
What is a self-complementary code? Name any two of them and show their complementary naturewith 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
-
8/11/2019 LeTrungHieu 10ES ECE351 Lab1report
3/13
In the lab you would be implementing a gray to binary and binary to gray code converter. Make a truthtable for both the codes by filling in the following tables and Simplify the expressions for W,X,Y,Z interms of A, B, C, D and vice versa. Also give some applications in which gray code could be used.Decimal Binary GrayHINT: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 foreach 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 12 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 16 0 1 1 0 0 1 0 1
7 0 1 1 1 0 1 0 08 1 0 0 0 1 1 0 0
9 1 0 0 1 1 1 0 110 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
-
8/11/2019 LeTrungHieu 10ES ECE351 Lab1report
4/13
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 = ACD
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 1000 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 1000 0 1 0 1
01 0 1 0 1
11 0 1 0 1
10 0 1 0 1
Z= C.D + C.D
-
8/11/2019 LeTrungHieu 10ES ECE351 Lab1report
5/13
We have the simplest expression for each output.W = AX= A.B + A.BY= 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 asindependent function of W,X,Y,Z. Make K-Map and simplify it). Arrive at the simplest expression foreach output.
Decimal Gray BinaryW X Y Z A B C D
0 0 0 0 0 0 0 0 0
1 0 0 0 1 0 0 0 12 0 0 1 1 0 0 1 0
3 0 0 1 0 0 0 1 14 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 110 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 013 1 0 1 1 1 1 0 1
14 1 0 0 1 1 1 1 015 1 0 0 0 1 1 1 1
-
8/11/2019 LeTrungHieu 10ES ECE351 Lab1report
6/13
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 = WYZ
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
-
8/11/2019 LeTrungHieu 10ES ECE351 Lab1report
7/13
We have the simplest expression for each output.
A = WB= 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.
W
X
Y
Z
A
B
C
D
A
B
C
D
B nary
Gray
B nary
-
8/11/2019 LeTrungHieu 10ES ECE351 Lab1report
8/13
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
-
8/11/2019 LeTrungHieu 10ES ECE351 Lab1report
9/13
Lab Task 2:
Implement the Gray to Binary Code Converter. Make the Schematic Diagram. Show the results to yourLab 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 theinputs 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
-
8/11/2019 LeTrungHieu 10ES ECE351 Lab1report
10/13
Lab Task4:
Design and simulate the gate-level model of the circuit you patched. Give the code to your LabAssistant.
1.Binary to gray converter:
a. Codemodule 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;endendmodule
-
8/11/2019 LeTrungHieu 10ES ECE351 Lab1report
11/13
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;endendmodule
-
8/11/2019 LeTrungHieu 10ES ECE351 Lab1report
12/13
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;
-
8/11/2019 LeTrungHieu 10ES ECE351 Lab1report
13/13
#10 A=1;B=1;C=1;D=0;#10 A=1;B=1;C=1;D=1;
$finish;endendmodule
b.Simulate
Observations/Comments:
For the Binary to gray converter and the Gray to binary converter, the simulation based on data in thetruth table.
In the last simulation, the input and output are the same. This does not surprise because we connectthe outputs of binary to gray converter to the inputs of the gray to binary converter so the input isbinary code and the output is binary code also.
top related