I've removed the rotary encoder from the scroll button of a defect mouse. Let's see how we can use that in a microcontroller design.

 

rotary encoder

 

 

 

 

The Encoder

 

On the outside, a rotary encoder looks like a potentiometer. On the inside, it's a different beast though.

Instead of a resistor, it has a number of contacts in there that open and close while you're turning the device.

As a result, you get two signals on the output that are 90° out of phase (hence the name quadrature encoder).

 

If you turn clockwise, B is lagging on A. If you turn counter-clockwise, A lags on B.

 

Drawing adapted from the Texas Instruments RM46x microcontroller TRM, Enhanced QEP (eQEP) Module documentation

 

The encoder in my mouse turned out to be a EC101102X2E-VAX. It's a jellybean part that's found back in many devices.

 

 

ec101102w2e-vax rotary encoder

 

Photo taken from http://www.soundwell.cn/products_detail/&productId=be545b9a-1e26-43c2-aecb-4b451cf432cd.html

 

Schematics

 

I'll be feeding the signal into a few different peripherals. All of them will want a debounced block signal from the encoder.

What we'll have to do is provide two pull-up resistors so that we get a high pulse when the switch is open, and debounce capacitors to keep the signal reasonably free from glitches.

rotary encoder

Literature advices to use .1µF caps. Just because I happened to have .5µ ones on my desk, I used those.

They work well. The signal  rises fast enough (the slope isn't really steep because the 10K resistor in series slows down the charging). And as you can see on the captures below, there's no trace of bounce.

 

Clockwise capture:

rotary encoder rigol capture

 

Counter-clockwise capture:

rotary encoder rigol capture

 

You can recognize the excerpt of that TI reference manual drawing in the captures.

 

Interpreting the Signal

 

There are a number of possibilities. Some microcontrollers use dedicated peripherals to translate rotary action into data and interrupts that can be used in your firmware.

For others you have to build the logic yourself. That can be done using edge interrupts or other approaches.

With the small test bed I have built here, I can explore some of those mechanics.

That's something for the next posts.

 

Content
Part 1: Electronics
Part 2: Capturing Input on Cypress PSoC4
Part 3: Capturing Input on an Arduino
Part 4: Capturing Input on a Texas Instruments Hercules LaunchPad with eQEP
Part 5: Capturing Input on an FPGA
Real World Application: Hercules LaunchPad and GaN FETs: Control Big Power with a Flimsy Mouse Scroll Wheel