Wednesday 21 January 2015

switches - switch debouncing - would toggle switch still bounce


I'm having the classic debouncing headache with the Arduino. The switch is meant to turn an led on and off. So if I use a toggle button (SPDT) would it still bounce? Maybe it won't since it not a push button. How much more would it cost to use toggle? It's just that it's a project I've been asked to do for my local Fabrication lab.



Answer



Most SPST switch or pushbutton will bounce, because there are only two states: contact closed (for instance low level) and contact open (high level through a pull-up resistor). This may seem obvious, but it's that hesitation when opening/closing that causes the bounce; just once is enough to make a toggle not work.


You can debounce the switch with a capacitor, but since you're using it with a microcontroller it's cheaper to do it in software. I usually have a 32 ms (software) timer for keypad scans, and only accept a state change if it persists during two consecutive scans. That means you'll have a delay of maximum 64 ms, but since the button will be manually operated you won't notice such a short delay.


You mention a SPDT button, and that's the best solution if you want to do it in hardware.



But frankly, I see no reason for not doing it in software, and you'll have much more choice in SPST buttons than in SPDT buttons.


If you want a button which hardly bounces then I can recommend the Alps SKQG tact switch




which with the devices I tested had an initial bounce of less than 10 ns.


No comments:

Post a Comment

arduino - Can I use TI's cc2541 BLE as micro controller to perform operations/ processing instead of ATmega328P AU to save cost?

I am using arduino pro mini (which contains Atmega328p AU ) along with cc2541(HM-10) to process and transfer data over BLE to smartphone. I...