Gray Code Converter for Absolute Encoders
Convert between binary and Gray code, as used by absolute encoders, and see the encoder position in degrees for its resolution.
- Gray = binary XOR (binary shifted right 1) = 0100101100 XOR 0010010110
- Gray = 0110111010
Gray Code Conversion
Binary: btop = gtop, bn = bn+1 XOR gn
Angle = position ÷ 2bits × 360°
B is the binary value and >> a right shift by one bit. In Gray code only one bit changes between neighbouring positions, so an encoder read during a transition is never off by more than one step.
Worked example
Position 300 on a 10 bit encoder is Gray 0110111010 (0x1BA) and corresponds to 105.47°.
Frequently Asked Questions
Why do encoders use Gray code?
Only one bit changes per step, so reading the code while it changes cannot produce a wildly wrong position.
How do I convert Gray to binary in a PLC?
Start from the top bit and XOR each Gray bit with the previous binary bit, or use a loop with shifts and XOR.
Do SSI encoders send Gray code?
Many SSI encoders can send binary or Gray; it is usually a configuration option in the encoder.
Learn more on the blog
Introduction to number systems
A practical, field focused guide on instrumentationblog.in that explains the theory behind this calculator and how engineers apply it on real plants.
Read Full Article