2021-05-17 09:32 AM
Hi all.
I have a rotary encoder which generates 512 ticks per rotation and I would like to generate a single interrupt once the rotary encoder has done a full turn (512 ticks). What would be the best approach? I'm currently looking to see if the STM32 encoder mode supports this or I will have to use some type of input capture?
Thanks
2021-05-17 10:04 AM
You could set the prescaler to 512-1, if you really want to get one interrupt per revolution.
Of course you wouldn't get any interrupt when the encoder turns e.g. ±350° alternately.
Regards
/Peter
2021-05-17 12:49 PM
> You could set the prescaler to 512-1,
I personally wouldn't set the prescaler to other than the default value of 0 in encoder mode. While that actually *would* result in CNT increment after 512 edges (according to particular mode setting) *regardless* of direction and its changes, it practically makes the *encoder* function useless.
What Peter probably meant was setting ARR to 512-1, that would after turning in one direction cause Update event and thus, if enabled, interrupt.
Perhaps a slightly better idea is to connect one of the signals to a second timer's input channel, and set that timer to external clock mode. You can do the interconnect internally, through the TRGI-TRGO mechanism.
JW
2021-05-17 12:55 PM
Or a second TIM in encoder mode but with a finite ARR setting so you get an Update interrupt for each rotation.
Figure the secondary could be a 16-bit where the count fits, and the primary is 32-bit for the long-count.
You'll need to find a way to zero the short-count, of an end-stop or other means.