I also had problems with contact bounce on rotary encoders, so I use the state machine described at http://www.piclist.org/techref/microchip/qenc.htm Harold > Hi there, Jim. > > You have discovered the easiest way to read a quadrature > encoder. This is the same technique that I first used many years ago > when feeding an encoder directly into hardware: treat one of the > encoder phases as the clock signal and use the other phase as the up > / down direction control. > > Although it does work, it suffers from poor noise rejection if you > have any contact bounce on the clock phase and will lead to erroneous > 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 > when dealing with a noisy encoder. The technique I use now is to > monitor both encoder phases for a change, then feed both phases into > a state machine. Illegal state changes (such as those caused by > noise or contact bounce) are ignored and I get to use the full > resolution that the encoder offers - this is 4 times the resolution > that your technique offers. > > By all means - if your technique works for your application, use > it. Just keep in mind the alternative options if contact bounce > 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. > > > -- > 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 > > -- > http://www.piclist.com PIC/SX FAQ & list archive > View/change your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist > --=20 FCC Rules Updated Daily at http://www.hallikainen.com - Advertising opportunities available! --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .