cancel
Showing results for 
Search instead for 
Did you mean: 

Input Capture issue

eduardo2
Associate II
Posted on August 28, 2014 at 01:04

Hi:

I am using the STM3221G-EVAL board and TIM example from STM32F2xx_StdPeriph_Lib. I modified the original example so I can use PG15 input.

There is a pushbutton connected to PG15 on the eval board.

When I press the pushbutton nothing happens. The system never goes through TIM1_CC_IRQHandler. what would be the problem?

Thanks.

int main(void)

{

  /*!< At this stage the microcontroller clock setting is already configured, 

       this is done through SystemInit() function which is called from startup

       file (startup_stm32f2xx.s) before to branch to application main.

       To reconfigure the default setting of SystemInit() function, refer to

       system_stm32f2xx.c file

     */     

       

  /* TIM1 Configuration */

  GPIO_InitTypeDef GPIO_InitStructure;

  NVIC_InitTypeDef NVIC_InitStructure;

  TIM_ICInitTypeDef  TIM_ICInitStructure;

  

  /* TIM1 clock enable */

  RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);

  /* GPIOG clock enable */

  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOG, ENABLE);

  

  /* TIM1 channel 2 pin (PG.15) configuration */

  GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_15;

  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_NOPULL;

  GPIO_Init(GPIOG, &GPIO_InitStructure);

  /* Connect TIM pins to AF1 */

  GPIO_PinAFConfig(GPIOG, GPIO_PinSource15, GPIO_AF_TIM1);

  

  /* Enable the TIM1 global Interrupt */

  NVIC_InitStructure.NVIC_IRQChannel = TIM1_CC_IRQn;

  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;

  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;

  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

  NVIC_Init(&NVIC_InitStructure);

  /* TIM1 configuration: Input Capture mode ---------------------

     The external signal is connected to TIM1 CH2 pin (PG.15)  

     The Rising edge is used as active edge,

     The TIM1 CCR2 is used to compute the frequency value 

  ------------------------------------------------------------ */

  TIM_ICInitStructure.TIM_Channel = TIM_Channel_2;

  TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;

  TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;

  TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV8;

  TIM_ICInitStructure.TIM_ICFilter = 0x0;

  TIM_ICInit(TIM1, &TIM_ICInitStructure);

  

  /* TIM enable counter */

  TIM_Cmd(TIM1, ENABLE);

  /* Enable the CC2 Interrupt Request */

  TIM_ITConfig(TIM1, TIM_IT_CC2, ENABLE);

  while (1);

}

void TIM1_CC_IRQHandler(void)

  if(TIM_GetITStatus(TIM1, TIM_IT_CC2) == SET) 

  {

    /* Clear TIM1 Capture compare interrupt pending bit */

    TIM_ClearITPendingBit(TIM1, TIM_IT_CC2);

    if(CaptureNumber == 0)

    {

      /* Get the Input Capture value */

      IC3ReadValue1 = TIM_GetCapture2(TIM1);

      CaptureNumber = 1;

    }

    else if(CaptureNumber == 1)

    {

      /* Get the Input Capture value */

      IC3ReadValue2 = TIM_GetCapture2(TIM1); 

      

      /* Capture computation */

      if (IC3ReadValue2 > IC3ReadValue1)

      {

        Capture = (IC3ReadValue2 - IC3ReadValue1); 

      }

      else if (IC3ReadValue2 < IC3ReadValue1)

      {

        Capture = ((0xFFFF - IC3ReadValue1) + IC3ReadValue2); 

      }

      else

      {

        Capture = 0;

      }

      /* Frequency computation */ 

      TIM1Freq = (uint32_t) SystemCoreClock / Capture;

      CaptureNumber = 0;

    }

  }

}

#input-capture #stm3221-eval
2 REPLIES 2
Posted on August 28, 2014 at 04:24

I am using the STM3221G-EVAL board and TIM example from STM32F2xx_StdPeriph_Lib. I modified the original example so I can use PG15 input.There is a pushbutton connected to PG15 on the eval board. When I press the pushbutton nothing happens. The system never goes through TIM1_CC_IRQHandler. what would be the problem?

Problem is that PG15 has no association with TIM1, you might want to review the part's Data Sheet.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
eduardo2
Associate II
Posted on August 28, 2014 at 14:29

ok, thanks clive1.