Debounce Mechanical Switch using FTM

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Debounce Mechanical Switch using FTM

1,274 Views
ericoneill
Contributor II

Hello,

I'm trying to debounce a mechanical switch hooked up to an FTM pin configured for input capture. I would like to trigger an action on the falling edge. My idea was to set up the input capture interrupt to trigger on the rising and falling edge, and start a software timer (using FreeRTOS) on every falling edge, and resetting it on every rising edge. Once the software timer successfully completes, after the switch is done bouncing, I would trigger the action.

My problem is I can't figure out how to detect if the interrupt is being triggered from the rising or falling edge when configured in this mode. Is there a way to do this? Or is there a better way for me to debounce the switch? I figure I could do something similar using GPIO interrupts as well.

I am using a K66 and KSDK2.0.

Any help would be greatly appreciated,

Eric

Labels (1)
4 Replies

1,077 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Eric,

You connect the external capture signal to FTM_CHx pin(just FTM_CH0/CH1/CH2/CH3 pins have digital function), in order to debounce the input signal, fortunately, the FTM input pin has digital filter function, I think you can use the digital function of the FTM input pin to debounce the noise signal.

This is the section of the digital input pin in RM of K66.

You just need to write the FTMx_FILTER register to set up the width of noise, it is okay.

As Mark and you said that the GPIO pin has the digital filter function.

Hope it can help you

BR

XiangJun Rong

pastedImage_1.png

1,077 Views
ericoneill
Contributor II

Hi Xiangjun,

Unfortunately, the hardware I'm working with doesn't have any FTM channels 0, 1, 2, or 3 brought out. This seems like a good solution though, so I'll see if I can get access to one of these channels in the next board revision.

0 Kudos
Reply

1,077 Views
mjbcswitzerland
Specialist V

Hi Eric

Using a GPIO interrupt you could use the interrupt to start a HW timer of the de-bounce period (and disable the interrupt input). When the HW timer's interrupt fires you can check the input state and either ignore the input (glitch) if it is not low, or start the action if it is low - and re-arm the GPIO falling input in each case for the next time.

GPIO interrupt can also be configure on inputs used for other peripherals (also together with FlexTimer use).

Regards

Mark

1,077 Views
ericoneill
Contributor II

Hi Mark,

Thanks, this is the solution I went with and it works well. Using the GPIO was much simpler than using the FTM module.

0 Kudos
Reply