AnsweredAssumed Answered

Problem with prescaler TIMER in ENCODER mode

Question asked by evgen on Apr 18, 2014
Latest reply on May 29, 2014 by waclawek.jan

Hi
I configured the timer in encoder mode with prescaler:

RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);

GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_8 | GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_UP ;
GPIO_Init(GPIOA,&GPIO_InitStructure); 
  
GPIO_PinAFConfig(GPIOA, GPIO_PinSource8, GPIO_AF_TIM1);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_TIM1);

TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);  
TIM_TimeBaseStructure.TIM_Period = PERIOD;
TIM_TimeBaseStructure.TIM_Prescaler = 0x0001;  //PROBLEM!!!!
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseStructure.TIM_RepetitionCounter = 0x0000; 
TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);

TIM_EncoderInterfaceConfig(TIM1, TIM_EncoderMode_TI12, TIM_ICPolarity_Rising, TIM_ICPolarity_Rising);
TIM1->CNT = 0;              
TIM_Cmd(TIM1, ENABLE);

and found a strange thing...
Encoder does not work properly if prescaler = 1 or 3 or 5 or 7 and ect...
and Encoder does work properly if prescaler = 0 or 2 or 4 or 6 and ect...

what I mean correct:
I connected to STM32f405 only channel A of encoder and channel B is not connected
if prescaler = 1 or 3 or 5 or 7 and ect... timer make increment count, but it is not correct
if prescaler = 0 or 2 or 4 or 6 and ect... timer not make increment count, this is correct, becouse channel B is not connected

How solved this problem?

Outcomes