AnsweredAssumed Answered

STM32F030F4 Encoder - only working on some ports of Timer

Question asked by berti on Dec 1, 2014
Latest reply on Dec 6, 2014 by berti
Hi,
since a couple of days I'm trying to get an optical encoder to work with the STM32F030F4. I followed the product specification on p. 19 which is telling me "TIM3 timer is capable of handling quadrature (incremental) encoder signals". So I tried to get it work on PA6 and PA7 - success. But I need these ports for SPI, so I tried basically the same code for PA6 and PB1, which is TIM3 too, but fails.
Here the source code:
GPIO_InitTypeDef GPIO_InitStructure;
  
/*TIM3 clock source enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
  
/* Enable GPIO, clock */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
  
/* Encoder unit connected to TIM3, quadrature mode */
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_6;
GPIO_Init(GPIOA, &GPIO_InitStructure);
  
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 ;
GPIO_Init(GPIOB, &GPIO_InitStructure);
  
GPIO_PinAFConfig(GPIOA, GPIO_PinSource6, GPIO_AF_1);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource1, GPIO_AF_1);
  
  
TIM_EncoderInterfaceConfig(TIM3, TIM_EncoderMode_TI12,  TIM_ICPolarity_Falling, TIM_ICPolarity_Falling);
TIM_Cmd(TIM3, ENABLE);

Does anyone have a solution to this (even if it's on another series of ST uC)?

Thanks!

Outcomes