Quadrature interfacing - Levels and Filters

Connecting a quadrature encoder up to an interrupt pin to read the wheels speed and direction ought to be straight forward but in practice it can be a little tricky, especially when using a 5V micro-controller.

The main problem is a combination of electrical noise and the 3.3v logic level of the HUB-ee wheel sensors. Most of the time the 3.3v logic level will happily trigger the interrupt pin on a 5V Arduino but every so often you will get false interrupts which then give inaccurate speed and incremental count readings.

If you are lucky enough to have a microcontroller with a hardware quadrature encoder interface then it may well include filtering and error detecting circuits that can screen out this noise but if not there are a few simple things you can do to prevent these problems.

Convert the voltage levels

Driving the pins to the correct voltage is by far the best method and involved using some form of level converter. The simplest is just a transistor hooked up to each sensor output to create an open collector driver that will work in conjunction with the internal pull up resistors. If you are using an Arduino ™ you can enable the pull up resistors with the following code:

pinMode(myPin, INPUT_PULLUP);

Open Collector Circuit

This open collector drive circuit does a great job of converting the votage from 3.3V to 5.0V but it also has the effect of inverting the output so 0.0V becomes 5.0V and 3.3v becomes 0.0V. When the sensor outputs 3.3v it switches the transistor on, which connects the micro-controller pin to ground. When the sensor output goes low the transistor switches off and the pull up resistor ensures that the micro-controller pin is connected to the micro-controllers own logic level voltage.

This solution isn’t perfect though and you can still get false interrupts occurring if there is too much noise on the power supply – something that can happen when you drive a lot of cheap, noisy DC motors.

Add filter capacitors

Adding a couple of capacitors to the transistor circuit can help reduce noise. The HUB-ee sensor outputs have 1k resistors built in so adding a capacitor between them and ground will create a low pass filter that can screen out high frequency noise.

FilterCircuit

An 0.1uf capacitor will produce a filter with a cut-off frequency of around 1.5KHz – low enough to filter out high frequency noise but high enough to give us a nice clean set of pulses when the wheels are running at full speed. Lower capacitor values will also do fine but give a higher cut-off frequency.

External pull-ups

If your micro-controller doesn’t have internal pull up resistors, or you don’t know how to enable them you can just add them to the circuit as shown below. The pull up resistors need to be connected to the micro-controllers logic supply voltage (usually 5V)

ExternalPullups

Forum Submit