Circuits for cheap mechanical rotary encoders

especially for the I/O card of FSbus

by Rob Hamerling - 7 September 2005 - version 1.0.4

Introduction

To be able to effectively use cheap - mechanical - rotary encoders, some additional electronics is required. The function of these electronics is:

The Redec filter seems to be a well known circuit in Flight Simulator circles. In the original documentation a logic diagram is missing. This is what I made of it:

{logic diagram of Redec 0.9b}

This circuit acts like two 'normally closed' switches. This is no problem when used in combination with FSbus, but for other purposes 'normally open' switches may be preferred.

To my opinion the circuit can be simplified and improved. In the following chapters some alternatives will be presented.


Modified Redec filter

Reasons to modify the original circuit are:

The figure below shows the modified logic diagram:

{logic diagram of modified Redec}

Wiring diagram for a pair of rotary encoders

Since only half of a 4066 is used per rotary encoder and normally several rotary encoders will be used in a cockpit, it seems obvious to build circuits for pairs of rotary encoders. The wiring diagram below gives an example for 2 rotary encoders. When more than 2 rotary encoders are used, multiples of this circuit could be placed on a single print.

{wiring of a dual modified Redec}


Intelligent Quadrature encoders

With the application of a microcontroller the debouncing characteristics of the circuit can be improved and at the same time the number of electronic components can be reduced, especially when 4 or more rotary encoders are used. The price of the components of such a circuit might be slightly higher, but the reduction of required (PCB-)space and number of components might be worth more!

Design and Implementation

It wouldn't be cost effective to use a relatively expensive microcontroller for a single or two rotary encoders. Since in most situations with Flight Simulator cockpits at least 4, and not uncommonly more that 12 rotary encoders are used, a cost effective circuit has been designed for 4 encoders, based on a MicroChip PIC.
The functional logic is all done in software. The major functions are explained in the following sections.

Debouncing

Mechanical switches have contact bouncing. This may result in false signals and a low-pass filter must be used to remove the effects.
'Digital' debouncing of a contact is performed by sampling. When the contact state does not change for a number of consecutive samples the contact is supposed to have reached a stable state. Actions are only taken on changes in the stable state.
An efficient method for 8 contacts (4 rotary encoders) is described by Scott Dattalo. This method is used here.
Rotary encoders have frequently 24 or more 'steps' (on/off cycles) per full rotation. The sample frequency must be high enough to avoid missing steps, but on the other hand it must be not too high because then debouncing will not work effectively. In this case the contacts are sampled about 3000 times per second, and after 4 consecutive 'on' or 'off' states the contact state is considered stable.

Direction of Rotation

The direction of rotation is determined by the sequence of opening and closing of (debounced) contacts 'a' and 'b' of the rotary encoder. When 'a' closes and 'b' is open at that time the rotary is turning clockwise. When 'a' closes and 'b' is closed at that time the rotary is turning counter-clockwise.

Pulse duration

The duration of the output 'pulse' (the time an output switch is closed) is as long as contact 'a' is closed. This gives approximately a 50% duty cycle: the time 'a' is closed is about the same time as it is open. Of course this depends on the behaviour of the rotary encoder. See its datasheet!

Missing pulses

The time that a switch is closed depends on the rotational speed of the rotary encoder. When turning the rotary encoder really fast a step may be missed from time to time, because a contact may not remain closed during 4 consecutive samples. This is not considered to be a problem!

Circuit for 4 rotary encoders

The selection of a suitable microcontroller was based on price, availablity and usable pins per chip. MicroChip PICs are pretty popular, not expensive and exist in a considerable variety. The PIC 16F88 looked the most suitable: by using its internal oscillator 16 of the 18 pins can be used for digital input/output.
This resulted in the following wiring diagram.

{wiring for 4 rotary endoders}

Four of these circuits will fit on a single strip-board (Vero-board) of Eurocard-format, so in total 16 rotary encoders can be serviced with a single print. See the pictures below.

{closeup of 1/4 Eurocard} {photograph of Eurocard}

{backview of Eurocard}

The required software for the MicroChip PIC is provided for free!
Although QUADRH4 was originally developed with a MicroChip PIC 16F88, there are some pin-compatible PICs which may be used in stead. Alternatives are 16F87, 16F818, 16F819, 16F628A and 16F648A. The differences between these PICs are of minor influence on the software, but each requires its own program.
Depending on the chosen PIC you must use the corresponding HEX file to program it. See the table below.

type of MicroChip PIC .hex file to be used
16F88 QUADRH4_88.HEX
16F87 QUADRH4_87.HEX
16F818 QUADRH4_818.HEX
16F819 QUADRH4_819.HEX
16F628A QUADRH4_628A.HEX
16F648A QUADRH4_648A.HEX
Table of matching hex files

The hex files can be found in a separate package: QUADRH_104.ZIP.

Building a QUADRH4 on Vero(strip)board

Some considerations when building a board yourself:

Hints and tips

Some other considerations:

{wiring of input from rotary encoder} {wiring of output to FSbus I/O card}

Printed Circuit Board

Although the circuits can be easily built on experiment/strip-board, with a specially designed PCB the assembly will be easier and even less space will be needed. The figure below shows (part of) a possible double sided Printed Circuit Board. Although the board is double sided, the component side contains very little copper. You might decide to make a single sided board and use discrete connections with wires for the upper (component) layer.

{design of printed circuit board}

Component list for 4 rotary encoders:

The Sprint Layout file "PCB_RVD_QUADRH_ENCODER.LAY" contains a 10x16 cm PCB with 4 of the designs of the figure above, thus providing support for 16 rotary encoders. The board is designed by Rob van Dijk with the Sprint_Layout program, a commercial but not very expensive program. The picture below shows the PCB with 4 quadrh4 encoders.

{picture of PCB}

The layout file can be found in the package QUADRH_104.ZIP, in which there are also the hex files for PICs. When you want to make the board yourself you need to have a regular copy of the SPRINT-LAYOUT program. To simply view the board you can download a free viewer to display the PCB at the site of Abacom.

With the assembly of the PCB please note:

  • The chips on this PCB are not all pointing in the same direction.
  • Start with soldering the 'passthrough' connection between the upper and lower layer of the board, some connections are under a chip socket!

    The PCB provides a 5-pins connector for In-Circuit Serial Programming for programming of a PIC. Only one of the 4 circuits has the programming connector, so if you want to reprogram all the PICs, you'll have to shuffle 'm! For this reason the use of IC-sockets is recommended!
    Only High Voltage Programming (HVP) is possible in this case. It requires a suitable PIC programmer, for example the Wisp628 PIC programmer and XWisp2 program.

    References

    The following sources of information may be useful:

    Summary of changes

    Date Version  Description
    21 Aug 2005 1.0.0
  • First public issue
  • 23 Aug 2005 1.0.1
  • Bug fix for 16F628A and 16F648A PICs.
  • Revised documentation, added picture of connector to I/O card.
  • HEX files moved to a separate package.
  • 24 Aug 2005 1.0.2
  • Fixed bug for 16F818 and 16F819: ADC is now disabled.
  • Correction of docs: '16F77' replaced by '16F87'.
  • 3 Sep 2005 1.0.3
  • Extended docs with layout of PCB.
  • Mapping of input to output ports adapted to PCB.
  • Sprint Layout file with 4 Quadrh4 circuits added to package.
  • 7 Sep 2005 1.0.4
  • Some improvements of the docs.
  • Final version of the PCB.