2017-08-31 04:27 PM
Board: NucleoF722 with STM32F722
I'm using TIM5 for quadrature encoder counter. I had seen some examples of using CubeMX to do this.
Since I'm interested in quadrature counter, i.e counting 4X the resolution of the encoder disc lines per revolution as generally the case, so I used both input channel TI1 and TI2. The question is why people configured the two input channels trigger polarity as Rising Edge but not Both Edge? Isn't that the Quad counter should count on both edges of each channel (total 4 counts per one period of one input pulse)? In fact the RM0432 Reference Manual page 645 for register MITxCCER says:
'
.......
11: noninverted/both edges
Circuit is sensitive to both TIxFP1 rising and falling edges (capture, trigger in reset, externalclock or trigger mode), TIxFP1 is not inverted (trigger in gated mode). This configurationmust not be used for encoder mode.'
Anyone know why the polarity must be set to Rising Edge instead of Both Edge?
A screenshot below was borrowed from other posting member on the same subject, and I posted below as a reference.
Best,
Brian
#stm32f3-timer-encoder-mode #encoder2017-08-31 06:56 PM
Further reading in the Reference Manual, I think this Polarity select bit is mean to select inverted or non-inverted signal of the input channel (TI1 or TI2), and not meant to say the triggering edge (In the CubeMX this should say 'Inverted Input' or 'non-inverted input' instead of Rising Edge or Falling Edge. And of course the Both Edge selection should be deleted from the pull down box.
2017-09-06 04:33 AM
Hello
dang.brian
,I raised your feedback and issue to the appropriate team for check and will keep you informed about thetaken actions or explanation if needed.
Also, your feedback in this discussion is reported
https://community.st.com/0D50X00009XkdsRSAR
Best Regards
Imen
2017-09-06 07:11 AM
Hello !
The encoder(MCU) takes as Input two digital lines .
Theese lines carry 2 bit of information.
The information is just edges and states with 90 deg. phase difference.
The encoder gives an output data also with two bits of information
One bit is the counter revolution and the other bit is the direction.
It is not possible to have 4x resolution without lose the direction.
So if you detect both edges at one channel there will be an ambiguity about the direction because the edge from other channel will be occur at 180 degrees... in the midle of the two detected edges.. and so on.
In case the polarities are different the direction changes (it is not something abnormal)
About 'Both Edge selection' in STM32 cube i think also that must be eliminated.
Regards
vf
2017-09-06 10:33 AM
Hi VF,
'
It is not possible to have 4x resolution without lose the direction.'
4X resolution means the encoder counter has an output count of 4X the resolution lines on the encoder disc or scale; i.e. a 1000-line optical disc will generate a total 4000 counts in one turn of the disc. This is a very common standard in the motion industry.
'
So if you detect both edges at one channel there will be an ambiguity about the direction because the edge from other channel will be occur at 180 degrees...'
This is not quite true. In Encoder Mode, the user can select to count only on one input, TI1 (2X resolution) or TI2 (2X res) , or both inputs (4X res), by setting SMS bits of TIMx_SMCR register, and regardless of counting only one or both inputs the counter always triggers on BOTH EDGES, no option about this.
The Direction is determined by the logic state of the other input (90* out of phase from the one having triggering edge). Review the Encoder Mode in the Reference Manual rev1, Figure 170 will show how it works in 4X resulution (4 counts in one period of input channel).
Best,
Brian
2017-09-06 12:44 PM
Hi VF,
We're discussing the STM32 Timer works in Encoder Mode, and so I take encoder as quadrature or 2X encoder, anything with 50% duty signal waveform including washer machine motor encoder, angle sensor or even gyro, as long as their outputs the definition of 2X or 4X encoder signal.
'
In this figure you supposed that the direction is given and you wrote that the resolution is x4. But the direction is not given. It takes at least a whole pulse to have certainty about direction.'
The direction is given within a count unit of the resolution. what do you mean 'a whole pulse'? A full period of TI1 or TI2? The direction is ambiguity only within a 1/4 of the input pulse period, just as the encoder count resolution. The counter in Fig 170 starts from 0 and counting up, and so when the count changed from 0 to 1, we can tell that it's counting up or moving CW, or when it changed from 10 to 9 then it is moving CCW. No direction? In fact there is a register (TIMx_DIR) that can be read for Direction.
Btw, do anyone know why clicking the ST logo on the upper left corner of this page does not return to ST.com home page? How do you get back to ST home?
Best,
Brian
2017-09-06 01:49 PM
Hello Brian!
There is some misunderstanding in terminology i think.
English is not my mother language.
In every use of term '' encoder'' i mean incremental quadrature encoder that measure counts and direction continuously . It can be a sound volume knob, an angle sensor of a gyro stabilized weapon, etc There are a lot of devices so called encoders like washing machines motors ''encoders'' but they measure speed or other magnitudes
I am sure, when you say ''
1000-line optical disc will generate a total 4000 counts in one turn of the disc
'' you mean that the direction is the same .. The same approach used to measure the motors position in one direction. (of course this a way to have better resolution but with specific conditions only)But just think ''
Is it possible to know the exact position of an encoder with 4x resolution in case the direction changes unpredictably
?''According to
Reference Manual rev1, Figure 170 Not.
This direction ambiguity has width, at least one complete pulse. and not 1/4. not even 1/2.
In this figure you supposed that the direction is given and you wrote that the resolution is x4. But the direction is not given. It takes at least a whole pulse to have certainty about direction.
Regards
VF
2017-09-06 10:01 PM
Hi Brian!
>>>>
what do you mean ''a whole pulse''? A full period of TI1 or TI2? I mean the positive only part of the period.. period TI1 = period TI2 because the outputs of the encoder going to TI1 and TI2 are mechanicaly connected (90deg diff)
I use this pulse as the nominal encoders resolution. Pulses Per Revolution (PPR) .
You use as resolution the Counts Per Revolution. (CPR) . I will never say that is wrong but must mention the details.
>>>direction is ambiguity only within a 1/4 of the input pulse period, just as the encoder count resolution''
Look at this figure (
AN4013
STM32 cross-series timer overview) The ambiguity is not 1/4. (hilighted DIR bit and gap)
Just make an emulation with mind, what will hapen if we change the direction of a rotary Q encoder every 1/2 (2x1/4 , as you wrote the ambiguity is 1/4)
The uper left ST logo leads to community and i didn't find any other way than having an opened browser window to st.com
Best Regards.
vf
2017-09-08 12:04 PM
VF,
So you said there was direction ambiguity for half of a line resolution of the encoder disc (a line resolution is the spatial includes the dark and clear of the lines). No, in quadrature encoder both the count and direction have resolution within ¼ of the lines resolution, not ½ as you think.
Reference to Fig 7 above and during the time t that you highlighted, TI1 doing up, down, up while TI2 stays low, the counter went through 3 events: +1, -1, +1, although in the Fig 7 it doesn’t show the counter is counting during the highlighted zone for some reasons, but I’m pretty sure in reality it counted +1, -1, +1 and the DIR bit changed accordingly.
Best,
Brian