27.6.4.3 Interrupt Pin Debouncing
The external interrupt pin (EXTINT) edge detection can use a debouncer to improve input noise immunity. When selected, the debouncer can work in the synchronous mode or the asynchronous mode, depending on the configuration of the ASYNCH.ASYNCH[x] bit for the pin. The debouncer uses the EIC clock as defined by the bit CTRLA.CKSEL to clock the debouncing circuitry. The debouncing timeframe is set with the debouncer prescaler DPRESCALER.PRESCALERn, which provides the low frequency clock tick that is used to reject higher frequency signals.
The Debouncing mode for pin EXTINT x can be selected only if the Sense bits in the Configuration y register (CONFIG.SENSEx) are set to RISE, FALL or BOTH. If the Debouncing mode for pin EXTINT x is selected, the Filter mode for that pin (CONFIG.FILTENx) cannot be selected.
The debouncer manages an internal valid pin state that depends on the external interrupt (EXTINT) pin transitions, the Debouncing mode and the debouncer prescaler frequency. The valid pin state reflects the pin value after debouncing. The external interrupt pin (EXTINT) is sampled continuously on the EIC clock. The sampled value is evaluated on each low frequency clock tick to detect a transitional edge when the sampled value is different from the current valid pin state. The sampled value is evaluated on each EIC clock when DPRESCALER.TICKON=0
or on each low frequency clock tick when DPRESCALER.TICKON=1
, to detect a bounce when the sampled value is equal to the current valid pin state. Transitional edge detection increments the transition counter of the EXTINT pin, while bounce detection resets the transition counter. The transition counter must exceed the transition count threshold as defined by the DPRESCALER.STATESn bit field. In the Synchronous mode, the threshold is 4 when DPRESCALER.STATESn=0
or 8 when DPRESCALER.STATESn=1
. In the asynchronous mode, the threshold is 4.
The valid pin state for the pins can be accessed by reading the register PINSTATE for either the Synchronous or Asynchronous Debouncing mode.
Synchronous Edge Detection mode – In this mode, the external interrupt (EXTINT) pin is sampled continuously on the EIC clock.
- A pin edge transition is validated when the sampled value is consistently different from the current valid pin state for 4 (or 8 depending on bit DPRESCALER.STATESn) consecutive ticks of the low frequency clock.
- Any pin sample at the low frequency clock tick rate with a value opposite to the current valid pin state increments the transition counter.
- Any pin sample at the EIC clock rate (when DPRESCALER.TICKON=
0
) or the low frequency clock tick (when DPRESCALER.TICKON=1
) with a value identical to the current valid pin state returns the transition counter to zero. - When the transition counter meets the count threshold, the pin edge transition is validated and the pin state PINSTATE.PINSTATE[x] is changed to the detected level.
- The external interrupt flag (INTFLAG.EXTINT[x]) is set when the pin state PINSTATE.PINSTATE[x] is changed.
In the Synchronous Edge Detection mode, the EIC clock is required. The Synchronous Edge Detection mode can be used in Idle and Standby Sleep modes.
- Any edge detected that indicates a transition from the current valid pin state immediately sets the valid pin state PINSTATE.PINSTATE[x] to the detected level.
- The external interrupt flag (INTFLAG.EXTINT[x] is immediately changed.
- The edge detector will then be idle until no other rising or falling edge transition is detected during four consecutive ticks of the low frequency clock.
- Any rising or falling edge transition detected during the Idle state returns the transition counter to 0.
- After four consecutive ticks of the low frequency clock without bounce detected, the edge detector is ready for a new detection.
In this mode, the EIC clock is requested. The Asynchronous Edge Detection mode can be used in Idle and Standby Sleep modes.