AnsweredAssumed Answered

How to config my timer to count external pulses

Question asked by farkash on Jul 2, 2014
Latest reply on Jul 3, 2014 by farkash
Hello everybody,

How can i config my timer ( i work on stm32f100 ) to count external pulses
this is my code but it doesn't work:

void
ConfigTimer17(void)
{
 
 GPIO_InitTypeDef GPIO_InitStructure;
  TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
 
 
  /* TIM17 clock enable */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM17, ENABLE);
 
  /* GPIOB Configuration: TIM17 CH1 (PB9) */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; 
  GPIO_Init(GPIOB, &GPIO_InitStructure);
 
    /* Connect TIM17 pins to AF */
  GPIO_PinRemapConfig(GPIO_Remap_TIM17,DISABLE); //<--> PB9
 
 TIM_TimeBaseStructure.TIM_Period = 65535;
  TIM_TimeBaseStructure.TIM_Prescaler = 0;
  TIM_TimeBaseStructure.TIM_ClockDivision = 0;
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
  TIM_TimeBaseInit(TIM17, &TIM_TimeBaseStructure);
 
  TIM_TIxExternalClockConfig(TIM17, TIM_TIxExternalCLK1Source_TI1, TIM_ICPolarity_Rising, 0);
 
  TIM_Cmd(TIM17, ENABLE);

 
///////////////////////////////////////////
}


when i read capture1 ( TIM_GetCapture1(TIM17)) i get random numbers ( also negative ).

thanks in advance

Outcomes