2
\$\begingroup\$

I'm looking to debounce the output of a rotary encoder I'm using as a switch to ground with a pull-up. Looking online I saw the debouncing circuit in Figure 2 and read about it here. However, I also saw the first image below and read about it here. Is one better than the other for my application? According to the datasheet, the GPIO of the imx6sl I'm using has a Schmitt trigger and input hysteresis, so I'm assuming having a capacitor connected to it is okay.

Figure 1

Figure 1

Figure 2

Figure 2

\$\endgroup\$
4
  • \$\begingroup\$ What encoder are you using (specifically)? \$\endgroup\$
    – Adam Z
    May 5, 2016 at 17:23
  • \$\begingroup\$ @adamZ This one: digikey.ca/product-detail/en/bourns-inc/PEC09-2325K-N0015/… \$\endgroup\$
    – Stephan GM
    May 5, 2016 at 17:35
  • \$\begingroup\$ @DmitryGrigoryev This question is about the difference in topology between the two circuits. I believe it is different. \$\endgroup\$
    – Stephan GM
    Jan 24, 2017 at 19:03
  • \$\begingroup\$ @StephanGM I don't think the analysis of the bad version of the circuit has much value, and the good one is exactly the same in both questions. Considering this question is self-answered, I don't see why you would want it open. I'll upvote your answer if that makes you feel better :) \$\endgroup\$ Jan 24, 2017 at 20:18

3 Answers 3

3
\$\begingroup\$

Assuming the MCU and Schmitt Trigger have infinite input resistance and modeling them as an open, we can close the switch and see what happens.

With the switch closed in the figure 2, the resistor R2 is in series with the capacitor, meaning that there is 0V DC at the input.

In the first diagram, with the switch closed, the resistor R is in parallel with the capacitor meaning that there will be a voltage at the input unless Rpull-up >> R, making the voltage drop across R negligibly small. having different resistor values would mean that the time constant would be different for charging and discharging and our debounce would be inconsistent between rising and falling edges.

Therefore, the first image is not a viable alternative to figure 2 and also does not properly debounce the switch. Figure 2 is preferable.

\$\endgroup\$
1
\$\begingroup\$

Figure 2 is preferable assuming your MCU's I/O power supply is the same as the pullup voltage for R1, and CMOS voltage levels are in use.

Connecting capacitors directly to the MCU pins- you may well be able to get away with it, but it's better to have some series resistance such as a few hundred ohms up to 1K. If you elect to not use resistors you should ensure that the dv/dt on the Vdd rail can never be less than \$-\frac {i_{MAX}}{C}\$ where \$i_{MAX}\$ is the maximum clamp diode current (to prevent latchup).

I presume you have identified some need for hardware debouncing- usually it's not necessary and firmware debouncing (polled inputs) does the job. If you are using interrupts then the hardware debouncing may be necessary, but that is rarely desirable.

\$\endgroup\$
0
\$\begingroup\$

I've used software-polling debounce with very good results. This approach requires that you're able to poll the input pins often enough to not miss switch activity:

  1. poll inputs
  2. if either switch has transitioned from off to on, store that value
  3. ignore further transitions for a period of time to avoid switch bounce

This technique can be used in conjunction with your figure 2 hardware debouncer, particularly if you're unable to poll very often.

A combination of soft- and hardware debounce will allow you to decrease the "ignore" time on the software side, and decrease the RC time constant on the hardware side. This can be better than either hardware-only or software-only debounce.

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.