2021-06-17 06:55 AM
Hi, I am using STM32F407 for my PMSM vector control project. And i need to determine the current position of motor for vector control. So I use TIM3 Encoder MODE (x4) and ı have 360 PPR (pulse per revolution) encoder. I set the ARR value 1439 (4*360-1). Encoder Mode : TI1 and TI2. Input filter 15 for both input. I didnt change anything but these. Finally i read the Tim3 CNT register value every 100us. (Encoder_val = htim3.instance->CNT).
For example I determine a position on encoder and watch the Encoder_val variable in debug mode. Suppose the value is 50. Then I turn the encoder one revolution and in the same position new Encoder_val value is 47. It is missing every single turn for both direction (2 or 3 count).
Has anyone encountered this problem before? What am I doing wrong? will be happy if you help. Thank you.
Solved! Go to Solution.
2021-06-18 01:05 AM
If you can't see problem with the setting of timer, observe the physical signals as they arrive using oscilloscope. Observe the voltage levels and the time difference between the edges.
JW
2021-06-17 07:09 AM
> TI1 and TI2. Input filter 15 for both input.
That's how much in microseconds? Can't that be more than the shortest pulse when you turn the motor? How exactly are the relevant TIM registers set? Read them out and check.
JW
2021-06-17 08:12 AM
I don't understand what you mean. Actually I turn the motor by my hand to watch rotor positon accuracy therefore the rotor speed is too low. i m not turning the motor without correct rotor angle.
2021-06-17 09:35 AM
> therefore the rotor speed is too low.
That does not mean the pulses are not short.
> I don't understand what you mean.
If the filter's setting is longer than the duration of pulses, those pulses may get filtered out.
Read out the timer registers content and calculate the duration of filter from timer's clock the DTS prescaler and the particular filter settings, according to the description of TIMx_CCMRx.ICxF field in TIM chapter of RM.
JW
PS. What's the content of TIMx_PSC?
2021-06-17 12:39 PM
I understand what you mean. My clock frequency is 168 MHz (***_INT) and fDTS = 168MHz because prescale division ratio setting is no division. According to the reference manual .
0000: No filter, sampling is done at fDTS
0001: fSAMPLING=***_INT, N=2
0010: fSAMPLING=***_INT, N=4
0011: fSAMPLING=***_INT, N=8
0100: fSAMPLING=fDTS/2, N=6
0101: fSAMPLING=fDTS/2, N=8
0110: fSAMPLING=fDTS/4, N=6
0111: fSAMPLING=fDTS/4, N=8
1000: fSAMPLING=fDTS/8, N=6
1001: fSAMPLING=fDTS/8, N=8
1010: fSAMPLING=fDTS/16, N=5
1011: fSAMPLING=fDTS/16, N=6
1100: fSAMPLING=fDTS/16, N=8
1101: fSAMPLING=fDTS/32, N=5
1110: fSAMPLING=fDTS/32, N=6
1111: fSAMPLING=fDTS/32, N=8
My FSAMPLING is 168000000/(32*8)=656.25 kHz. Maybe I need to increase the cutoff frequency. I am going to try to reduce input filter and give you a feedback tomorrow. Thank you for your help.
2021-06-17 01:39 PM
What's the content of TIMx_PSC?
JW
2021-06-17 01:52 PM
Prescaler value is 1.
static void MX_TIM3_Init(void)
{
TIM_Encoder_InitTypeDef sConfig = {0};
TIM_MasterConfigTypeDef sMasterConfig = {0};
htim3.Instance = TIM3;
htim3.Init.Prescaler = 0;
htim3.Init.CounterMode = TIM_COUNTERMODE_UP;
htim3.Init.Period = 1439;
htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
sConfig.EncoderMode = TIM_ENCODERMODE_TI12;
sConfig.IC1Polarity = TIM_ICPOLARITY_RISING;
sConfig.IC1Selection = TIM_ICSELECTION_DIRECTTI;
sConfig.IC1Prescaler = TIM_ICPSC_DIV1;
sConfig.IC1Filter = 15;
sConfig.IC2Polarity = TIM_ICPOLARITY_RISING;
sConfig.IC2Selection = TIM_ICSELECTION_DIRECTTI;
sConfig.IC2Prescaler = TIM_ICPSC_DIV1;
sConfig.IC2Filter = 15;
if (HAL_TIM_Encoder_Init(&htim3, &sConfig) != HAL_OK)
{
Error_Handler();
}
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
if (HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig) != HAL_OK)
{
Error_Handler();
}
}
2021-06-18 01:05 AM
If you can't see problem with the setting of timer, observe the physical signals as they arrive using oscilloscope. Observe the voltage levels and the time difference between the edges.
JW
2021-06-19 05:33 AM
I have tried to reduce filter. Nothing was changed. Then I observe the encoder signal from oscilloscope and count the pulses. I saw jitter on the A and B signals. The jitter bacuse of the IPMSM magnet. I removed the encoder from the motor. I tried to see change of the counter on the oscilloscope and debugger . There is no jitter and no counting problem when i turn the encoder away from the motor shaft. When i turn the rotor with my hand encoder is turning but while i release the motor, encoder is jitter. I think the problem is caused by jitter. I m still thinking and searching.