Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

TITLE:

Designing and implementation of Binary to gray code


converter, 4 bit magnitude comparator and BCD to 7
segment decoder.

DLD LAB # 7
DEPT: CS-03
DATE OF EXPERIMENT: 29/3/23

NAME:
RIJA MOBIN IFRAH JANNAT EMAN SHAHID

REG NO:
37 40 44
OBJECTIVES:
 Designing and implementation of Binary to gray code converter and gray code to binary
converter according to their given table.
 Implementation and designing of 4 bit magnitude comparator by comparing all the values
of respective truth table.
 Implementation and designing of BCD to 7 segment decoder by checking the values of truth
table.

EQUIPMENTS:
 Logic gates
 Logic probes/states
 Connecting wires
 BCD to 7 segment decoder
 Anode and cathode type
 Magnitude comparator
INTRODUCTION:
GRAY CODE:
It is also known as reflected binary code (RBC). It consist of Boolean expression in which the Boolean value is differ from
only one bit. Gray code is used in communication systems, it is also used in to minimize the error in communication
system. Gray code concept is also used in k-map rule. In k-map we first construct a map according to the binary values
of input variables. Then we convert binary values into gray code by using following rules: gray code is obtained by
comparing two binary values according to XOR. Eg:
The gray code of 1001 is 1101, according to XOR table:
1 XOR 1=0
1 XOR 0=1
0 XOR 1=1
0 XOR 0=0
Gray code helps us in reducing the errors in grouping process, it is also used to reduce the complexity of circuit and
increase reliability. But it is not suitable for arithmetic operations.

BINARY TO GRAY CODE CONVERTER:


It is digital circuit which takes input in binary form and converts it in grey code and vice versa. The most significant (MSB) of
the grey code is the same as most significant (MSB) of the binary code Firstly for this type of conversion we must specify a
bit combination for both input and output, if we want to convert 3 bits from binary to gray code then we take 3 bit input in
binary as B2, B1 and B0 and output is designated in gray code bits as G2, G1 and G0. From conversion from binary code to
gray code or from gray to binary code. We compare the inputs using XOR combinations. We have some specified rules.

XOR truth table

From binary to gray code:


4-BIT BINARY TO GRAYCODE:
Equations:
Equations to convert binary to gray code are:
g3=b3
g2=b2 b1
g1=b2 b1
g0=b1 b0
Here b 3 is 1st bit of 4-bit binary code, b 2 is 2nd bit, b 1 is 3rd bit and b 0 is 4th bit of 4-bit binary code which is to be converted
to gray code.
Similarly, g 3 is 1st bit of 4-bit gray code, g 2 is 2nd bit, g 1 is 3rd bit and g 0 is 4th bit of 4-bit gray code which is converted
from binary code.
PROCEDURE:
1. To convert binary code to gray code, we design circuit using equations given above.
2. First, we take an input say b 3 and join LED to its output say g 3 equal to b 3.
3. Now, take another input b 2 and join b 3 as another input to XOR gate and join LED to its output g 2.
4. Take new input b 1 and join b 1 as one and b 2 as another input to second XOR gate and attach LED to its output g 1.
5. Take 4th input b 0 and give b 0 and b 1 as two inputs to another XOR gate and attach LED to its output g 0.
6. Giving 4-bit binary to 4 inputs will give 4-bit gray code as resultant and we verify it using truth table. Switched on LED gives
1 and switched off gives 0.
(Task1(a) done according to it.)

Truth Table:

From gray code to binary:


GRAYCODE TO 4-BIT BINARY:
Equations:
Equations to convert binary to gray code are:
b3=g3
b2=b3 g2
b1=b2 g1
b0=b1 g0
Here b 3 is 1st bit of 4-bit binary code, b 2 is 2nd bit, b 1 is 3rd bit and b 0 is 4th bit of 4-bit binary code which is converted
from gray code.
Similarly, g 3 is 1st bit of 4-bit gray code, g 2 is 2nd bit, g 1 is 3rd bit and g 0 is 4th bit of 4-bit gray code which is to be converted
to binary code.

PROCEDURE:
1. To convert gray code to 4-bit binary code, we design circuit using equations given above.
2. First, we take an input say g 3 and join LED to its output say b 3 equal to g 3.
3. Now, take another input g 2 and give g 2 as one input and g 3 as another input to XOR gate and join LED to its output b 2.
4. Take new input g 1 and join g 1 as one and b 2 (output of g 2) as another input to second XOR gate and attach LED to its
output b 1.
5. Take 4th input g 0 and give g 0 and b 1 as two inputs to another XOR gate and attach LED to its output b 0.
6. Giving 4-bit gray code to 4 inputs will give 4-bit binary code as resultant and we verify it using truth table. Switched on LED
gives 1 and switched off gives 0.
(Task1b done according to it.)
Truth Table:

BCD TO 7 SEGMENT DECODER:


BCD to 7 segment converter is an electronic device which takes input in binary form and shows output in different decimal
numbers on 7 segment display. BCD stands for binary coded decimal which shows binary form of decimal digit, such as the
binary form of decimal digit 6 is 0110 and 7 segment is an electronic device which shows output in decimals, it consist of 7
attachments 7 for each attached LED and one for common terminal and these seven segments are turned off and on
individually to show output such as numbers and characters according to the given binary input. 7 segment display is labeled
from a to g.

In seven segment display DP stands for “decimal point” which is used to indicate decimal points or any special character
and it is located at the right bottom of 7-segment display.
There are two common types of 7 segment display .

1. Common cathode type


2. Common anode type

COMMON CATHODE TYPE:


Common cathode type is a type of electronic circuit in which all the cathode of multiple LEDs are connected to the ground
and anode is connected to output terminal. In seven segment display the cathodes of all the LEDs are connected to a single
common cathode pin when a high level voltage is applied to the anodes specific segment, those segment will light up and
shows output of a particular number or letter according to the given binary input.
COMMON ANODE TYPE:
Common anode type is a type of electronic circuit in which all the anode of multiple LEDs are connected to the +vcc and
cathode is connected to output terminal. in seven segment display the anodes of all the LEDs are connected to a single
common anode pin, when a low level voltage is applied to the cathodes specific segment, those segment will light up and
shows output of a particular number or letter according to the given binary input.

In order to check the type of segment that whether it is common cathode type or common anode type then you may use
decimal point in this case. First connect the decimal to the ground and then apply the voltage of 5v to the center pin, if dot
point’s light turns on then it is common anode type and if the light on dot pin turns off then it is common cathode type.

PROCEDURE:
1.First we take 4 inputs and give them to BCD to 7 segment decoder IC 7447 at A, B, C and D.
2.Then, we connect its 7 outputs to common 7 segment display.
3.Now, attach 7 segment display with DC supply and give it 5 Volts.
4.We confirm outputs using truth table.
(Task 2 is done according to this procedure).

MAGNITUDE COMPARATOR:
Magnitude comparator is a digital circuit which is used to compare the magnitude of two number to check whether a
number is greater, smaller or equal. In this case we take two binary inputs A and B, and produces three binary inputs in
A>B (A is greater than B), A<B (A is less than B) and A=B(A is greater than B)and output will be shown by high (“1”) and
low (“0”) logic states. We compare the numbers in such a way that we compare the (MSB) most significant numbers if
they are equal then we compare next significant numbers and so on until we found the number is greater or smaller if
all the significant numbers are equal then high output will be show high (“1”) in A=B column, we will only consider first
input A0. Here we see an example of two inputs binary magnitude comparator.

CASCADE INPUT:
In some cases we have to compare the values of a large sized binary numbers, e.g we have to take 8 bit inputs of A and
B to get compared but we only have a 4-bit input magnitude comparator. In such a case we use cascade input it is a
combinational circuit which does the same work as magnitude comparator that it is used to compare two binary inputs
to check whether number is greater, smaller or equal but mainly it is used to break the comparison in order to easily
compare a large sized binary inputs, in such a way that first it compares four most significant numbers of A and B with
first 4 bit magnitude comparator then it compares the least significant numbers of A and B with the second 4-bit
magnitude comparator. So cascade input helps to break the comparison of larger binary inputs and the output of
comparator is then used as a cascade input to the next comparator in the series. For 4-bit comparator we take 8 inputs
and for 2-bit comparator we take 4 inputs. Here we see an example of cascading input.

Where X represents “don’t care”, H represents (“high”) and L represents (“low”).

PROCEDURE:
1. To verify the truth table for 4-bit comparator, we connect 8 inputs A0, A1, A2, A3, B0, B1, B2, B3 to IC 7485.
2. Now, we join its three outputs of QA < B, QA= B, QA > B to three LEDs to check its output.
3. On giving different inputs we verify outputs of 4-bit comparator using its truth table.
(Task 3 has done according to this procedure).
TASK RESULTS:
Task 1:
 You are required to design a 4-bit binary to grey code converter.
 Find out the resultant equations (using any technique) and draw equivalent logical diagram.
 Verify the truth table.
A.BINARY TO GRAY CODE CONVERTER: TRUTH TABLE:

RESULTANT EQUATION:
Equations to convert binary to gray code are:
g3=b3
g2=b2 b1
g1=b2 b1
g0=b1 b0
Here b 3 is 1st bit of 4-bit binary code, b 2 is 2nd bit, b 1 is 3rd bit and b 0 is 4th bit of 4-bit binary code which is to be converted
to gray code.
Similarly, g 3 is 1st bit of 4-bit gray code, g 2 is 2nd bit, g 1 is 3rd bit and g 0 is 4th bit of 4-bit gray code which is converted
from binary code.
B.GRAY CODE TO BINARY CONVERTER: TRUTH TABLE
RESULTANT EQUATION:
Equations to convert binary to gray code are:
b3=g3
b2=b3 g2
b1=b2 g1
b0=b1 g0
Here b 3 is 1st bit of 4-bit binary code, b 2 is 2nd bit, b 1 is 3rd bit and b 0 is 4th bit of 4-bit binary code which is converted
from gray code.
Similarly, g 3 is 1st bit of 4-bit gray code, g 2 is 2nd bit, g 1 is 3rd bit and g 0 is 4th bit of 4-bit gray code which is to be converted
to binary code.

Task 2:
 You have to display decimal numbers on 7 segment display using 7447/7446 IC.
 Verify results with truth table for BCD to 7-segment display.
7 SEGMENT DISPLAY USING 7447 IC:

TRUTH TABLE:

Task 3:
 You are given a 4-bit comparator IC (7485).
 You have to verify the truth table for 4-bit comparator.
4-bit comparator:
TRUTH TABLE:

CONCLUSION:
In this lab we have learnt concept of binary to Gray code converter and vice virsa, designing and implementing BCD to 7-segment display
and 4-bit Magnitude comparator. A code converter is a logic circuit that changes data presented in one type of binary code to another
type of binary code, such as BCD to binary, BCD to 7 segment, binary to BCD, binary to Gray code, and Gray code to binary. Furthermore,
Gray codes are widely used to prevent spurious output from electromechanical switches and to facilitate error correction in digital
communications such as digital terrestrial television and some cable TV systems. Seven segment displays are used in a wide range of
devices. Examples include simple calculators, digital clocks, microwave ovens, refrigerators, and plenty of other devices that display
numerals. Comparators are used in central processing units (CPUs) and microcontrollers (MCUs). Magnitude comparator is widely used in
CPU, microcontroller, combinational and communication systems and is specially designed to compare the relative magnitudes of binary
numbers.

You might also like