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

Bob S
Super User
Sep 19, 2019 7:07 PM UTC

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.

clonephone82
Associate III
Sep 25, 2019 8:22 AM UTC

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

waclawek.jan
Super User
Sep 25, 2019 11:11 AM UTC

And what are you looking for, then?

JW

clonephone82
Associate III
Oct 1, 2019 5:57 AM UTC

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

thanks

waclawek.jan
Super User
Oct 1, 2019 6:40 AM UTC

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
Mar 11, 2024 3:44 PM UTC

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

 

clonephone82
Associate III
Oct 2, 2019 12:44 PM UTC

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.

waclawek.jan
Super User
Oct 2, 2019 1:42 PM UTC

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

clonephone82
Associate III
Oct 3, 2019 5:44 AM UTC

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

waclawek.jan
Super User
Oct 3, 2019 7:04 AM UTC

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

JW

Bob S
Super User
Oct 3, 2019 5:36 PM UTC

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.