Please support this site: If you find this information useful, interesting, or entertaining, please help me by voting for my entry on the MyPIC32 contest, and learn more about Microchip's new line of 32 bit microcontrollers. By viewing a few of the contest entries each week you will be eligible for community prizes, such as an iPod Touch. Thanks!----------
Rotary Encoders are devices with a shaft which one can rotate that has output which will indicate either: the shaft's absolute position, or its relative position. The common computer mouse has two relative position rotary encoders The following is a dialogue between myself and Tom, who had a few questions about rotary encoders.
Generally there are two kind of rotary encoders:
The absolute position output will vary depending on the resolution and manufacturer. They may use a binary code (also look up references to 'grey code').
On a 16 position absolute encoder, with four outputs, the outputs may look like this:
OUT 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 OUT 2 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 OUT 3 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 OUT 4 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 Position 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
The relative position encoder will either put out a sine wave on both wires, with the second being 90 degrees out of phase with the first, or it puts out a square wave on both wires, as follows (You'll need to set the following to fixed width font to see it):
___ ___ ___ ___ ___ OUT 1 ___| |___| |___| |___| |___| |___ ___ ___ ___ ___ ___ _ OUT 2 _| |___| |___| |___| |___| |___| <--Clockwise Counter-clockwise-->
This square wave is basically a representation of a sine wave, 90 degrees out of phase. It is easy to interface, if you take OUT 1 and define it as your direction. If OUT 1 is high when a pulse starts on OUT 2, then the rotary encoder is going clockwise. If OUT 1 is low when a pulse starts on OUT 2, then the encoder is going counter-clockwise. A sine wave output encoder is good if you want a higher resolution than you can get from a square wave encoder. It would require more hardware or software to interpret, though.
I hope this helps!
Timing is based on the resolution of the encoder, and the speed at which it will be turned.
First, if we say the encoder is rotating at a constant speed, then generally the square waves are 50% duty cycle (depending, as always, on the manufacturer).
These encoders can come at different resolutions, meaning that every time you turn the encoder one revolution, it may put out 1 pulse on each channel, 10 pulses, 360 pulses or whatever the manufacturer designed it for. If you take a 360 pulse per revolution encoder, and turn it at 100 RPM, then you can expect 36,000 pulses per minute, or 600 Hz.
Let's say, for instance, you are creating an electronic etch-a-sketch, and the display resolution is 640x480. You decide that the user should have to turn the rotary encoder 4 turns to cross the screen horizontally, and three turns to cross the screen vertically. This means that the horizontal encoder must pulse 640 times in 4 revolutions, or 160 pulses per revolution. We will find that the vertical encoder needs to be 160 PPR too, which makes the project cheaper because we can buy in bulk. Now, through studies (i.e., we passed it around the office), we find that the fastest user can spin our control at 200 RPM (about 3 times a second). This means that we can get 32,000 pulses each minute, or we will be receiving 534 pulses per second. This gives us a minimum of 1.8 milliseconds to detect a pulse, easily detectable by a uController running at 32kHz, assuming we sample both inputs 4-10 times every 1.8mS.
I don't have any references to manufacturers. I know that many distributors sell them. For instance, you might refer to DigiKey and find out who they get their encoders from. A quick search turns up quite a bit:
I hope this answers your question, I wasn't exactly sure of what you were asking about the timing.
The relative rotary encoders have either square wave output or sine wave output:
Absolute encoders may use any of the above methods, possibly including additional electronics to encode the signal. For instance, using a regular sine wave output with one period per revolution, one can determine the absolute position of the shaft.
Higher resolution reading
You can also get more resolution out of an ordinary rotary encoder.
___ ___ ___ ___ ___ A ___| |___| |___| |___| |___| |___ ___ ___ ___ ___ ___ _ B _| |___| |___| |___| |___| |___| <--Clockwise Counter-clockwise--> ^ ^ ^ ^
I've added arrows below the signal to highlight that there are 4 transitions for each full pulse. A 200 pulse per revolution encoder has 800 transitions. This method requires that you keep track of the current state of the two outputs, and the previous state of the two outputs.
If the previous state was A=1, B=1, and the encoder then outputs A=0 and B=1 then the encoder has moved one transition clockwise. There are only four possible states for the encoder to be in:
A B 0 0 0 1 1 1 1 0
So by keeping track of what the encoder was outputing last time you checked, and comparing it with this time you can determine whether it has moved by 1/4 of a pulse.
Some other unique methods of determining absolute position: