How To Debounce a Switch 10 ms edge triggered....
2005-09-02 by Venkat Nagappan
Yahoo Groups archive
Index last updated: 2026-04-28 22:41 UTC
Thread
2005-09-02 by Venkat Nagappan
Dear Friends kindly send me codes to debounce a switch assembly language avr program is needed..., kindly help m eout friends venkattttttttttttttt __________________________________________________________ Yahoo! India Matrimony: Find your partner online. Go to http://yahoo.shaadi.com
2005-09-02 by Peter Gargano
Venkat Nagappan wrote: > Dear Friends kindly send me codes to debounce a switch > assembly language avr program is needed..., > kindly help m eout friends > > venkattttttttttttttt Sure, and will you do my history assignment if I tell you how? P.
2005-09-02 by Farzlina Ab.Hadi
2005-09-03 by arhodes19044
In software, when the edge is detected, then just wait for the time it takes a switch to finish bouncing before you ever re-check the state of the switch. Use a delay or whatever. I prefer hardware debouncing (just a low pass RC filter, and a schmitt trigger inverter), that way I do not waste processor time needlessly. One hex inverter will work for 3 or 6 depending on the logic output you need. 3 switches if you need to uninvert the inverted signal, 6 if you do not. The actual software debouncing implementation is trivial, and left as an exercise for the reader. If you need to trigger an interrupt on both rising and falling edges, it can get more complicated SR latches and stuff will work. There is a ton of stuff on the internet when you look under switch and debounce. -Tony --- In AVR-Chat@yahoogroups.com, Venkat Nagappan <venkatnagappan@y...> wrote: > Dear Friends kindly send me codes to debounce a switch > > assembly language avr program is needed..., > > kindly help m eout friends > > > venkattttttttttttttt > > > > > > > __________________________________________________________ > Yahoo! India Matrimony: Find your partner online. Go to http://yahoo.shaadi.com
2005-09-04 by erikc
Venkat Nagappan wrote:
> Dear Friends kindly send me codes to debounce a switch
>
> assembly language avr program is needed...,
>
> kindly help m eout friends
>
>
> venkattttttttttttttt
>
Excuse my enthusiasm, but I came across this trick a few years back; it
is incredibly elegant, and is now just about the only debounce routine I
use for mechanical switches.
[1] It debounces all the bits on a port at the same time.
[2] It is inline code with no loops or branches, hence it operates in
constant time.
[3] It will basically work on anything. I have used it on 8051, 68HC11,
80x86, and just recently, AVR.
but, here's the caveat:
[4] You DO have to either call it from a timer interrupt or on a polling
basis.
Just hold your noses and look at this PIC page. ;-)
http://www.dattalo.com/technical/software/pic/debounce.html
Here is the "C" code taken from there:
====begin code====
static unsigned clock_A,clock_B,debounced_state;
debounce(unsigned new_sample)
{
unsigned delta;
delta = new_sample ^ debounced_state; //Find all of the changes
clock_A ^= clock_B; //Increment the counters
clock_B = ~clock_B;
clock_A &= delta; //Reset the counters if no changes
clock_B &= delta; //were detected.
//Preserve the state of those bits that are being
// filtered and simultaneously
//clear the states of those bits that are already filtered.
debounced_state &= (clock_A | clock_B);
//Re-write the bits that are already filtered.
debounced_state |= (~(clock_A | clock_B) & new_sample);
}
=====end code=====
Read the cited web page for an explanation.
erikc
--
"The kind of man who wants the government to adopt and enforce his
ideas is always the kind of man whose ideas are idiotic."
-- H. L. Mencken