Using Gray code for rotary encoders
Gray code is well known and widely used in angular movement systems where angular positions has to be known. Gray code encoder can be constructed pretty easily by masked wheel where tracks are read with photocells.
Did you look at the picture and thought for yourself that gray code is same binary code. Well no… main problem with binary system that using binary code in tracks there are many positions where several tracks change state at same time. This may result in error. Actually in gray code only one track can change at same time during rotation. So then if error occur, the resulting erro will be only one bit. Gray code is easy to convert to binary this task can be done by any microcontroller using a lookup table:
Also you can convert Gray code to binary analytically. To convert from binary to Gray, start at the MSB and compare it to 0. If MSB is equal to0, then write 0 as the MSB for the Gray coded number, otherwise write 1. Next compare the next MSB and compare it to the MSB. If they are equal write a 0 in the position for the Gray coded number, otherwise, 1. Then compare each bit in the binary number to the bit just to the left of it and write 0 for a true comparison and 1 for a false. This procedure continues until the LSB is compared with the second bit.
The image bellow shows a 5-bit rotation encoder, using a Gray-code pattern and an optical sensor.

(http://tams-www.informatik.uni-hamburg.de)
Blogsphere: TechnoratiFeedsterBloglines
Bookmark: Del.icio.usSpurlFurlSimpyBlinkDigg
RSS feed for comments on this post | TrackBack URI for this post
New on WinAVR Tutorial
Running TX433 and RX433 RF modules with AVR microcontrollers,Sometimes in embedded design you may want to go wireless. Might be you will want to log various readi …Programming AVR ADC module with WinAVR,Most of AVR microcontrollers have Analog to Digital Converter (ADC) integrated in to chip. Such solut … |
New on WinARM Tutorial
What are differences between WinARM and WinAVR,Everyone who is working with AVR microcontrollers knows this powerful tool – WinAVR (http://win …LPC2000 watchdog timer,As in all microcontrollers watchdog timers purpose isto reset microcontroller after reasonable amount … |

September 11th, 2007 at 12:31 am
[...] Gray code for rotary encoders - [Link] Filed in [...]
January 29th, 2008 at 12:07 am
> The image bellow shows a 5-bit rotation encoder,
> using a Gray-code pattern
Actually, that is a 5 bit binary pattern. It shows one of the apparent impracticalities of binary encoding patterns; the inner ring has a very high ‘frequency’.
The image on top of the article shows a Gray pattern. Note the lower ‘frequency’ of the inner ring.