I recently acquired some of those cheap encoders off of Ebay (to help my 30 yr old son with music synth project), and the bounce was pretty awful (see attached waveforms). I implemented some hardware debounce using some programmable logic. So depending on your application, you may or may not care about bounce, but here is my hardware solution (I'm sure I will get some flak for the use of all the glue logic when it could be done with firmware).
Nasty output. No flak from me, sometimes you have bigger fish to fry at the software level so a little hardware (MC14490) goes a long way into making the I/O routines cleaner and faster when generating external interrupts with mechanical switches.
https://www.maximintegrated.com/en/app-notes/index.mvp/id/287
C:
if (INTCONbits.INT0IF) {
INTCONbits.INT0IF = LOW;
V.buttonint_count++;
hid0_ptr->bled_on = !hid0_ptr->bled_on;
}
if (INTCON3bits.INT1IF) {
INTCON3bits.INT1IF = LOW;
V.buttonint_count++;
hid1_ptr->bled_on = !hid1_ptr->bled_on;
}
Last edited: