Electronic – Optical quadrature encoder goes out of sync at higher speeds

741-opampencodermicrocontrollermotor controller

I'm trying to get a microcontroller (stm32) to read a quadrature encoder, but running into an issue when at higher speeds line 1 seemingly gets narrower pulses until it gets out of sync with line 2.

In other words, line 1 starts off fine, but as speed picks up it gets shorter pulses. Eventually, with cycle time of ~150usec, it starts dropping off at the wrong time of the cycle, confusing the counter. See image below for the logic analyser view.

I'm not sure whether the problem is with hardware (misaligned detectors? although I don't see anything obvious) or with electronics and would really appreciate advice. Unfortunately I'm a noob with electronics and won't vouch that this simple circuit is enough to handle faster rotations. In particular, many schematics I found on the web use an op-amp, which I don't: example

Below is the schematic, followed by the logic analyzer output. Finally motor and encoder look like this.

circuit schematic

logic analyzer view

Best Answer

Optical sensors (phototransistors or photodiodes) have capacitance, and the 10k pulldown resistor is making an RC time constant. If you want fast operation, consider using a smaller pulldown, and (there will be a lessening of output potential) amplifying the signal with a comparator instead of using it directly for logic. A threshold around 100 mV might be appropriate, one LM393 dual comparator would work for both signals.

It's not clear what components your 'D2" and "D3" are, but photodiodes would be in opposite polarity; could these be phototransistors?

A possible circuit would be like this:

schematic

simulate this circuit – Schematic created using CircuitLab