Taming a Rotary Encoder

The rotary encoder is a popular input device for many microcontroller devices. A knob that can be used to increase or decrease a setting with a nice tactile click for each increment. You can even get an integral pushbutton, just rotate for the setting then press the same knob to enter. With some clever programming you can create a one device user interface using only the encoder.

GenPIC Development Setup
The development setup in use generating the first software release for the GenPIC utility PCB

I have integrated a rotary encoder in the GenPIC utility board. With the combination of an LCD display and the rotary encoder you have all the ingredients for a functional user interface arranged neatly for a panel mount unit.

In the past I have simply set an interrupt to fire on the edge of one channel, then sampled the opposite channel to detect the direction. With the addition of a small delay to debounce the result. This worked well in previous devices, but this time I encountered trouble, the direction sampling was erratic, the value going up when it should have gone down and vice-versa.

Breaking out my logic analyser I found out why, this particular encoder proved to be somewhat noisier than I had seen in the past, with notable periods of bouncing signals.

Continue reading “Taming a Rotary Encoder”

A New Hammer

“I suppose it is tempting, if the only tool you have is a hammer, to treat everything as if it were a nail.” – Abraham Maslow

The above statement is an adage that goes a long way to explaining many engineering decisions. Often referred to as Maslow’s Hammer it is a concept that has been well understood in science and technology for a very long time. In engineering we tend to use the tools we know to solve every problem in front of us, even if the tools we have may not be the best solutions.

Inclinometer Controller
A hand wired microcontroller circuit intended to be used to control a pair of inclinometers in the Keck 2 dome.
There are good reasons to sometimes use the same old tools. The time and effort it takes to learn new tools, particularly with very complex technologies, is considerable. A decision needs to be made… The old tools may not be the most efficient way to solve the problem, but the time and effort it takes to change outweigh any gains to be made. Thus many wise engineers put off updating until the gains to be made are worth the investment of time and resources.

Or the old tools are simply obsolete and you are forced to update.

I am as guilty as any engineer in this. The major example, at least in my case, are microcontrollers. For many decades I have used Microchip PIC16F controllers each time I encountered a problem that required some form of complex control. Specifically I have always loved the PIC16F73 and the later PIC16F873 parts. they had everything I usually needed… A serial port, plenty of I/O pins, a few channels of 10-bit analog to digital, a convenient 28 pin DIP package. If I needed more I/O or more memory just step up to one of the larger packages like the PIC16F876.

Then Microsoft Windows 7 happened. How is this even related? The old versions of MPLAB I used to write the software and program the parts does not run of 64-bit Windows 7. When I updated my machine, I was forced to update to MPLAB X, a totally different platform. A new hammer to learn.

Continue reading “A New Hammer”