cancel
Showing results for 
Search instead for 
Did you mean: 

Questions related to encoders in STM32MotorControl code

Kevin8
Associate

Hardware: EVLSERVO1 official motor evaluation board
In the "ENC Calc Angle" function, there is a step to perform bitwise AND operation 0x7ffffff on TIM ->CNT, multiply it by the unsigned 32-bit maximum value divided by the polar logarithm. Its left value is a number of type uint32/t, which can cause data overflow. I don't quite understand how it converts pulse values into electrical angles. As shown in the following figure企业微信截图_17655092006150.pngimage.png

1 REPLY 1
GMA
ST Employee

Hello @Kevin8,

According to defined values:
PulseNumber = M1_ENCODER_PPR * 4 (for ultra-high-resolution encoder can offer up to 50,000 PPR).
U32MAXdivPulseNumber = UINT32_MAX / PulseNumber = UINT32_MAX / (M1_ENCODER_PPR * 4)
Timer2 Auto-reload register is set to 
M1_PULSE_NBR = ((4 * (M1_ENCODER_PPR)) - 1) (which is the maximum Counter value).
Then uwtemp1 is lower than UINT32_MAX.

If you agree with the answer, please accept it by clicking on 'Accept as solution'.
Best regards.
GMA