I have a requirement to connect 3+ standard rotary encoders (A/B quadrature) into an STM32 - the STM32L072x is the current choice.
While I could bit-bang it, it would be nice if I can just use the standard STM32 TIMx hardware General Purpose Timer (GPT) counters in encoder mode.
However, the datasheet / programming manual is very vague on anything other than a single encoder connected to TI1/TI2 channels of a timer (EG Timer 2 Channels 1 + 2), the CubeMX software appears to let me hang a 2nd encoder from (for example) Timer 2 Channels 3+4.
This would mean I can (for example) connect;
Encoder 1 --> GPTimer 2 CH1+2
Encoder 2 --> GPTimer 2 CH3+4
Encoder 3 --> GPTimer 3 CH1+2
etc...
Is this correct? Has anyone successfully done it?
EDIT: Accepted the correct answer (which is "no you can't"), however it looks like CubeMX actually multiplexed pins, so T2C3/T2C4 are shared with T21C1/T21C2 on the same pins and it was in fact using T21 for the 2nd encoder input.
2 Answers 2
It's not possible. Each TIM module has only 1 (single) counter. Encoder mode is simply a clocking logic, which increments or decrements the single counter according to signals coming from input channels.
TIM2 & TIM3 Diagram showing the counter and encoder signal path
-
1\$\begingroup\$ Thanks, I thought that was what the manual said but for some reason CubeMX allowed me to do it. Luckily the larger footprint chip you can use TIM2, TIM3, TIM21 and TIM22 so looks like I can get up to 4 using hardware. \$\endgroup\$John U– John U2021年01月27日 13:55:05 +00:00Commented Jan 27, 2021 at 13:55
-
1\$\begingroup\$ @JohnU I am currently in need to have more than one encoder, so I think you should make your comment an answer as it is adding valuable info to this topic. \$\endgroup\$smajli– smajli2021年10月19日 12:15:56 +00:00Commented Oct 19, 2021 at 12:15
Well as prompted by @smajli's comment, I will answer my own question with how I did it...
I used a larger device (STM32F411-VET6 in LQFP100 package) and used TIM1, TIM3 and TIM5 in encoder mode, leaving me several other hardware timers for other fuctions such as PWM.
Explore related questions
See similar questions with these tags.