Hi Erik,
> 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.
Thanks. I've got a single button debounce by now, but this one is
quite nice due to its multi-input nature. I've saved it to my favs for
future reference.
Best,
MarcMessage
Re: [AVR-Chat] ATtiny2313 button handler
2009-11-03 by Marc R.J. Brevoort
Attachments
- No local attachments were found for this message.