BINARY TO GRAY CODE ·CONVERTER

DEPARTMENT OF ELECTRICAL POWER TECHNOLOGICAL UNIVERSITY
PAKOKKU JULY, 2007

BINARY TO GRAY CODE CONVERTER

DEPARTMENT OF ELECTRICAL POWER TECHNOLO.GICAL UNIVERSITY PAKOKI(U JULY, 2007

BINARY TO GRAY CODE CONVERTER
BY

UAUNGTHATTUN DEMONSTRATOR (E.P) A.GT.I (E.P)

B.Sc ( Physics)

TECHNOLOGICAL UNIVERSITY

5 2.4 1:6 18 19 CHAPTER IV RESULT AND DISCUSSION REFERENCES 20 .1 3.CONTENTS Page ACKNOWLEDGEMENT ABSTRACT LIST OF FIGURES LIST OF TABLES CHAPTER I CHAPTER II INTRODUCTION BACKGROUND THEORY The Gray Code Gray Code Application Karnaugh Map The Exclusive-OR Gate LED Exclusive-OR Gate (74LS86 IC) 1 2.1 2.2 2.6 CHAPTER III OPERATION OF THE SYSTEM Gray Code Karnaugh Maps Gray Code Conversions Required Equipment 3.2 3.4 2.3 4 8 10 13 14 2.3 3.

Pakokku.ACKNOLEDGEMENT t. Teclmological University. I The author would be greatly indebted to Daw Mi Mi Aung Lecturer and Head of Department of Electrical Power. Technological University.E U Thaung. . Pakokku for accepting and giving guidance. Minister. r The authors wish to express their deep gratitude to I-I. Pakokku for her kindly permission. The authors would like to express the heart felt gratitude to Dr Shwe Sin Htay. Ministry of Science and Technology for the opening for Technological University. i Principle.

The conversion between Gray Code and binary code are done by using Karnaugh Map. the more possible combinations of output codes. . the conversion c~ be done simply with exclusive-OR gates. By using this method. The difference between the Gray Code and the regular binary code is that the Gray Code varies only 1 bit from entry to the next entry.ABSTRACT The Gray Code is useful code used in digital systems. This code is like binary in that it can have as many bits as and the more bits. It is used primarily for indicating the angular position of a shaft on rotating machinery such as automated lathes and drill presses.

4 Logic circuit for providing the exclusive-OR function 12 Exclusive-OR built with and AND-OR-NAND combination Logic symbol and equation for the exclusive-OR Logic symbol for exclusive-OR gate Pinout Diagram ofa 74LS86 Ie Binary To Gray Code Circuit Diagram for Binary to Gray Code Converter Photo of Binary to Gray Code Converter 14 18 19 20 Figure 2.LIST OF FIGURES Page Figure 2.7 Figure 3.3 Figure 2.1 Figure 2.1 Figure 3.5 Figure 2.2 Gray Code Wheel Karnaugh Maps (a) Two-variable (b) Three-variable (c) Four-variable 5 9 Figure 2.6 Figure 2.3 .2 Figure 3.

LIST OF TABLES Page Table 2.1 Table 2.2 Table 3.1 Four Bits Gray Code Truth Tables for an OR Gate versus an Exclusive-OR Gray Code Gate 3 11 15 .

etc. The Binary is commonly used in digital system and the conversion of ~ to Gray is done simply with exclusive-OR gates by using Karnaugh maps. Digital electronic involves quantities with discrete values and analog electronics involves quantities with continuous values. The two state numbers system is called binary and its two digits are 'O'and'l'. alphabetical characters and other types of information. opened and closed switches.. Digital electronic involves circuits and systems in which there are only two possible states representing two different voltage levels ( High / Low).CHAPTER I INTRODUCTION Electronic circuits can be divided intotwo broad categories. ASCII. symbols.Y~ . In digital system combinations of two states called codes are used to represent numbers. digital and analog. BCD. ~ There are many specialized codes used in digital systernsw such as Binary. BIt·)Q. Gray.

3 Table 2.1 Four Bits Gray Code Decimal . 4 5 6 7 8 9 10 11 12 13 14 15 . Binary Gray Code 0 1 2 3 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111 0000 0001 0011 0010 0110 0111 0101 0100 1100 1101 1111 1110 1010 1011 1001 1000 .

the Gray code can have any number of bits. while the binary code changes from 0011 to 0100. a change of three bits. The only bit change is in the third bit from the right in the Gray Code. . the others remain the same. Binary numbers are shown in the table for reference. The important feature of the Gray Code is that it exhibits only a single bit change from one code word to the next in sequence. For instance. This property is important in many applications. there are no specific weights asssigned to the bit positions.1 The Gray Code The Gray Code is unweighted and is not an arithmetic code: that is.CHAPTER II BACKGROUND THEORY 2.1 is a listing of the 4-bits Gray Code for decimal numbers 0 through 15. such as 'shaft position encoders. in going from decimal 3 to 4. Table-2. Notice the single bit change between successive Gray Code words. the Gray Code changes from 0010 to 0110. Like binary numbers. where error susceptibility increases with the number of bit changes between adjacent numbers ina sequence.

1. The difference between the Gray Code and the regular binary code is illustrated in table 2. out of 16 possible angular positions 'at 22. the code reads from one position to the next would vary by only l-bit. Notice in the table that the Gray Code varies by only l-bit from one entry to .5). . giving a resolution of one . for example. This code is like binary in that it can have as many bits as necessary and the more bits. . the more possible combinations of output codes ( numbers of combinations = 2 N ) are also available.4 2. if each Gray Code represents a different position on a rotating wheel. . Now. the next and from the last entry (15) back to the beginning (0). as the wheel turns.5 degrees each (360/16=22. A 4-bits Gray Code. will have 24 = 16 different representations. It Is used primarily for indicating the angular position of a shaft on rotaitng machinery such as automated lathes and drill presses.2 Gray Code Application The Gray code is a useful code used in digital systems.

5 ~ \ \ 0 0 0 0 ~ o OUTPUT 41' OUTPUT '0' Figure 2.1 Gray Code Wheel .

but since all 4-bits are changing ( 0 to 1 or 1·to 0 ) the code that it reads may be anything from 0000 to 1111. regradless carries. as the wheel turned from 7 to 8. Therefore. either a 0100 is read or a 1100 is read ( no problem ). the following rules apply. so if a read is taken right on the border between the two numbers.6 If the same wheel labeled in binary. when the position changes from 7 to 8. the code changes from 01DOto 1100. The MSB is the only bit that changes. To convert a binary number to a Gray Code number. on the other hand. the potential for an error using the regular binary system is great. the code would change from 0111 to 1000. With the Gray code wheel. it might see 0111 or 1000. The most significant digit ( Left Most Bit) in the Gray Code is the same as the corresponding digit in the binary number. 1. add each adjacent pair of binary digits to get the next Gray code digit. Going from left to right. If the digital machine happened to be reading the shaft position just as the code was changing. 2. .

The left most Gray digit is the same as the left most binary digit.Add the left most binary digit to the adjacent one. .7 For instance Step 1 .1 Step 3 1 0 1 o Binary Gray .Add the next adjacent pair 1 0 +1 Step 4 1 1 Gray 1 -Add the last adjacent pair 1 0 1 +0 1 1 0 Binary 1 1 1 1 Binary Gray The conversion is now complete and the Gray Code is 1111.Let us convert the binary number 1010 to Gray Code. 1+0 1 1 1 o Binary Gray . . 1 1 Step 2 .

In that casetheAC remained the same and only the B change to B.-- . . Each cell within the K-map corresponds to a particular combination of the input variables. The upper left -----cell is ABC. is another method of simplifying logic circuits. A two variable map will require 22= 4 cells. teclmiques. three.cumbersome and can be more practically solved using advanced computer . and the lower right cell is AB. Also notice that when moving from one cell to an adjacent cell. The same holds true for each adjacent cell. but from that a sytem approach which will always produce the simplest configuration possible for the logic circuit. five or six different input variables. For example. Solving five and six variable K-maps is extremely . A Kamaugh map (K-map ) is similar to a truth table in that table in that it graphically shows the output level ofa Boolean equation for each of the possible input variable combinations. Each output level is placed in a separate cell of the K-map.8 2. Determining the number of cells in a K-map is the same as finding the number of combinations or entries in a truthe table. A three variable map will require 23 = 8 cells. the adjacent cell just below it isABC. only one variable changes. K-maps can be used to simplify equations having two. Teh three different K-maps are shown in figure 2.2. For example. . A four variable map will require 24 = 16 cells. four.3 Karnaugh Map Kamaugh map named for its originator. look at the three variable K-map. the upper left cell corresponds to . in the two variable K-map. the upper right cell is AB. AB the lower left cell is AB. It still requires to reduce the equation to a sum-of-products ( SOP) form.

2 (c) Four variable .2 (b) Three variable CD CD CD CD AB AB AB AB Figure 2.2 (a) Two variable C AB AB AB AB C Figure 2.9 B A A B Figure 2.

10 2. The exclusive-OR gate is common enough to deserve its own logic symbol and equation. The Boolean equation for the exclusive-OR function is written X =AB+AB and can be construsted using the combinationl logic shown in figure 2. This point is made more clear by comparing the truth tables for an OR gate versus an exclusive-OR gate.shown in figure 2. the other combinations of the basic gates that provide the exclusive-OR function. Note .The shorthand method of writing the Boolean equation is to use a plus sign with a circle around it.4 The Exclusive . provides a HIGH output if one input or the other input is HIGH but not both. The exclusive-OR.3.OR Gate The OR gate provides a HIGH output if one input or the other input is HIGH. . as shown in table 2.5. By experimenting and using Boolean reduction. the combination of A~. OR andNAND gates shown in figure2. or ifboth input are HIGH.4 will reduce to the "one-or-the-other-butnot-both" (X-OR) function. For example. on the other hand.2.

11 Table 2.2. Truth Tables for an OR Gate Versus an Exclusive-OR Gate A' B X 0 0 1 1 o· 1 (OR) 0 1 0 1 1 1 A 0 B 0 1 X 0 1 0 1 0 1 (Exclusive-OR) 1 1 0 .

4 Exclusive-OR builts with andAND-OR-NAND combination X=A(±)B = AB +AB Figure 2.. l--X X=A'B (A+B) X=(A+B)(A+B) X = AA+AB+BA+BB X=AB+AB Figure 2.5 Logic symbol and equation for the exclusive-OR .3 Logic Circuit for providing for exclusive-OR funciton.12 A~----l AB ._X AB+AB B -----'----1 AB Figure 2.

Because free electrons recombine with holes near the junction. LEDs may be connected the common anode type and common cathode type. The size of this resistor determines how much current flows through the LED. By using elements like Gallium. As the free electrons fall from a higher energy level to a lower one. A LED emits radiation when forward-biased. a manufacture can produce LEDs that produce visible radiation are useful in test instrument.yellow. (Typical LED current is between 1 and 50 rnA). pocket calculator. The conunon anode type connects a current limiting resistor between each LED and ground. blue. etc. Arsenic and Phosphorus.13 2. LEDs emit red. orange and infrared (invisible) light. green.5 LED LED is a light emitting diode. they gives up energy in the from of heat and light. The comrnon cathode type uses a current-limiting resistor between each LED and +Vcc. .

This digital integreated circuit (IC) contains four 2-input exclusive-OR gate inside a 14-pin dual-in-line package (DIP ).Ok gate .for exclusive .7 Pinout diagram ofa 74LS86 Ie .6.Figure 2.6 Logic symbol.6 Exclusive-OR Gate ( 74LS86 rc ) The pinout diagram ofa 74LS86 IC. . + Vcc GND Figure 2. a TTL quad 2-input exclusive-OR gate is shown in figure 2..14 2.

1 Binary Decimal A B 0 C D Gray Y3 I Y2 ' Y-l '0 YO '0 0 1 2 3 4 5 0 0 0 0 0 0 0 0' 1 0 ' .." 0 0 0 1 0 1 1 0 0 0 0 0 1 1 1 1 0 0 1 0 1 0 0 0 0 0 0 1 1 Ii 1 0. 1 0 .15 CHAPTER III ' OPERATION OFTHE SYSTEM 3.1 Gray Code Table 3. 0 1 ~ 0 0 1 6 7 8 9 10 11 12 13 14 0 0 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 1 1 1 1 1 I " 0 1 1 0 0 1 1 0 0 1 l' 1 0 1 0 0 1 1 1 0 0 '1 1 J 0 0 1 1' 0 0 I 1 1 15 1 0 1 0 1 1 1 1 1 1 0 0 0 1 1 0 0 .-0 -. 0.

2 Karnaugh Maps For practical consideration code conversions are made for each bit.16 3. (a) For Y3' the Karnaugh map can draw as follow. CD CD CD CD AB AB AB AB 0 0 0 0 1 0 0 1 0 0 1 1 1 - 1 1 1 (a) By minimization. Y3=A (b) For Y2' the Kamaugh map can draw as follow. Y2 =Ac:BB . 'CD CD AB CD CD 0 0 0 0 1 0 1 AB AB AB (1 0 1 0 1 1 0 J - (1 1) (b) By minimization.

(d) For YO' the Karnaugh map can draw as follow. CD CD AB AB 0 0 0 0 1 1 1 1 1 1 1 1 AB AB - (b) By minimization. CD CD AB AB AB AB 0 1 0 1 - CD CD U 0 0 0 0 1 0 1 0 n YI =Bc±)C CD CD 0 0 0 0 (a) By minimization. YO=C(BD .17 (c) For Yl' the Karnaugh map can draw as follow.

1 Binary-to-Gray Code ABeD are used as Binary inputs and D stands for LSB and A stands for MSB corresponding output Gray Code take from '3 '2\}'0..3 Gray Code Conversions By Karanugh map minimization the conversion circuit can be ( 'De as followed by using 3 exclusive-OR gates . four slide switches are used and up position corresponds to 1state and down position corresponds to 0 state. For exclusive-OR gate 7486( quad-X-OR) IC is used and for power supply.2. For Binary input. The pins connections and the whole circuit block diagram is shown in figure 3. .: Binary Input A B C D Yo Gray Code Output Figure 3. 3AA dry cells are used for simplicity.18 3. .

2 Circuit diagram for Binary to Gray Code Converter. Universal Chip 1 No 1 No 8 Nos 8Nos 3 Nos 1 No ABC D Vcc(+4.4 Required Equipments 1.5v) 14 13 12 11 10 9 8 1234567 Figure 3.19 3. Pin Base 3. 74LS86 IC 2.5 Volt Battery 6. . 1. Resister 330 ohm 4. LED 5.

20 Figure 3.3 Photo of Binary To Gray Code Converter .

we can control the shift's angular positions in 16 positions and the degree e between two adjacent positions is 22. it can work only using the exclusive-OR gates. Code conversion takes part an important role in digital system. Not only conversion to Gray code. . For de 4. Normally IC supply voltage must be 5V by using power supply circuit. digital (Ijstate can get by using de 4. The circuit diagram is very simple and only use an 74LS8q IC . other code conversion can be done by using this way.CHAPTER 4 RESULT AND DISCUSSION :)ecimal to Gray code converter converts correctly decimal 0 0 0 0 to 1 1 1 1 into Gray code. But the result ofKarnangh rnap minimization. serial combination of3 AA dry cells are used to supply the Ie.5 V. If 5-digits Binary numbers are used.5 V. By using 4-digits Binary number.25°. For example.5 .Code conversion for 5-digits Binary numbers can be done like this way. the 32 shaft's angular position can be controlled and the degree between two adjacent positions may be 11. Un less the Karnaugh map is used. many ~ates may be used. conversion to ASCII code is also possible. But for digital circuit. This project is the first step for code conversion and another code conversion can do in future projects based on this way.

R.L (2003): "Digital Fundamentals" (Prentice Hall) . R. Thomson Asia Pte. 6.Ltd) Duncan. Bignell. Thomas.REFERENCES 1. T. (2000): "Practical Electronics Handbook" 2. (2001 ):"Digital Electronics" (Singapore. 4. I.C. A. D.) Malvino.P. Maini.Al' and Leanch. J and Donovan. 3.(l999):"Success in Electronics" (London:~urray) Floyd.K. (2002):"Digital Electronics Principles and Applications" (Delhi. Khanna. (1988):"Digital principls andApplications" (Singapore: ~c Graw-Hill) Sinclair. 5. .

Sign up to vote on this title
UsefulNot useful