Debouncing Switches

This is the place for any magazine-related discussions that don't fit in any of the column discussion boards below.
Post Reply
i_myself_matthew
Posts: 18
Joined: Tue Jul 29, 2003 1:01 am
Contact:

Debouncing Switches

Post by i_myself_matthew »

Hello<p>What would be a good way of debouncing a momentary switch without using a 555 or a lot of components? <p>It would be used for PIC or TTL inputs, by the way.<p>Thanks.
Madness has a toll. Please have exact change ready.
User avatar
Joseph
Posts: 681
Joined: Mon Dec 10, 2001 1:01 am
Location: USA,World
Contact:

Re: Debouncing Switches

Post by Joseph »

I found what worked the best for me is to use two resistors and a capacitor. Before the switch is pushed, both resistors are low and the capacitor is discharged. When the switch is pushed, the two resistors are pulled up together for a couple of microseconds, but the second drops down quickly dependent on the RC time constant of the capacitor and the second resistor. When the switch is released, the system returns to the first condition quickly. The resistor closest to the switch should be large like 10meg, the capacitor 01uF, and the second resistor 1k. This will give a pulse of 10uS with a reset time of 100mS. With the second resistor very low-valued and the first high, when the switch is released, no appreciable negative pulse is sent forward to the gate being triggered. <p>The principle is that the bouncing switch contacts are too fast to let the circuit reset, but too slow to send two pulses within the 10uS.<p>[ August 28, 2003: Message edited by: Joseph Meisenhelder ]</p>
bodgy
Posts: 1044
Joined: Tue Dec 04, 2001 1:01 am
Location: Australia
Contact:

Re: Debouncing Switches

Post by bodgy »

Don't forget with the Pic you can do the debounce in software as well.<p>
Colin
On a clear disk you can seek forever.
i_myself_matthew
Posts: 18
Joined: Tue Jul 29, 2003 1:01 am
Contact:

Re: Debouncing Switches

Post by i_myself_matthew »

now how does that work? (debouncing software?)
Madness has a toll. Please have exact change ready.
hlreed
Posts: 349
Joined: Wed Jan 09, 2002 1:01 am
Location: Richmond, TX
Contact:

Re: Debouncing Switches

Post by hlreed »

You don't really need to debounce the switch, since you read it once only. Does not matter if it bounces some, since you are not looking at it.<p>Connect the switch to an input pin, say A.1. The other end goes to ground, so switch on is 0.
Then the little program is:<p>; other code
Test
BTFSS A,1 ; test the switch
GOTO SwitchOn
GOTO Test
SwitchOn
BSF Switch,1 ;record switch on
; do whatever
; There are lots of ways to do this. This is a
; crude way.
Harold L. Reed
Microbes got brains
bruinbear714
Posts: 26
Joined: Thu Apr 17, 2003 1:01 am
Contact:

Re: Debouncing Switches

Post by bruinbear714 »

Yes, you can do it in a crude way in the software...<p>btfsc PORTA, 0
call MyFunction
rest of code<p>
MyFunction
some code here
btfsc PORTA, 0
goto $ - 0x01
return
Chris Foley
Posts: 146
Joined: Mon Jan 13, 2003 1:01 am
Location: Chicago IL
Contact:

Re: Debouncing Switches

Post by Chris Foley »

If you're reading the switches with a PIC, you just use a software debounce (if it's there a certain number of times in a row, it must be there). However, if you're using the inputs for TTL or other discrete logic, you will want to have a hardware debounce.<p>If you're just getting one input, you could put an R-C lowpass in front of the input to a schmitt trigger gate like the 74C14 (inverter), or the 4093 (NAND gate). If you've got multiple inputs, the extra Rs and Cs will take up space. In that event, you might want to try the On Semi MC14490, which will give you six debounced inputs per IC. It has built-in pullups, a built-in oscillator, and built-in input protection.<p>http://www.onsemi.com/pub/Collateral/MC14490-D.PDF
bodgy
Posts: 1044
Joined: Tue Dec 04, 2001 1:01 am
Location: Australia
Contact:

Re: Debouncing Switches

Post by bodgy »

Here is a program/algorithm in 'C' for software debounce using the polling method.<p>if (ButtonPort&ENTER_BUTTON)// BTFSx ButtonPort,ENTER_BUTTON
{

KeyPress=ENTER_KEY; //movlw ENTER_KEY movwF KeyPress or you could have movlw 1 etc

}



if(KeyPress==KeyDetect)
{
KeyCount++;
if(KeyCount==5)
{
KeyDetect=KeyPress;
return KeyPress;
}
}
else
{
KeyCount=0;
}

KeyDetect=KeyPress;

}<p>The other method is to use an interrupt method using a timer, or just poll the timer.<p>Colin
On a clear disk you can seek forever.
Post Reply

Who is online

Users browsing this forum: No registered users and 11 guests