Gray codes

What are they?

This is what I’ve read:

With Gray codes, from one sequential number to the next, only one digit changes, and that one digit changes by one.

So one possible Gray code sequence would be 0000, 0001, 0011, 0111, etc.

OK, so what are the practical applications of Gray codes. Martin Gardner, who normally does a pretty good job of explaining esoterica, had a good explanation of Gray codes in some of his books, but not so good a job of showing their use.

The main thing I have used them for is transmitting A->D data (rotational position info for example) where I am unsure of the line quality. If 2 or more bits are different from the previous sample, you have an error. Single errors can also be easily corrected.

Based on some hazy recollections from my undergraduate days, I think they have an application in digital circuit design. If you have multiple inputs changing at once, you can get race conditions. That is, based on slight timing fluctuations in the circuit, you might get transient incorrect states. If only one input can change at a time, your problems are reduced or eliminated.

I’m not sure gray code reduces the risk of a race condition, but it certainly helps to detect an error that may be the result of a race condition.

Aside from error dection, another common application for gray code is to reduce the power consumption of digital circuits. Many functions are counting up or counting down operations. The fewer bits that change at one time, the lower your power consumption.

FWIW, the only Gray code I have seen was an encoder strip in a 15-year old piece of equipment. The encoder was painted on glass with photointerrupters reading the slots. The Gray code minimized the potential for positioning errors due to encoder wear.