Electrical – Remove DC offset from differential output, rotary encoder

differentialoperational-amplifier

Op-amp in my circuit is accepting differential sinusoidal signal, that swings around 0 V with 1 Vpp. It is configured as a comparator – swings to upper rail when the signal is positive and swing to lower rail when negative, effectively converting sine to square. Square wave pulses are then counted by uC.

However, differential output from my incremental rotary encoder swings around 2.5V.

rotary encoder voltage output

What is a good way to solve this problem? Note that there is one unused channel in an op-amp, but I am not sure if it can help.
Thank you

Best Answer

Use one opamp as a differential to single-ended converter and then use a comparator (or schmitt trigger) to convert to a square wave. Using an opamp as a comparator is a recipe for trouble, any noise on the signal (and there is always noise) will cause rapid switching of the opamp output as the analog signal transitions across the threshold. Comparators and schmitt triggers have built-in hysteresis which creates a margin between the turn-on threshold and the turn-off threshold. Schmitt triggers often do not have programmable thresholds, but you can manipulate the gain of the differential to single ended conversion to move the signal to the threshold value for your selected Schmitt trigger. As long as this margin is greater than the maximum amount of noise in your system you get a clean square wave on the output.

If you have an ADC on the microcontroller with a differential input (and it is fast enough to sample the signal), you might be able to configure the ADC to operate on two pins as differential input and eliminate the opamp all together. If you do this, you will have to implement hysteresis or pulse width filtering in software. Even without differential inputs on the ADC, you might be able to sample the signal using two channels and simultaneous sampling on the ADC (if available) and just subtract the values.