cancel
Showing results for 
Search instead for 
Did you mean: 

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

TDJ
Senior III

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

1 ACCEPTED SOLUTION

Accepted Solutions
TDJ
Senior III

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

View solution in original post

1 REPLY 1
TDJ
Senior III

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