AnsweredAssumed Answered

STM32 Rotary Encoder config

Question asked by piker on Aug 22, 2012
Latest reply on Aug 23, 2012 by Clive One

I am trying to use timer 8 in Encoder mode and my setup is as follows. Pins PC8 and PC9 (timer8) are connected to a cheap 3 terminal encoder that has C pin grounded so pullups are activated on these pins.

TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; 
GPIO_InitTypeDef GPIO_InitStructure; 
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE); 
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9; 
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; 
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; 
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; 
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; 
GPIO_Init(GPIOC, &GPIO_InitStructure); 
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM8, ENABLE); 
TIM_TimeBaseStructure.TIM_Period = 0x0FFF; 
TIM_TimeBaseStructure.TIM_Prescaler = 0; 
TIM_TimeBaseStructure.TIM_ClockDivision = 0; 
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; 
TIM_EncoderInterfaceConfig(TIM8,TIM_EncoderMode_TI1,TIM_ICPolarity_Falling, 
TIM_ICPolarity_Falling); 
TIM_TimeBaseInit(TIM8, &TIM_TimeBaseStructure); 
TIM_Cmd(TIM8, ENABLE); 

I then read the counter with temp=TIM_GetCounter(TIM8);

I have tried all the possible modes and falling/rising combos I can and am getting nothing. Does the Timer channel have any effect. It is using channels 3 and 4
I assume that there doesn't need to be any interrupts setup but maybe this is incorrect.

Any suggestions would be appreciated. Thanks

Outcomes