Gray Code for Rotary Incremental Encoders

Gray code was named for Frank Gray, a Bell labs researcher, who patented the procession in 1953,  even though a form of it was used by Emile Baudot for telegraphy as early as 1878.

The most important thing to understand about Gray code is that only one bit changes from transition to transition.   In binary it is possible for a number to go from all ones to all zeros, as is the case with 11111111 (255 decimal)  going back around to 00000000 (zero).

Dec           Bin                    Gray
0              0000                0000
1              0001                0001
2              0010                0011
3              0011                0010
4              0100                0110
5              0101                0111
6              0110                0101
7              0111                0100
8              1000                1100
9              1001                1101
10            1010                1111
11            1011                1110
12            1100                1010
13            1101                1011
14            1110                1001
15            1111                1000

Notice how only one of the 0’s or 1’s of the Gray code change as the number increments?  In binary there are times when all of the bits change, (0111  to 1000 (Seven to Eight ) and 1111 back to 0000 (Fifteen to Zero) ).

Error Checking

The advantage to only one bit changing in Gray code is that it gives you error-checking ability.  If you sum the number of bits the bit total will always change by only one.

You could also do some error checking knowing that the bit sum will always alternate between even and odd.

Gray      Bit Sum
0000         0
0001           1
0011           2
0010           1
0110           2
0111            3
0101            2
0100           1

Gray Code in Incremental Encoders

The A & B channels of Incremental Encoders are in quadrature, which makes a two-bit gray code progression.  Depending on direction, the Incremental Encoder bit progression with be a cyclical pattern of either 00 – 01 -11 – 10  or  00 – 10 – 11 – 01 – 00.

Only one bit changes from transition to transition.

The QD787 absolute encoder shown at the top of this post has an option for an eight bit Gray code output.

Links to more information on Gray code:

http://encyclopedia2.thefreedictionary.com/Grey+code

http://www.itl.nist.gov/div897/sqg/dads/HTML/graycode.html

http://mathworld.wolfram.com/GrayCode.html

Sample C code:

http://www.nrbook.com/a/bookcpdf/c20-2.pdf

WIKI:

http://en.wikipedia.org/wiki/Gray_code#Constructing_an_n-bit_gray_code

For more information on encoders, go to http://www.quantumdev.com

Jim can be reached at:  jmiller@quantumdev.com

Advertisements

About Quantum Devices Inc.
Quantum Devices, Inc. (QDI) Barneveld, WI, was established as a Wisconsin corporation in October 1989, as an outgrowth of activities in the general area of optoelectronics. The main goal of QDI is to provide customers with a complete source for all stages of product design and development, starting from concept to a marketable commodity. These products include application specific Silicon Photodiodes, Optical Encoders and Light Emitting Diodes (LED) for commercial, industrial and medical applications. QDI's photodiodes and LED's are used in instrumentation for photosynthesis and photobiological research, biomedical and medical instrumentation for measuring blood sugar levels (glucometer), oxyhemoglobin and pulse rate (pulse oxymeter). One of the most dramatic products developed at QDI was the application of LED lighting systems for use as the light source for Photodynamic Therapy (PDT). Sales of QDI products include both domestic and international markets. Quality and reliability are very important concepts in maintaining our company wide commitment to overall product performance. Quality simply means continuous process improvement. We are committed to continually increasing our product excellence through increased quality and reliability. Quantum Devices, Inc. is ISO 9001 certified and the ISO Standard will provide the guidance for the vital function of maintaining our commitment to constantly improve our product quality. Quantum Devices is now proud to introduce it's new line of rotary encoders. Incorporating QDI's patented sensor technology, our QPhase™ Family of Encoders feature high resolution, increased frequency response and superior reliability over temperature (0 to 120 degrees C). QDI incremental and absolute encoders set a new standard and are backed by a 2 year factory warranty. We invite you to request an evaluation unit, additional information or price quotations. Mission Statement Quantum Devices is dedicated to the principle that light provides the power for all life on earth. We believe the quality, delivery and control of light is essential to the wellness of man and his advancement into the future.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: