Using the encoder mode with TIM4
Hi all, I'm using an STM32F4Discovery (it's and STM32F407VGT6 on it).
I'm trying to use the TIM4 timer to read a quadratic encoder (plugged on PB6-PB7), but somehow, it doesn't work.I'm using exactly the same code with TIM8 and it does work (plugged on PC6-PC7). I validate the working code by reading the counter in GDB after turning the encoder by hand.void
configureEncoder
()
{
RCC_AHB1PeriphClockCmd
(
RCC_AHB1Periph_GPIOB
,
ENABLE
);
RCC_APB1PeriphClockCmd
(
RCC_APB1Periph_TIM4
,
ENABLE
);
GPIO_InitTypeDef
GPIO_InitStructure
;
GPIO_InitStructure
.
GPIO_Mode
=
GPIO_Mode_AF
;
GPIO_InitStructure
.
GPIO_Speed
=
GPIO_Speed_100MHz
;
GPIO_InitStructure
.
GPIO_OType
=
GPIO_OType_PP
;
GPIO_InitStructure
.
GPIO_PuPd
=
GPIO_PuPd_NOPULL
;
GPIO_InitStructure
.
GPIO_Pin
=
GPIO_Pin_6
|
GPIO_Pin_7
;
GPIO_Init
(
GPIOB
,
&
GPIO_InitStructure
);
GPIO_PinAFConfig
(
GPIOB
,
GPIO_PinSource6
,
GPIO_AF_TIM4
);
GPIO_PinAFConfig
(
GPIOB
,
GPIO_PinSource7
,
GPIO_AF_TIM4
);
/* Configure the timer */
TIM_EncoderInterfaceConfig
(
TIM4
,
TIM_EncoderMode_TI12
,
TIM_ICPolarity_Rising
,
TIM_ICPolarity_Rising
);
/* TIM4 counter enable */
TIM_Cmd
(
TIM4
,
ENABLE
);
}
I expect my error to be simple, but I'm blind. I did not forget to move the physical wires between TIM8 and TIM4.Both full codes are here:https://gist.github.com/nraynaud/5082298
If you want some Stackoverflow love, here is the question:http://stackoverflow.com/questions/15203069/stm32-rotary-encoder-config-on-tim4
Thanks for your help,Nico #stm32-timer-counter