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
    September 19, 2019

    Yes, use EXTI interrupts on rising edge for both GPIO pins and have each interrupt routine increment a counter. And I have to ask... but why???? What additional information do you hope to get by counting rising edges? In an encoder interface rising edges aren't the only thing that have meaning.

    Visitor II
    September 25, 2019

    yes but that was not what i am looking for. But anyway thanks.

    Super User
    September 25, 2019

    And what are you looking for, then?

    JW

    Visitor II
    October 1, 2019

    Hi, I taught maybe there is also a way to read out each count value.

    thanks

    Super User
    October 1, 2019

    I still don't understand what do you want. Do you understand how the encoder mode works? There is one single counter, which counts +1 or -1 at every edge of any the inputs, plus a logic determining the direction of counting from the order of the edges. There are not two counters.

    Try to describe the intended application.

    JW

    Visitor II
    March 11, 2024

    I am trying to use encoder interface mode with stm32fx103 but even though i selected TI1 ONLY mode and also selected polarity to RISING by polarity bit but i got DOUBLED counts then my encoder max PPR ,can you please help me....

     

    Visitor II
    October 2, 2019

    Hi JW,

    Yes I know ho an encoder works. For diagnostics we would like to count als the rising and falling edges for each signal (A and B). With this information we now which wire (A or B) is okay or not. So as an example if you see no count in the input CNT register then you can also have a look on the diagnostic count value an check which signal is not okay. So therefore it would be great to count each signal independent from each other.

    Super User
    October 2, 2019

    You can't do that without externally connecting the same signal to a different timer's input (pin).

    One of the inputs (CH1) probably could be set as TRGO, and then in an internally connected trigger used as TRGI and used as external clock. But not both.

    IMO this is not a useful diagnostics; but the project is yours.

    JW

    Visitor II
    October 3, 2019

    Okay many thanks.

    I agree, but my boss wanted to do it that way. Do you know any better way for diagnostic. Maybe I can change his with a better idea.

    mg

    Super User
    October 3, 2019

    Sorry, no. I don't work with encoders. I just can't imagine what information would you extract from counting the individual inputs.

    JW

    Super User
    October 3, 2019

    If you want to count (or detect) transitions on the encoder lines separate from the encoder function, you have 2 choices: (1) run the two encoder lines to two additional timers (one for phaseA and one for phaseB) and have each timer count pulses on one of the two phases, or (2) use EXIT as in my original post. Each timer has only one count register, so it can only count one thing.