An encoder is a device that counts occurances in a certain way. The most common application is as light and dark segments on a rotating disc, though there are linear encoders.
The way they work is by sending a "high" or "low" signal indicating whenever the light and dark regions pass the detector. You can count them up to find what distance you've traveled or count the rate and determine a speed.
The problem with a simple encoder is that it can tell you number of signal switches and/or rate of change, but it cannot tell you direction. To get direction, a 2nd detector is offset (usually 90 degrees out of phase --
note: this is not 90 degrees on the wheel, but 1/4 of the way through a cycle of high and low) so you can determine the direction of motion. These are commonly known as the "A" and "B" channels.
An example of how this would work is
Code:
Forward Reverse
A - low ; B - low A - low ; B - low
A - high; B - low A - low ; B - high
A - high; B - high A - high; B - high
A - low ; B - high A - high; B - low
A - low ; B - low A - low ; B - low
As you can see, the direction can be determined by looking at which signal is leading (changing first). This is what's know as a
quadrature encoder.
As far as line counts, it's a balancing act. The more lines you have, the greater precision you can get, which is a good thing. But this can cause problems too. With very small divisions, your encoder is subject to "noise" in its measurement. Any small misalignments or vibrations can be enough to cause the signal to behave in erratic ways. Fewer line counts reduce the probability of this occuring. The other drawback to a high number of line counts is the signal processing rate of your controller. If you're spinning so fast, you send 100,000 line counts past your detectors, your system may not be able to count that fast, and then your signal will become garbled as the controllers struggles to keep up.
So, more lines = better precision. Less lines = cleaner signal. We typically use 100 line count encoders for direct motor output since we gear down the motors and 360 line count encoders for more precise measurements on devices that don't move as fast.