The component - Rotary or Quadrature encoder:
A rotary or "shaft" encoder is an angular measuring device. It is used to precisely measure rotation of motors or to create wheel controllers (knobs) that can turn infinitely (with no end stop like a potentiometer has). Some of them are also equipped with a pushbutton when you press on the axis (like the ones used for navigation on many music controllers).
How does it work:
On one side of the switch there are three pins. They are normally referred to as A, B and C. Inside the encoder there are two switches. Once switch connects pin A to pin C and the other switch connects pin B to C. In each encoder position, both switches are either opened or closed. Each click causes these switches to change states as follows:
- If both switches are closed, turning the encoder either clockwise or counterclockwise one position will cause both switches to open
- If both switches are open, turning the encoder either clockwise or counterclockwise one position will cause both switches to close.
the angular position of the A terminal and the B terminal is such that:
- Rotating the switch clockwise will cause the switch connecting A and C to change states first.
- Rotating the switch counterclockwise will cause the switch connecting B and C to change states first.
Essentially, determining which switch changed states first is how the direction of rotation is determined. If A changed states first, the switch is rotating in a clockwise direction. If B changed states first, the switch is rotating in a counter clockwise direction.
With a rotary encoder we have two square wave outputs (A and B) which are 90 degrees out of phase with each other. The number of pulses or steps generated per complete turn varies.
Every time the A signal pulse goes from positive to zero, we read the value of the B pulse. We see that when the encoder is turned clockwise the B pulse is always positive. When the encoder is turned counter-clockwise the B pulse is negative. By testing both outputs with a microcontroller we can determine the direction of turn and by counting the number of A pulses how far it has turned. Indeed, we could go one stage further and count the frequency of the pulses to determine how fast it is being turned.