Thanks for sharing! Sounds like Gray code with twos complement math to me. If you've never heard those two terms then I think you should be justly proud in having come up with the solution on your own- it shows insight into what's actually going on under the hood, so to speak. Mike H. On Tue, Oct 11, 2011 at 8:08 AM, 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. > > If anyone is interested, I can post the code. But my guess is I have > just on my own rediscovered an old > method of decoding rotary encoders. > > > Regards, > > Jim > > > > -- > http://www.piclist.com PIC/SX FAQ & list archive > View/change your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist > --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .