Debounce Switch Circuit - Choosing Component Values

Thread Starter

dmarciano84

Joined Oct 1, 2023
36
I am working on a project with a PIC16F18877 which will have 5-6 buttons as input (which will be read as interrupts) and I need a debounce circuit. I came across the following circuit on Microchip's website which I should have all the components to make it:
1699470063792.png

However, they provided no guidance on the best way to should the values for R1, R2, and C1. As this is the first debouncing circuit I have ever had to design/use, I would appreciate any guidance on the best way to choose these values (or at least a starting point). TIA.
 

AnalogKid

Joined Aug 1, 2013
10,950
It is with sadness that I agree. A debounce circuit is basically a timer, and I have it on good authority that a PIC can time things.

Interesting take on the classic - U1 changes state at the *end* of the debounce period.

ak
 

Ian0

Joined Aug 7, 2020
9,533
Might also be able to debounce through programmed delays.
Yes - just don't read the switch inputs too often.
If the repetition period of the program loop that reads the switches is longer than the bounce time, you don't need any circuitry at all.
 

Thread Starter

dmarciano84

Joined Oct 1, 2023
36
A link would be helpful in giving some context.
Are you going to trigger something on switch closure and switch opening? Or just one or the other?
My mistake...it was actually from Digikeys website. Here is their article are various debouncing strategies: https://www.digikey.ee/en/articles/how-to-implement-hardware-debounce-for-switches-and-relays

Yes - just don't read the switch inputs too often.
If the repetition period of the program loop that reads the switches is longer than the bounce time, you don't need any circuitry at all.
The program won't be reading the switches via a loop. It will be using interrupts on either the rising and/or falling edge (having fully decided yet).

Thank you...I will give that a try and see how it goes. Thanks for a suggested starting point.
 

dl324

Joined Mar 30, 2015
16,732
It will be using interrupts on either the rising and/or falling edge (having fully decided yet).
I've never had issues with using switches that weren't debounced for interrupts.

If you're triggering on both edges, you should keep the extra diode and resistor (that wouldn't be required if you triggered on one edge or the other). Since switch bounce can vary from a couple ms to up to 20 (for military applications), I'd start with a 5ms RC time constant (47k and 0.1uF). Can't give more specific values without knowing the switch type and which edge you're triggering on.
 

eetech00

Joined Jun 8, 2013
3,824
I am working on a project with a PIC16F18877 which will have 5-6 buttons as input (which will be read as interrupts) and I need a debounce circuit. I came across the following circuit on Microchip's website which I should have all the components to make it:
View attachment 307055

However, they provided no guidance on the best way to should the values for R1, R2, and C1. As this is the first debouncing circuit I have ever had to design/use, I would appreciate any guidance on the best way to choose these values (or at least a starting point). TIA.
Hi
See simulations below. I've shown them using a CD40106B but a 74HC14 could be used as well for a 5v circuit.
The switch bounce duration is stepped using 50ms, 100ms and 150ms.

Here is a simulation (#1) of the circuit with the RC values shown in post #2.
1699508236503.png

You can see the the output of the inverter bouncing (a bad thing).

Now, here is the simulation (#2) with recommended RC values:

1699508468401.png

You can see that there is a clean, bounce free, output from the inverter, even at 150ms of bounce duration.

I don't know who your project is for but I would go with the values in simulation #2 unless you are certain of the quality of the switch(s) you'll be using. High quality switches usually have bounce times around 20ms but I'd plan for 50-100ms bounce times.

Reference:
http://www.ganssle.com/debouncing-pt2.htm
 
Last edited:

Ian0

Joined Aug 7, 2020
9,533
The program won't be reading the switches via a loop. It will be using interrupts on either the rising and/or falling edge (having fully decided yet).
Unless your interrupt routine takes longer to run that the bounce time, then you will need a debounce.

I would use R2=10.R1 and no diode - that would make it almost symmetric.
 

Thread Starter

dmarciano84

Joined Oct 1, 2023
36
I've never had issues with using switches that weren't debounced for interrupts.

If you're triggering on both edges, you should keep the extra diode and resistor (that wouldn't be required if you triggered on one edge or the other). Since switch bounce can vary from a couple ms to up to 20 (for military applications), I'd start with a 5ms RC time constant (47k and 0.1uF). Can't give more specific values without knowing the switch type and which edge you're triggering on.
The switches I am currently planning on using are PTS645SL50-2 LFS and almost definitely going to be triggering on the rising edge.

Unless your interrupt routine takes longer to run that the bounce time, then you will need a debounce.

I would use R2=10.R1 and no diode - that would make it almost symmetric.
Potentially it may be extremely close/slightly longer as the buttons will be updating an LCD screen. I literally just got the screen working a few minutes ago so, but I haven't planned out all the screens yet so I don't know yet which screen will take the longest to print. My thought was to maybe set some bit flag to determine which screen should print and then just set that flag in the ISR and do the actual updating from the loop I am currently in so that way the code isn't staying long in the ISR. My concern though was timing; that is, ensuring the screen is updated before the next ISR can be handled/trigger. But this is something I am still designing/testing. Because of some of the opens questions/design choices, I figured it was safer to just plan to debounce the switches rather than do a design without one and then find out under some circumstances I need them and have to do a redesign.
 
Top