Skip to main content
TDJ
Senior III
Feb 24, 2021 11:45 PM UTC
Solved

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

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

This topic has been closed for replies.
TDJ
TDJBest answer
Senior III
Mar 31, 2021 7:11 PM UTC

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

2 replies

TDJ
TDJAuthorBest answer
Senior III
Mar 31, 2021 7:11 PM UTC

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
Aug 2, 2024 10:47 AM UTC

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?