cancel
Showing results for 
Search instead for 
Did you mean: 

TIM_encodermode_TI1 - why doesnot it count ?

mehmet.karakaya
Associate III
Posted on December 28, 2010 at 15:15

TIM_encodermode_TI1 - why doesnot it count ?

#encoder #timer
4 REPLIES 4
lowpowermcu
Associate II
Posted on May 17, 2011 at 14:19

Hi mehmet,

Is the RCC and GPIO well configured for TIM4 ?

Can you give us your configuration so perhaps I can help you.

Herzlich,

 

MCU Lüfter

lowpowermcu
Associate II
Posted on May 17, 2011 at 14:19

Hi mehmet,

Your config looks fine.

Check that the encoder interface signals are toggling and well connected to PB6 and PB7.

Good luck.

Herzlich,

 

MCU Lüfter

mehmet.karakaya
Associate III
Posted on May 17, 2011 at 14:19

hello thank you , here are the routines I wrote

---------------------------

void TIM4init(void) {

  TIM_TimeBaseStructure.TIM_Period = 0xffff;

  TIM_TimeBaseStructure.TIM_Prescaler = 0;

  TIM_TimeBaseStructure.TIM_ClockDivision = 0;

  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;

  TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);

  TIM_EncoderInterfaceConfig(TIM4,TIM_EncoderMode_TI1,TIM_ICPolarity_Rising,TIM_ICPolarity_Rising );

  TIM_Cmd(TIM4, ENABLE);

    TIM4->CNT=0; } ------------------------------

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9|GPIO_Pin_8|GPIO_Pin_7|

                                GPIO_Pin_6|GPIO_Pin_5;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;

  GPIO_Init(GPIOB, &GPIO_InitStructure);

------------------------------

RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);

------------------------------

and in the main loop

{

  int16_t *RAMptr=&RAM[DATAWORDS+500*2];  

  *RAMptr= TIM4->CNT; }

I can watch the *RAMptr in the PC with my comunication program, no problem there

I tried to give pulse PB6 , direction PB7 and vice versa - no counting ( they are TIM4_CH1 & CH2 )

( btw I have STM32F103RC )

mehmet.karakaya
Associate III
Posted on May 17, 2011 at 14:19

Hello MCU Lüfter , I think I discovered a bug in STM32  🙂

I checked the signals, everything is fine with my circuit

the problem is no matter what encoder mode is selected

the Timer counts only phase shifted A B encoder mode

I mean I selected TIM_EncoderMode_TI1 and TIM_EncoderMode_TI2

the timer counted only when I simulated phase shifted A B signals

on the CH1 and CH2 inputs