AnsweredAssumed Answered

STM32f407 external pulse counter channel selection

Question asked by jakos.anze on Aug 21, 2013
Latest reply on Apr 28, 2014 by jobin.jean_marc
Hi guys,

I am having a big problem;

I would like to count external pulses with 2 timers; TIM 2 and TIM5. The problem is, that I need to connect my two timers to the 2 I/O pins that are free. So that means I need to select a channel for each of them. And I just can't find any channel selection for counting external pulses.

So I chose TIM2 ch4 on PB11 and TIM5 ch4 on PA3. I need to use 32bit counters.

How do I enable any other channel that default channel, which is ch1?

Many thanks guys

void PulseCounter(void)
{
 
 
      GPIO_InitTypeDef GPIO_InitStructure;
      TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
 
 
 
 
      RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE); 
 
 
 
 
      /* GPIOx clock enable */
      RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
      RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
 
 
      /* TIM2,TIM5 clock enable */
      RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
      RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM5, ENABLE);
 
      /* GPIOA Configuration: TIM2 CH4 (PB11) */
      GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
      GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; // Input/Output controlled by peripheral
      GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
      GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
      GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; // Button to ground expectation
      GPIO_Init(GPIOB, &GPIO_InitStructure);
 
      /* GPIOA Configuration: TIM5 CH4 (PA3) */
      GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
      GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; // Input/Output controlled by peripheral
      GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
      GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
      GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; // Button to ground expectation
      GPIO_Init(GPIOA, &GPIO_InitStructure);
 
 
 
 
        /* Connect TIM2 pins to AF */
      GPIO_PinAFConfig(GPIOB, GPIO_PinSource11, GPIO_AF_TIM2);
 
        /* Connect TIM5 pins to AF */
      GPIO_PinAFConfig(GPIOA, GPIO_PinSource3, GPIO_AF_TIM5);
 
 
 
      TIM_TimeBaseStructure.TIM_Period = 500000;
      TIM_TimeBaseStructure.TIM_Prescaler = 0;
      TIM_TimeBaseStructure.TIM_ClockDivision = 0;
      TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
      TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
 
      TIM_TimeBaseStructure.TIM_Period = 500000;
      TIM_TimeBaseStructure.TIM_Prescaler = 0;
      TIM_TimeBaseStructure.TIM_ClockDivision = 0;
      TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
      TIM_TimeBaseInit(TIM5, &TIM_TimeBaseStructure);
 
      TIM_TIxExternalClockConfig(TIM2, TIM_TIxExternalCLK1Source_TI1, TIM_ICPolarity_Falling, 0);
      TIM_TIxExternalClockConfig(TIM5, TIM_TIxExternalCLK1Source_TI1, TIM_ICPolarity_Falling, 0);
 
 
      TIM_Cmd(TIM2, ENABLE);
      TIM_Cmd(TIM5, ENABLE);
 
 
}


Outcomes