Paul Maddox wrote:
> All,
>
>
>> I completely agree with you..... How to organize it ?? Where to put it
>>?? It is a real shame to have this kind of knowledge being lost with time
>>!!
>>New programmers do not even now how to mask flags in bits !! What about a
>>sister list in Yahoo to keep just the "knowledge bits" ??
>
>
> if someone is willing to spend the time, I'm happy to provide space and a
> subdomain of my server (Www.Synth.Net), I don't have the time to do the
> webpage and update it, but I can supply the space/bandwidth.
>
> Paul
I'd like to contribute this bit of code, even though it is not mine.
I got it from here
http://www.dattalo.com/technical/software/pic/debounce.html
a couple of years ago and have used it ever since:
It is an algorithm for debouncing all the inputs on a port
simultaneously. No loops or branches, just inline code. The routine is
expected to be called periodically, as by a timer interrupt.
Although the original code is for the PIC, there is an explanation of
the logic written in C which I repeat here with some small changes for
clarity.
static unsigned // global variables
clock_A, // counter LSB
clock_B, // counter MSB
temp, // temporary location
delta; // temporary variable
debounced_state; // the result you will read
void debounce(unsigned new_sample)
// new_sample read from port once per call
{
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.
temp = (clock_A | clock_B);
debounced_state = temp;
//debounced_state &= (clock_A | clock_B);
//Preserve the state of those bits that are being filtered
// and simultaneously
//clear the states of those bits that are already filtered.
debounced_state |= (~temp & new_sample)
//debounced_state |= (~(clock_A | clock_B) & new_sample);
//Re-write the bits that are already filtered.
}
All I can say is that whoever originally came up with this little gem
has to be some kind of genius.
--
erikcMessage
Re: [AVR-Chat] Re: Challenge
2005-06-10 by erikc
Attachments
- No local attachments were found for this message.