Quadrature encoder interface loses count
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. 


If you see a rising edge on Line A and Line B is low you count up. 
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.