cancel
Showing results for 
Search instead for 
Did you mean: 

stm32f401rc encoderMode of tim9 do not work

YunHao Zhang
Associate
Posted on October 31, 2017 at 11:27

I used the PA2 PA3,the TIM9->CNT do not change

void MotorBEncoder_Init(void)

{

TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;

TIM_ICInitTypeDef TIM_ICInitStructure;

GPIO_InitTypeDef GPIO_InitStructure;

RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM9, ENABLE);

RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;

GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;

GPIO_Init(GPIOA, &GPIO_InitStructure);

GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_TIM9);

GPIO_PinAFConfig(GPIOA, GPIO_PinSource3, GPIO_AF_TIM9);

TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);

TIM_TimeBaseStructure.TIM_Prescaler = 0x0;

TIM_TimeBaseStructure.TIM_Period = 0;

TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;

TIM_TimeBaseInit(TIM9, &TIM_TimeBaseStructure);

TIM_EncoderInterfaceConfig(TIM9, TIM_EncoderMode_TI12, TIM_ICPolarity_Rising, TIM_ICPolarity_Rising);

TIM_ICStructInit(&TIM_ICInitStructure);

TIM_ICInitStructure.TIM_ICFilter = 5;

TIM_ICInit(TIM9, &TIM_ICInitStructure);

TIM_SetCounter(TIM9,0);

TIM_Cmd(TIM9, ENABLE);

}
1 REPLY 1
Jan Waclawek
Senior II
Posted on October 31, 2017 at 11:49

TIM_TimeBaseStructure.TIM_Period = 0;

Set it to nonzero - best to 0xFFFF.

JW