What you can do with the PiXi - No. 3
A rotary encoder interface for the Raspberry Pi
Rotary encoders are everywhere. They are the wheel rotation sensors on your robot vehicle, they are the digital volume control on your radio, they are the navigation control on your cars dashboard, they might help track position in your 3D printer, count bottles off a production line, they could be behind the thermostat that controls your home’s central heating, they are used on game controls, computer mice and toys, they are being used more and more to replace the analogue potentiometer as a means of measuring rotary position or track movement.
They are low-friction, they have no end-stops and they offer a feel of quality, reliability and a degree of measurement accuracy that is simply difficult to beat. Some are cheap, some are expensive, some come attached to the motor you may have just bought, some are small, some are huge but a lot of them probably work on the same two-signal phase-shifted system that needs a small amount of dedicated electronics to properly use them. One thing you can’t do is to use software to read them directly, at least not if you want to read them fast, accurately and not miss any points in their rotation so they can appear to be a little difficult to to use. A common mistake (and one that I made myself many years ago…) is that you can use one signal output as a clock, using the positive edge and the other as a direction control but as this diagram shows, you can get jitter out of the encoder reader if the encoder slows down or stops near a transition point and this can end up with the encoder reader drifting off wildly in one direction. To track it properly and accurately you really need to look for both positive and negative edges and this is where it can get a little difficult.
But if you have an FPGA at your disposal it can be a relatively simple task to create your own custom rotary encoder reader in just a few lines of VHDL or Verilog code. The PiXi FPGA has eight rotary encoders built into it, you just have to connect up the rotary encoder to the FPGAs GPIO that support this function, either via the 3.3V I/O of via the 5V I/O. Inside each rotary encoder interface there’s an 8-bit up/down counter to track the position of the encoder giving you 256 points of rotation. And if you want better resolution or a larger range then it’s a relatively simple process to change the design in VHDL, re-compile and re-configure the FPGA to give you the resolution or range that you need.
We used rotary encoders in several of our application examples for the PiXi add-on for the Raspberry Pi.
In the first example we added a rotary encoder to a Raspberry Pi based replacement control panel for a computer-controlled telescope. The original control panel had a couple of menu keys that were used to navigate through the menu system. While building the replacement panel we decided to add a rotary encoder to help navigate through the menus. You can still use the keys to go up & down through the menu and select targets from the thousands of objects built into the telescope but you can now also use the rotary encoder to move through the menu system and target selection more efficiently.
In the second example we used the PiXi FPGA to track the wheel rotation on our Dagu ‘Rover-5’ using the encoders that were built into the rover’s gearbox found on each wheel. With this we could then drive and accurately position the rover with near-millimetre accuracy.
In an earlier example, we used the FPGA’s rotary encoder reader to track the position of a Lego Mindstorm NXT servo for the steering control on a Lego Technic truck.
So if you have an application for the Raspberry Pi that needs a rotary encoder reader, an add-on board or HAT with an FPGA on-board like the PiXi Board might very well be worth a look…