Skip to main content
Visitor II
September 19, 2019
Question

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

  • September 19, 2019
  • 13 replies
  • 4209 views

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.

    13 replies

    Super User
    October 3, 2019

    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

    Super User
    March 11, 2024

    > 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
    March 12, 2024

    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...

     

    Super User
    March 12, 2024

    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