cancel
Showing results for 
Search instead for 
Did you mean: 

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

clonephone82
Associate III

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

15 REPLIES 15
Bob S
Principal

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.

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

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

 

> 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

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

 

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