2024-01-20 01:32 AM
hi friends,
In STM32F412 microcontroller with HAL Library
I put timer 2 in encoder mode and everything works fine
I want, for example, if the counter reaches 1500, an interruption will occur, but I don't want the counter value to be reset after this interruption.
How can I do this?
I want the number 1500 to be recognized very quickly. When I check this value in the Super loop, every time the CPU may be involved in small delays (like LCD Update) and exceed the set value.
The things I did -> I thought it was possible to use timer 3 as a slave so that timer 3's clock is supplied from counter timer 2 But I was not successful
Thanks,
2024-01-20 06:38 AM
Interrupts don't reset the counter. Perhaps if it hits ARR, it will roll over. That is expected and avoidable by setting ARR higher than 1500.
Your handling of the encoder shouldn't rely on hitting any one particular value exactly.
2024-01-20 12:39 PM - edited 2024-01-20 12:40 PM
> Your handling of the encoder shouldn't rely on hitting any one particular value exactly.
+1
However, if you set ARR higher than 1500 as you should, and want to have an interrupt when the counter is 1500, just set up one of the channels to Compare (any mode, may be PWM, you don't need to set up any pin in GPIO to be at this channel) and its CCRx to 1500, and enable its interrupt by setting corresponding TIMx_DIER.CCxIE, enable in NVIC and write a proper interrupt handler.
This probably can be clicked somehow in CubeMX, I don't use it.
JW