Electronic – 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):

alt text

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.

Best Answer

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

enter image description here

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.
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.

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