AnsweredAssumed Answered

Quadrature Encoder (STM32F4) counts not working properly at high speeds

Question asked by perera.duminda on Mar 31, 2014
Latest reply on Apr 23, 2014 by lewis.william
I am using the TIM1 in the stm32f4 in encoder interface mode to get position. The two chanels of my rotary quadrature encoder are connected to the pins A8 and A9 through a comparator. The outputs from the comparator can be seen as two nice square waves on a scope.

At low speeds the timer counts perfectly well. But at slightly moderate speeds the timer losses a lot of counts and does not work properly. At high speeds it performs very badly.

I configured the GPIO pins as such;
GPIO_InitTypeDef GPIO_InitStructure;
 
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOA, &GPIO_InitStructure);
     
GPIO_PinAFConfig(GPIOA, GPIO_PinSource8, GPIO_AF_TIM1);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_TIM1);

The timer was configured as such;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
     
TIM_TimeBaseStructure.TIM_Prescaler = 0;
TIM_TimeBaseStructure.TIM_Period = 0xFFFFFFFF; // Maximal
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);
TIM_EncoderInterfaceConfig(TIM1, TIM_EncoderMode_TI1, TIM_ICPolarity_Rising, TIM_ICPolarity_Rising);
TIM_Cmd(TIM1, ENABLE);

Why is the timer loosing counts? 
Should I also configure input capture for the two channels of TIM1?
What am I doing wrong here?

Outcomes