Hi there, Jim. You have discovered the easiest way to read a quadrature=20 encoder. This is the same technique that I first used many years ago=20 when feeding an encoder directly into hardware: treat one of the=20 encoder phases as the clock signal and use the other phase as the up=20 / down direction control. Although it does work, it suffers from poor noise rejection if you=20 have any contact bounce on the clock phase and will lead to erroneous=20 counts. It also does not give you the maximum possible encoder resolution. I don't use that technique any more because I got bit once too often=20 when dealing with a noisy encoder. The technique I use now is to=20 monitor both encoder phases for a change, then feed both phases into=20 a state machine. Illegal state changes (such as those caused by=20 noise or contact bounce) are ignored and I get to use the full=20 resolution that the encoder offers - this is 4 times the resolution=20 that your technique offers. By all means - if your technique works for your application, use=20 it. Just keep in mind the alternative options if contact bounce=20 rears its ugly head at some time in the future. dwayne At 08:08 AM 10/11/2011, jim@jpes.com wrote: > All, > > I have been working with a rotary encoder that I am planning to use as >a control for a piece of test > equipment at work. I have looked on the web for algorithms to decode >the outputs of said encoder, > and have found several. Most of them work as advertised in my >application, but I have come up with a > version that works very well in my opinion. > > I don't know whether it is new or novel, but all I have done is watch >for the "A" output to go high. > When it does, I then read the port that the encoder is attached to. I >mask of the bits I am interested > in, and use this as an index into a table. If the value is "01" I add >"1" to my variable. If the value > is "10", I subtract "1" by adding 255. Any other combination "00" or >"11" adds a zero for no change. > > I have tried this out spinning the knob on the encoder as fast as I >can, and I can't see any missed > counts. I am using a delay of 2.5 mS in my routine for debouncing. --=20 Dwayne Reid Trinity Electronics Systems Ltd Edmonton, AB, CANADA (780) 489-3199 voice (780) 487-6397 fax www.trinity-electronics.com Custom Electronics Design and Manufacturing --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .