Debouncing Switches
-
- Posts: 18
- Joined: Tue Jul 29, 2003 1:01 am
- Contact:
Debouncing Switches
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.
Re: Debouncing Switches
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>
Re: Debouncing Switches
Don't forget with the Pic you can do the debounce in software as well.<p>
Colin
Colin
On a clear disk you can seek forever.
-
- Posts: 18
- Joined: Tue Jul 29, 2003 1:01 am
- Contact:
Re: Debouncing Switches
now how does that work? (debouncing software?)
Madness has a toll. Please have exact change ready.
Re: Debouncing Switches
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.
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
Microbes got brains
-
- Posts: 26
- Joined: Thu Apr 17, 2003 1:01 am
- Contact:
Re: Debouncing Switches
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
call MyFunction
rest of code<p>
MyFunction
some code here
btfsc PORTA, 0
goto $ - 0x01
return
-
- Posts: 146
- Joined: Mon Jan 13, 2003 1:01 am
- Location: Chicago IL
- Contact:
Re: Debouncing Switches
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
Re: Debouncing Switches
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
{
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.
Who is online
Users browsing this forum: Ahrefs [Bot] and 18 guests