Skip to main content
TDJ
Senior III
February 24, 2021
Solved

Using timer Input Capture/Input Filter for button debouncing - is it possible?

  • February 24, 2021
  • 1 reply
  • 2984 views

I know timers are not designed for that purpose but Input Capture channels have unique Input Filter property which I think could be used to debounce a button. It just needs to be configured a way so interrupt is triggered on external signal rising (or falling) edge.

I cannot figure out how to configure it in CubeMX. It would also be good to know which channel triggered the interrupt - in case more than one channel is used.

Please advise.

0693W000007ZPfMQAW.png

Best answer by TDJ

It is actually quite trivial, basic setup (below) will do + timer interrupt enabled.

The only catch is that channels on the same timer have to be enabled separately:

HAL_TIM_IC_Start_IT(&htim4, TIM_CHANNEL_3);
HAL_TIM_IC_Start_IT(&htim4, TIM_CHANNEL_4);

This does NOT work:

HAL_TIM_IC_Start_IT(&htim4, TIM_CHANNEL_3 | TIM_CHANNEL_4);

Next, within HAL_TIM_IC_CaptureCallback() interrupt handler button pressed can be identified using htim->Channel

That's all.

0693W000008yTNkQAM.pngTIMERS_CLOCK_FREQ is 'user constant' I defined

1 reply

TDJ
TDJAuthorBest answer
Senior III
March 31, 2021

It is actually quite trivial, basic setup (below) will do + timer interrupt enabled.

The only catch is that channels on the same timer have to be enabled separately:

HAL_TIM_IC_Start_IT(&htim4, TIM_CHANNEL_3);
HAL_TIM_IC_Start_IT(&htim4, TIM_CHANNEL_4);

This does NOT work:

HAL_TIM_IC_Start_IT(&htim4, TIM_CHANNEL_3 | TIM_CHANNEL_4);

Next, within HAL_TIM_IC_CaptureCallback() interrupt handler button pressed can be identified using htim->Channel

That's all.

0693W000008yTNkQAM.pngTIMERS_CLOCK_FREQ is 'user constant' I defined

Associate II
August 2, 2024

hi

could you please brief what Input filter will do with input capture data?   how input capture data will affect using this filter and without using this filter?