Rotary Max

If you have a optical or rotary encoder this techniques can extract the maximum resolution from it.  Introduction

In one of my projects I wanted to determine the direction of pointing for a telescope. For this I used an optical shaft encoder on each axis of the telescope’s mount. However I wanted better resolution than I could afford so I developed this technique for squeezing more resolution out of them.

An optical shaft, or or rotary encoder, gives a series of pulses when it is turned, there are two in a mouse. The accuracy you can get, depends upon your ingenuity and your depth of pocket. In fact you don’t just get one pulse train but two in quadrature. That is to say they are 90 degrees out of phase, this is so you can tell the direction. This is quite simple to do, take one signal as your reference and when the other signal leads it is going one way, when it lags it is going the other way. Now, optical shaft encoders are characterised by how many pulses they produce per revolution and in most circuits this translates directly into the resolution. Therefore an encoder giving 360 pulses per resolution will give one degree accuracy.

However, as I studied the diagram it occurred to me that there was much more information to be had from these signals. If you consider each edge of the two signals it is indicating some movement therefore I thought that this extra information could be usefully extracted. If you now look at  the logic sequence produced for each incremental movement you come up with two sequences. One for clockwise and one for anti clockwise movement. Therefore, I designed a circuit that would detect which sequence was being produced and to clock an up down, counter accordingly.

The block diagram of this circuit is shown here and takes a little thought to understand. For any given state of the two signals from the encoder there are two possible states it can move to next, one for clockwise and the other for anti clockwise movement. You can construct a logic circuit that when fed with any of the states will produce the next rotational state. This I call a predictor circuit and we have two, an up predictor and a down predictor. Now this is not so complex as you would imagine and only requires a few inversions. What you have to do it to use the current state table in the diagram as the input and the predictor state as the output. If you consider the up prediction you will see the the predicted state for output 2 is the same as the current state of output 1. Similarly the predicted state for output 1 is the same as the inverse of the current state of output 2.

This current state of the outputs is held in a latch and fed to the predictors. Then this is compared to the current state of the outputs. Therefore normally there is no output. However, as the shaft is turned the output changes and matches one of the two predicted states. This causes the comparator to produce an output. This clocks the counter and latches the current state ready for the next turn. Take time to study the block diagram because it is the one that can be followed easily. The full circuit diagram, shown below, is one of those rare occasions where it is hardly possible to see what is going on. You will see that the outputs from the shaft encoders are fed through Schmitt triggered inverters, this is to remove any noise picked up from the leads into the electronics. The 74LS75 latch provides normal and inverted outputs and so serves as both the latch and predictor combined. The comparator is made from two exclusive OR gates and an OR gate. The output from each comparator is fed to the up or down input of a bidirectional counter. Finally the comparator outputs are combined into one signal that you can use to indicate the reading has changed. Note the power supply connections to the ICs are not shown for clarity, if you are making this then they should be included.

To use this circuit with the Arduino you can connect the Axis output count to four of the input pins. However, if you  have two or more encoders then you might run out of inputs quite rapidly. In that case you can connect the counter output through an input shift register, or I2C expander chip. In that case you could use the Axis Count input directly into the Arduino to monitor when the count had changed so you only read the bits in when there was something worth reading. Depending on how quickly your software can respond to a change in count you might not need to input all four bits of the counter, you could make do with three or two. The extra bits are only needed when counts occur faster than you can gather them in.

This system can be implemented in software providing you can read the state of the signals quickly enough. This will normally require you to use interrupts which as two disadvantages. First you will need to generate an interrupt on every edge of one of the pulses then you will need to service that interrupt which could be as often as every 3 mS. Not much of a problem if you only have one encoder but it becomes increasingly difficult the more encoders you have.

This way of reading an optical shaft encoder gives four times the quoted resolution from any given shaft encode or rotary encoder.      Rotary Max