What are Quadrature Encoders
Quadrature Encoders are handy sensors that let you measure the speed and direction of a rotating shaft (or linear motion) and keep track of how far you have moved.
A quadrature encoder normally has at least two outputs - Channel A and B - each of which will produce digital pulses when the thing they are measuring is in motion. These pulses will follow a particular pattern that allows you to tell which direction the thing is moving, and by measuring the time betewwn pulses, or the number of pulses per second, you can also derive the speed.
Let's start with an animation showing how the quadrature encoder inside the HUB-ee wheels works.
This animation shows what it is like inside our HUB-ee wheels. They have a black and white reflective code wheel inside the wheel rim, and the PCB has a pair of reflective sensors that point at the code wheel. These sensors have just the right spacing between them, and relative to the stripes on the wheel, to produce the pattern of pulses you see in the animation.
In technical terms these pulses are 90 degrees out of phase meaning that one pulse always leads the other pulse by one quarter of a complete cycle (a cycle is a complete transition from low -> high -> low again.
The order in which these pulses occur will change when the direction of rotation changes. The two diagrams below show what the two pulse patterns look like for clockwise and counter clockwise rotation.
So how do you actually work out the direction?
Lets start with channel A at the top (clockwise rotation):
1 Channel A goes from LOW to HIGH
2 Channel B is LOW
You are going CLOCKWISE!
Now take a look at channel A when going counter clockwise:
1 channel A goes from LOW to HIGH
2 Channel B is HIGH
You are going COUNTER-CLOCKWISE!