I have seen this routine posted several places for debouncing a pin. Its supposed to be a lot faster than using delays to wait for the pin to debounce.
If I was checking my buttons every 10ms (using a timer), will this code work for me- or should I only use it on an interrupt-on-change type button? Any comments on this routine would be great. Thanks.
if(PIN_OVERLOAD) // Test the inputs status at this time
{ if(bit_test(++debounce_counter_OVERLOAD,CounterSize)) // Aproach and test for true status
{ --debounce_counter_OVERLOAD; // Remove counter overflow state
Overload_Alarm=1; // Set true status
} // Make adjustments to the tested bit
} // to change the counter size
else // The input was false
{ if(--debounce_counter_OVERLOAD==0) // Aproach and test for false status
{ ++debounce_counter_OVERLOAD; // Remove counter from zero state
Overload_Alarm=0; // Set false status
}
}
I suggest CounterSize = 4; to debounce in 6 passes (60mS at 10mS per pass)
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum