Incremental Rotary Encoder


Nowadays, the incremental rotary encoder is used everywhere. You'll be familiar with it, of course; anytime you can spin the knob to dial up (or down) a number, and lock it in with a push of the knob, you're using an incremental rotary encoder.

This demo simply shows those operations, rather baldly, on an LCD. You can dial an increasingly larger or smaller number, and then by pressing on the knob can select it. See the photo above which shows the current state of affairs. Previously, the number 81 was locked in, but the number 35 indicates the current position of the rotary shaft.

For the purposes of demonstration, I have the encoder set to to accept numbers from 0 to 100, but this range is easily changed via the compiler directives in the library unit I've provided; see below.

These devices are quite inexpensive now. As you'll note from the schematic, below, they require three pull-up resistors. The unit I'm using in the photo is on a breakout board which includes the resistors. Called the KY-040, I got it from Amazon for a pittance.


Now jitter could be a real problem with a device like this, since it is, of course, mechanical and typically made cheaply. However, I've used a powerful software scheme which makes it work smooth as silk. In particular, you'll note that the demo program calls upon a PMP unit I've written (called "Encoder_Unit") which makes the operation quite reliable. Be sure to read over the source code for that unit. It explains all of the features which are accessible via compiler directives.

This demo also calls upon the LCD library unit which resides in the Common directory of your PMP installation. Make sure you've pointed the compiler towards this directory in the project settings.

These rotary encoders are quite something. They give you a lot of action and versatility for inputing things, yet tie up only three port lines in the process.

Click to get the source code.
Click to get the schematic PDF.

Next Project: Keypad -- Matrix Type

No comments:

Post a Comment