by Clive “Max” Maxfield, Editor at DENA.

Rotary encoders can provide unwanted surprises to the unwary.

When I started my career, rotary controls came in two main flavors. First, we had potentiometers (variable resistors), which were used for things like volume controls on radios. These were smooth and silent with a limited range of rotation (commonly 270°). Second, we had rotary switches, which were used for things like channel selection on televisions.

I’m not too sure when rotary encoders first arrived on the scene. All I know is that one day when I looked around, they were everywhere—on my oscilloscope in the office, on my toaster oven at home, and all over my car’s console.

There are different types of encoding (absolute vs. incremental) and different underlaying implementation options (mechanical, optical, capacitive, magnetic). The most common kind are mechanical incremental because these are cheap and cheerful, so it is this type that is our focus here.

The first thing we notice is that these devices can be rotated without limit. It’s up to the microcontroller (MCU) to determine what’s happening and what to do. Also, they have multiple detents (24 detents for a full 360° rotation is a common number) that provide an inaudible tactile “clicking” sensation when you are rotating the knob.

These devices typically have a GND connection along with A and B outputs that require the addition of pull-up resistors. Internally, they employ two conducting disks to provide a quadrature encoding scheme on their AB outputs. Starting at 11, a clockwise “click” will result in the AB outputs passing through 01, 00, and 10 before returning to 11 (A leading B). Similarly, an anticlockwise “click” will result in the AB outputs passing through 10, 00, and 01 before returning to 11 (B leading A). Many include a pushbutton switch action with a SW output that also requires a pull-up resistor.

So, nothing too complicated here. Ah, but did I mention that the mechanical incarnations of these devices are very much subject to switch bounce, which only gets worse as they age?

A lot of software developers are unequipped to deal with this. In my Subaru Crosstrek, for example, the switch bounce ensuing from rotating the volume control a single “click” in any direction may be perceived and actioned by the underlying MCU as 1, 2, 3, or more clicks in either direction, which can make for an interesting audio experience.

To cut a long story short (which is opposite to the way I usually like to do things), one of my “hats” is to be the CTO of LogiSwitch. Our claim to fame is a portfolio of small ICs that remove switch bounce. We recently launched a new device called the LS30 (available in LTH and SMT packages). No pull-ups are required on the encoder’s outputs because these are implemented inside the LS30.

Even better, we don’t simply debounce the decoder’s A and B outputs. Instead, we translate them into their debounced D and P counterparts. A pulse on P indicates that a “click” has occurred (P can be poled or used to trigger an interrupt), after which D can be read to determine the rotational direction. Now, that’s what I call easy peasy lemon squeezy!

www.logiswitch.com