Glitch and Debounce Filter configuration

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Can anyone provide some information or a code snippet to implement a glitch filter for E70 or Cortex-M if possible using ASF ? I see that there are several PIO registers and there is an ASF function pio_set_debounce_filter() but I cannot figure out how to calculate appropriate values to filter noise on the interrupt pin.

 

EDIT: added debounce filter configuration in working title

SAME newbie

Last Edited: Fri. Mar 9, 2018 - 05:17 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I tested glitch and debounce filter configurations and failed to configure a "pure" debounce filter. I have an interrupt service routine which must be triggered with the first edge of a transition and shall ignore following transitions for a couple of microseconds. Checking out the glitch and debounce timings shown in the E70 manual I did not find a signal which matches what I call a debounce filter. The red colored signal behavior is what I need/expected:

 

If I set up a filter using PIO_IFCSR=1 and PIO_IFSR=0 no filtering seems to apply. If PIO_IFSR=1 is set then the interrupt is delayed and glitches are removed.

 

I checked out the ASF source of the ioport setup and it seems to me that a pure debounce filter cannot be configured at least using ASF. The code below is executed when calling ioport_set_pin_input_mode().

 

__always_inline static void arch_ioport_set_port_mode(ioport_port_t port,
		ioport_port_mask_t mask, ioport_mode_t mode)
:
	if (mode & (IOPORT_MODE_GLITCH_FILTER | IOPORT_MODE_DEBOUNCE)) {
		base->PIO_IFER = mask;
	} else {
		base->PIO_IFDR = mask;
	}
:

So it seems it is not possible to configure a debounce filter without filtering glitches too and having a significant delay ?

 

This is the code I use for debounce filter configuration:

 

#define MAX_FILTER_FREQ 32768/2
#define SLOW_CLOCK_FREQ MAX_FILTER_FREQ
#define PIN_NOT_INT_GPIO  (PIO_PA3_IDX)
#define IOPORT_MODE		(IOPORT_MODE_DEBOUNCE)
#define PIO_MODE		(PIO_DEBOUNCE)
#define PIN_NOT_INT_FLAGS (IOPORT_MODE_PULLUP | IOPORT_MODE)
#define PIN_NOT_INT_SENSE (IOPORT_SENSE_RISING)
#define PIN_NOT_INT_MASK  PIO_PA3
#define PIN_NOT_INT_PIO   PIOA
#define PIN_NOT_INT_ID    ID_PIOA

ioport_set_pin_input_mode(PIN_NOT_INT_GPIO, PIN_NOT_INT_FLAGS, IOPORT_MODE);
pio_set_debounce_filter(PIN_NOT_INT_PIO, PIN_NOT_INT_MASK, SLOW_CLOCK_FREQ);
pio_handler_set(PIN_NOT_INT_PIO, PIN_NOT_INT_ID, PIN_NOT_INT_MASK, PIN_NOT_INT_ATTR, PeakIrq);
pio_handler_set_priority(PIN_NOT_INT_PIO, (IRQn_Type) PIN_NOT_INT_ID, IRQ_PRIOR_PEAK_CURR);
pio_enable_interrupt(PIN_NOT_INT_PIO, PIN_NOT_INT_MASK);

 

SAME newbie

Last Edited: Mon. Mar 12, 2018 - 08:52 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Jack Ganssle wrote a pretty good article about software debouncing here: https://www.embedded.com/electro...

 

The trick is to shift the edges through a variable of whatever size you want.  Use interrupts and a timer to trigger/sample the signal at whatever frequency you want.  Once the edges make it all the way through the variable has a bit value of all ones, and the signal is active.  All zeros and the signal is inactive.  But anything else is a transition state for you to handle however you want.

 

In your case sample quickly and drop short strings on one's as noise.   But accept longer strings of one's as a valid transition.  Or go even more complicated and only debounce the first transition, then accept all edges.  Again, all done in software.