cancel
Showing results for 
Search instead for 
Did you mean: 

TIM_ICPolarity_ always both edges

Willunen
Associate III
Posted on January 29, 2017 at 12:29

Hi Forum,

Can anyone tell me why

TIM_EncoderInterfaceConfig(TIM2, TIM_EncoderMode_TI1, TIM_ICPolarity_Falling, TIM_ICPolarity_Falling);

doesn't work the way I expect it to?

No matter what I tell it to do, it always counts on both edges of the input signal.

I'm using a STM32F103RB with uVision5.22.

Here is the code:

/*-------------------------------------------*/

GPIO_InitTypeDef GPIO_InitStruct;

TIM_TimeBaseInitTypeDef TIM_TimeBaseStruct;

    

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);

RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);

    

GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;

GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IPU;

GPIO_Init(GPIOA, &GPIO_InitStruct);

    

TIM_TimeBaseStruct.TIM_Period = 0xFF;

TIM_TimeBaseStruct.TIM_Prescaler = 0;

TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStruct);

    

TIM_EncoderInterfaceConfig(TIM2, TIM_EncoderMode_TI1, TIM_ICPolarity_Falling, TIM_ICPolarity_Falling);

    

TIM2->CNT = 0;

TIM_Cmd(TIM2, ENABLE);

/*--------------------------------------*/

Thanks,

Wilko

0 REPLIES 0