Electronic – Encoder direction change during index pulse

counterdecoderencoderquadrature

I have a quadrature encoder with an index pulse, and I would like to keep track of angular position over multiple turns. The microcontroller I am using has counters that count both index pulses (revolutions) and phase edges. Each time an index pulse is seen, the revolution counter is incremented (or decremented if going in reverse) and the edge counter is reset to zero.

Everything works fine for a normal 'clean' transition through the index pulse. However, if I am unlucky and the direction changes during an index pulse, then the counter that tracks revolutions (i.e. counts index pulse edges) becomes incorrect. It increments the revolution count at the rising edge of the index, but does not decrement it at the falling edge (which corresponds with the same physical position as the rising edge). The result is that the revolution counter is one count higher than it should be.

Is it common to use encoders with an index pulse to track multiple turns? What can be done to avoid this problem?

I am considering using only the first index pulse to reset the edge counter, and then ignoring all subsequent index pulses (just allow phase edges to accumulate instead). The downside is that without the index pulse to reset counts, the accumulated counts may drift over time if used for long periods with occasional missed pulses.

Best Answer

The proposal in your last paragraph is a good and common way to handle this. For increased robustness, you can detect index pulses after the first and compare them to the accumulated location, modulo one full revolution. If they don't match to within the ambiguity of one quadrature count, you have a couple of options for how to respond. I would start by simply throwing some kind of alarm, so that after some duration of testing you'll be able to decide whether or not you actually do ever get periods of missed quadrature pulses. If it turns out you do, you can do a little math to have it snap the accumulated position to the nearest integer number of revolutions.