Electrical – Quadrature encoder interface loses count

encoderintegrated-circuitrotaryservotm4c123g

I am trying to read the encoder signal of a drive amplifier using an ARM (TM4C). The amplifier has differential outputs (+- 5V), the MCU has 2 QEIs (Quadrature Encoder Interfaces).

First I have tried to use the A and B signals like single ended ones, and sometimes I get a steady signal / count number. (Compared to the drive amplifiers configuration software both of them are dead on the same count).

BUT from time to time, the counts start to float even if the motor is not moving. Or while moving from one direction to the other it starts to lose count.

I have measured the signal with my Rigol DSO and there are spikes on the encoder signals. So I have decided to use both A and notA feed them to a UA9637A to make the differential signals single ended and get a nice square wave, but no joy.

The problem persist.

Side notes:

  • Drive Amplifier = Hiwin D2
  • Encoder = 13 bit incremental (RS4222
    Differential)
  • MCU = TM4C123G LaunchPad

What shall I try to get the proper count of steps? The cable coming from the amplifier to the breadboard is not shielded but it's only like 20-25cm long. Does this matter?

I am open for any ideas that might fix this issue.

Best Answer

This is a common mistake with quadrature encoders.

You can NOT just count the edges / pulses of one signal or the other on it's own. Encoders inherently generate spurious edges as the mask uncovers the sensor, whether that be optical, magnetic or whatever.

You can add filtering to reduce that noise when the thing is turning, but that will not help if the encoder is stopped exactly on an edge of the slot or mask. Obviously electrical noise will be an issue, but even vibration from a fan connected to the same chassis can make the thing send out hundreds of edges.

As such you actually need to use an up-down counter algorithm or logic that monitors both lines.

Lets say we are using line A to count.

  1. If you see a rising edge on Line A and Line B is low you count up.
  2. If you see a falling edge on Line A and Line B is still low, your encoder is telling you it thinks you went backwards a bit. You need to count down

This gets further complicated by the fact that the extra edges can happen faster than your monitor can watch them.

When you are driving something at speed, and you know whatever it is can't spontaneously go backwards you can use the second signal as a throttle for the first. That is if you see a rising edge on Line A and Line B is low you count up and wait for line B to go high then low before monitoring line A again.