Question
help! - I couldnot get stm32f4 timer work in encoder mode
Posted on October 20, 2013 at 19:17
hello dear forum,
I am trying to read an AB encoder with stm32f4 timer_1 I got the encoder signals through 75175 to timer_1_ch1 and ch2 pins I can see square waves of A and B with osciloscope the codes are below - any help appreciated - thank youvoid
Encoderinit(
void
) {
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9|GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOE, &GPIO_InitStructure);
GPIO_PinAFConfig(GPIOE,GPIO_PinSource9,GPIO_AF_TIM1);
GPIO_PinAFConfig(GPIOE,GPIO_PinSource11,GPIO_AF_TIM1);
/* Time base configuration */
TIM_TimeBaseStructure.TIM_Period = 0xffff;
TIM_TimeBaseStructure.TIM_Prescaler = 0;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);
TIM_EncoderInterfaceConfig(TIM1,TIM_EncoderMode_TI12,TIM_ICPolarity_Rising,TIM_ICPolarity_Rising );
TIM_ITConfig(TIM1,TIM_IT_Update , ENABLE);
TIM_Cmd(TIM1, ENABLE);
TIM1->CNT=0;
} and in the main loop I read enkoder 100 times a second but always value 0
main{
..................
Encoderinit()
..................
while
(1){
..................
enkoder=TIM1->CNT;
}
#tim-encoder #tim-encoder #stm32f4-timer-encoder