Electronic – How to pick component values for a debouncing filter

debouncepassive-filter

I bought an incremental/quadrature rotary encoder for a project I'm working on.

The specs: https://www.bourns.com/docs/Product-Datasheets/PEC12R.pdf

They provide a diagram of a suggested filter circuit for debouncing the contacts on the encoder.

Here is the diagram from the PDF as an image:
enter image description here

I'm not an electrical engineer, but I get the basic idea of an RC based filter. The resistor values make sense: They pull the switch up to logic 1 value while limiting the current drawn from the 5V rail. How do you select a capacitor value for such a circuit? Do you measure the maximum rate-of-change for the square wave pulses you'd get from this switch, round up a little for safety, and then design a low pass filter that blocks signals at higher frequencies? Do you identify the frequency of the jitter and design a filter that filters that?

The project is built using an Arduino microcontroller and a digital input. I have written an interrupt service routine (ISR) that detects a falling edge on one of the inputs of the encoder, and then compares the value to the value of the other input to determine rotation direction.

I'm not sure how much hysteresis an Arduino digital input line has. The whole arrangement would probably work better with a Schmitt trigger in it, but I don't have a lot of room left on my project board for a DIP package, and don't have the skills for surface mount soldering.

(I'm beginning to think the digital input on the Arduino can't handle the slow-changing signals from the filtered output of the encoder and that I will need to add a Schmitt trigger.)

Best Answer

The bouncing characteristic is not repeatable or consistent. Note that the RC filter will add a delay to your turn on time as the output will need to charge once the voltage is stable. Figure out what is the max delay you can tolerate and design your 5tao RC time constant to be that delay. This will give you the most margin against bounces, as now any bounce less than that 5tao time constant delay will be rejected since it can't charge the capacitor to your threshold value. Otherwise, just pick component values that are reasonable for what you can accommodate size wise and see if that's good enough.