There are a few tricks to using quad encoders. The main problem is that mechanical encoders can be noisy when they are turned, or the lines from the encoder can be corrupted by ESD, AC hum, line noise. The way to solve these issues is to sample 5 times and accept the data change only after the data is stable; to verify that it is stable, read it at least 5 times in a row, and all five captures must have the same result. Using a PIC makes this easy. --Bob On Sat, Sep 5, 2009 at 4:54 PM, Josh Koffman wrote: > Hi all. I've been working on a new project using mechanical rotary > encoders. I wrote a new encoder reading routine based on the info I > found in this document: > http://www.tufts.edu/programs/mma/emid/RotaryEncoder.pdf. The method > is to compare the LSB of the current reading to the MSB of the last > reading, XOR them together, and from there you will be able to > determine an up or down motion. > > It works quite well. A bit too well in fact... > > For each movement of the encoder I'm getting too many events in my > code. From my understanding of the datasheet it should be one detent =3D > one pulse. For each detent I currently get about 4 events. I've > written the manufacturer of the encoder just to double check, but I'm > guessing the problem lies in my work somewhere. > > I'm currently in Brazil so I don't have access to my scope or analyzer > so I can't verify if I'm actually getting more pulses than I should > be. Is it possible I'm getting contact bounce on the encoder and my > code is reading those as turns? What's interesting is that it's almost > always 4 events. I call the routine in a timer trigger interrupt, and > I've played with the values just to see what would happen. I expected > that the number of extra events would change, but it seems to always > be 4. Occasionally it's 3, but only rarely. > > Does anyone have any suggestions on what might be going on and how I > might be able to fix it? > > Thanks! > > Josh > -- > A common mistake that people make when trying to design something > completely foolproof is to underestimate the ingenuity of complete > fools. > =A0 =A0 =A0 =A0-Douglas Adams > -- > http://www.piclist.com PIC/SX FAQ & list archive > View/change your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist > -- = http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist