Skip to main content
clonephone82
Associate III
Sep 19, 2019 9:28 AM UTC
Question

Encoder Mode and also get the counts (rising edge) from each input.

Dose someone know if it is possible to use TM3 in Encoder Mode. And also get the internal detected counts for each input. I use TIM3 channel 1 and 2 for the encoder.

many thanks

This topic has been closed for replies.

15 replies

waclawek.jan
Super User
Oct 3, 2019 7:11 PM UTC

There is one more option, more of a trick - count one input as I've outlined above, through the TRGO-TRGI timers link, and use the other to trigger dummy DMA transfers, then NDTR of the DMA is your counter.

JW

waclawek.jan
Super User
Mar 11, 2024 5:00 PM UTC

> i got DOUBLED counts

The original STM32 timer supports only x4 and x2 modes (newer STM32 such as 'G4 supports also x1).

Simply divide what you read out from TIMx_CNT by two.

JW

Visitor II
Mar 12, 2024 12:21 PM UTC

but where i am learning these they said to do these task without dividing it and if you know where it is exactly written about how many times it mutiplied then please mention it...

 

waclawek.jan
Super User
Mar 12, 2024 1:28 PM UTC

It is not *multiplied*. The x2 mode just means, that for every cycle (which contains 1 pulse = 2 edges on signal A and 1 pulse = 2 edges on signal B) the counter counts +-2 (because it counts both the rising and falling edge of one of the signals). The x4 mode counts both edges on both signals, so that is +-4 per cycle.

waclawekjan_0-1710249760576.png

"Polarity selection" in Encoder mode is a bit misleading name (but is in fact good name for the main purpose of the timer channels set as input, i.e. Input Capture); in encoder mode this does not *select* the edge, but determines, whether the input signal is inverted or not, before it enters the decoder.

> where i am learning these they said to do these task without dividing it

You can't.

Your teacher maybe wants you to set the prescaler (TIMx_PSC) to perform that division, but I recommend not to do that (or you can do that just to fulfull a school assignment, but don't use it for real application).

JW