Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Message

Re: [AVR-Chat] ATtiny2313 button handler

2009-11-01 by erikc

http://www.dattalo.com/technical/software/pic/debounce.html

Who ever came up with this orignally was a frickin' genius.

Sure, it's for PIC but the code is in C.

A little helpful cut-n-paste to give you the basic idea.

;
;static unsigned clock_A,clock_B,debounced_state;
;
;unsigned debounce(unsigned new_sample)
;{
;  unsigned delta;
;  unsigned changes;
;
;  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.
;
;  changes = ~(~delta | clock_A | clock_B);
;  debounced_state ^= changes;
;
;  return changes;
;} /* debounce */
;

The cool thing is that this can debounce a whole port at once.  It 
runs in an interrupt routine.


Marc R.J. Brevoort wrote:
> On Wed, 28 Oct 2009, wagnerj@proaxis.com wrote:
> 
>> Due to the very strong similarities among all of the AVRs (both tiny and
>> mega), there is no real difference for debounce software between 2313 and
>> any other ARV.
> 
> Searching 'debounce avr' gave plenty to work with, thanks to this tip.
> 
> Thanks,
> Marc
> 
> 
> ------------------------------------
> 
> Yahoo! Groups Links
> 
> 
> 
>

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.