Introduction

Author: Qubo Hu, Microchip Technology Inc.

Typical button debouncing approaches are often not sufficiently robust, and with slow setup and response, which may lead to ghost or non-detected stimuli. This Tips and Tricks document presents two more robust and quick debouncing solutions, which equally applies to rotary encoders, buttons, switches, keypads, knobs, and the like. By using an internal timer to provide customized slower clock and Configurable Logic Cells (CLCs), it is possible to filter out various kinds of button generated noise. One solution requires two CLCs per button, which on PIC18F Q10 family devices with eight CLCs can support the debouncing of four buttons. Another solution requires three CLCs per button, which is more robust and addresses a timing corner case in the 2-CLCs solution. The debouncing is performed in hardware peripherals with no CPU execution required, after a system initialization which contains the timer and CLCs configuration. Both solutions require two CLC clock cycles as this gives a very fast debouncing.

An example creation in MPLAB and MCC configuration is described in this document. The example code for replicating the results is also available from MPLAB Xpress code example: mplabxpress.microchip.com/mplabcloud/example/details/799.