0
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

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

\$\endgroup\$
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 Jan 27 at 13:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.