Electronic – Avoiding false optical rotary encoder readings

encodermicrocontroller

I have an optical shaft encoder that has rather big resolution – 2500 pulses per rotation. The problem is that false pulses get registered from environmental vibrations – if I shake it in my hand or slap a hand holding it with other hand – I get several pulses forth, then several back, then forth again – it looks like decaying sinusoide.

One way to deal with that is to count some amount of pulses that are in the same direction before registering "ok, the rotation has started".

Does anyone know some clever tricks to deal with this kind of problem in microcontroller code?

Best Answer

[...]count some amount of pulses that are in the same direction before registering "ok, the rotation has started"

A kind of hysteresis is proposed by the O.P. If there is a slow but real motion, your actual input will be slow and smooth, but it would be perceived as a series of steps.

First thing that come to mind is low-pass filtering your signal in software. Boxcar average (sliding average), for example, is nice and simple.

Second thing that comes to mind is isolating the encoder from unwanted vibration.

P.S.

There are several philosophies.

Philosophy #1. Attempt to solve optical problems with optics, mechanical problems with mechanics, analog problems with analog, digital problems with digital, software problems with software. In that order or precedence (roughly).

Philosophy #2. Try to solve every problem with software, because software changes are more expedient than hardware changes. If it can't be helped with software, try digital solution. Then try analog... Notice that the order is reversed w.r.t. Philosophy #1.