AnsweredAssumed Answered

TIM5 counter

Question asked by jamp on Sep 2, 2016
Latest reply on Jan 11, 2017 by Khouloud G
Hi all,

I want to count pulses from an input, using TIM5 channel 3, I have tried with channel 1 and it is working but I cannot make it works in channel 3 , can someone let me know what can be wrong.

This is the code:
 
   GPIO_InitTypeDef GPIO_InitStructure;
   TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;

   /* GPIOH clock enable */
   RCC_AHB1PeriphClockCmd (RCC_AHB1Periph_GPIOH, ENABLE);

   /* TIM5 clock enable */
   RCC_APB1PeriphClockCmd (RCC_APB1Periph_TIM5, ENABLE);


   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
   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_UP; 
   GPIO_Init(GPIOH, &GPIO_InitStructure);

   GPIO_PinAFConfig(GPIOH, GPIO_PinSource12, GPIO_AF_TIM5);

  TIM_TimeBaseStructure.TIM_Period = 65535;
  TIM_TimeBaseStructure.TIM_Prescaler = 0;
  TIM_TimeBaseStructure.TIM_ClockDivision = 0;
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
  TIM_TimeBaseInit (TIM5, &TIM_TimeBaseStructure);

  TIM_TIxExternalClockConfig (TIM5, TIM_TIxExternalCLK1Source_TI1, TIM_ICPolarity_Rising, 0);

  TIM_Cmd (TIM5, ENABLE);

Thanks

Outcomes