switch debounce

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
siliconchip
Posts: 392
Joined: Wed Jan 05, 2011 11:24 am
Has thanked: 101 times
Been thanked: 24 times

switch debounce

Post by siliconchip »

hi all,
my question concerns switch debounce when connecting a switch to a pic micros input, whats the best method for the PIC, ive seen circuits using the cmos 40106 schmitt trigger with a couple of resistors and a cap, or just a switch with a cap and resistors or is the software method better ??, i did read some where that pic micros dont like just a cap and resistors with a switch on their inputs ?? and prefer the schmitt approach id appreciate any comments thanks in advance

bob

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times

Re: switch debounce

Post by medelec35 »

Hi Bob.
If you use the switch component, then that will have a debounce option within properties.
The reason for debounce is because the microcontroller can so fast a switch detection, it will count the times the switch contacts have vibrated when the intention was just to detect a single switch event.
The other way is to have an input, then a decision branch if the switch is detected.
Within the decision branch, have a delay that will cover the maximum bounce duration e.g 10 to 50ms
Both methods should work well.
Martin

siliconchip
Posts: 392
Joined: Wed Jan 05, 2011 11:24 am
Has thanked: 101 times
Been thanked: 24 times

Re: switch debounce

Post by siliconchip »

Hi Martin
as always thanks for the reply so it's safe to say that the software debounce is just as good as the hardware variants plus with the added bonus of a lower component count

Bob

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times

Re: switch debounce

Post by medelec35 »

You're welcome.
The answer is yes.
I have never used external components for switch debounce. I have used both software methods for great reliability in my projects.
Martin

siliconchip
Posts: 392
Joined: Wed Jan 05, 2011 11:24 am
Has thanked: 101 times
Been thanked: 24 times

Re: switch debounce

Post by siliconchip »

Thanks Martin 👍👍

Post Reply