cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4 Timer encoder mode

Turbonatta
Associate

Good morning everyone,

I'd like some help on this problem.

On a WeAct BlackPill board equipped with STM32F411CEU6 I wrote a fairly simple program using the encoder mode on Timer2 to keep up with count and direction.

I activated the interrupt feature as well since I need to generate some signal base on certain counter value.

My problem is the HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim) that is call only half of the time.

I know this by a variable which is incremented every time the funcion is called and compare it the the counter value and is exactly half.

I put a breakpoint on HAL_TIM_IRQHandler(TIM_HandleTypeDef *htim) and trace the code and notice that both interrupt flag of each input it's handled and the same CaptureCallback is called.

I know there are other ways to manage quadrature encoder but I thought since the feature it's available on the timer I could use it.

Before changing method I'd like to know if I am doing something wrong.

Thanks

1 REPLY 1

This may be an inherent limitation.

The counter in encoder mode counts upon both edges, but the interrupts on both edges are disabled:

waclawekjan_0-1723541775494.png

One way to work around this could be feeding *externally* the signals also to channels 3 and 4 of the same timer, and setting up the interrupt on both edges.

Of course, using Cube/HAL is usually a hindrance for anything other than what can be simply clicked in CubeMX.

JW