# How to implement a “rotary switch” like in audio equipment?

for my current project I'm planning to use an input "device" like this in the photo (don't know its real name):

It is used in a lot of musical instruments and it is like a potentiometer that can be rotated as many times as you want. I think it isn't read like an analog value. Can someone give me some hints?

Thank you very much.

• It's also used in measurement equipment like scopes and logic analyzers, for instance. – stevenvh Dec 25 '10 at 16:56
• I believe that in the A/V world, that's called a jog wheel. – JustJeff Sep 29 '11 at 12:15
• If your mouse has a scroll wheel, that's essentially the same thing, just turned on edge. – markrages Sep 29 '11 at 15:24

It's a rotary encoder. It has two outputs giving pulses in quadrature (see image), as to determine the way it's rotated.

In the image you can see that the level of the B channel is low on the rising edge of the A channel if the knob is rotated clockwise, but high if rotated counterclockwise.
Differences in models are the number of pulses per rotation, often between 15 and 20, and the number of channels. More than 2 channels are used to obtain the absolute position of the knob. E.g. 10 channels give 1024 unique codes per rotation. Gray coding is used.
edit
Another parameter is the detent. Detents are click-positions, which require a certain momentum to overcome. Some models have 2 detents per pulse, others don't have detents and rotate rather smoothly, so that it feels like a potmeter without stops.

"Control Shaft Encoders" $-$ Circuit Cellar issue 250, May 2011, p.28 ff

• thank you! do you know if it is possible to buy it with the plastic part attached? – 3mpty Dec 25 '10 at 15:05
• The encoder as sold is like a potmeter, i.e. with a plastic or metal 6mm axis. You'll have to purchase the knob separately. In the past I've had trouble finding knobs with greater than 40mm diameter, esp. ones with an index like in your picture may be hard to find. – stevenvh Dec 25 '10 at 15:11
• great answer! sometime it seems like half the challenge is finding out the names of things. – Mark Harrison Dec 25 '10 at 23:13
• Another note, they sell these type of encoders as quadrature (as shown above) and pulse. Pulse encoders pulse two lines every detent, with one trailing the other depending on direction. I like the pulse better because you don't need a state machine to implement, just a couple interrupt inputs. But it's important to know what you get or you could run into problems interfacing with them. I'd also check out CUI, they have good encoder prices. One other thing to look for, mechanical versus optical. Mechanical is cheap, optical have long life. – bt2 Dec 26 '10 at 15:57
• @bt2 I'm pretty sure standard quadrature encoders don't require a state machine to implement -- just set an interrupt on one of the lines, and when it goes high, check the value on the other line. If it's high, it's going one way, if it's low, it's going the other. – Evan Krall Jan 21 '12 at 10:44