cancel
Showing results for 
Search instead for 
Did you mean: 

TIM2_IRQHandler never executes??!!

srinath3142
Associate
Posted on November 13, 2011 at 12:40

Hello everyone,

I have tried to use GPIO PortB, Pin 10 (which i believe can use AF TIM2_Channel 3) to capture PWM signals on my stm32f2.  I am using the standard peripheral lib. 

I am having issues with the TIM2_IRQHandler never being called/executed.  Below is the code fragment to setup the GPIO, NVIC and TIM for PWMIN  - 

     GPIO_InitTypeDef GPIO_InitStructure;

     NVIC_InitTypeDef NVIC_InitStructure;

     TIM_ICInitTypeDef  TIM_ICInitStructure;

     RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE); 

     RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);

     GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_10;

     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; // Unclear on this setting

     GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

     GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;

     GPIO_Init(GPIOB, &GPIO_InitStructure);

     GPIO_PinAFConfig(GPIOB, GPIO_PinSource10  , GPIO_AF_TIM2);

     NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;

     NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;

     NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;

     NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

     NVIC_Init(&NVIC_InitStructure);

     TIM_ICInitStructure.TIM_Channel = TIM_Channel_3;

     TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;

     TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;

     TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;

     TIM_ICInitStructure.TIM_ICFilter = 0x0;  

     TIM_PWMIConfig(TIM2, &TIM_ICInitStructure);

    

     TIM_SelectInputTrigger(TIM2, TIM_TS_TI2FP2);  

     /* Select the slave Mode: Reset Mode */

     TIM_SelectSlaveMode(TIM2, TIM_SlaveMode_Reset);

     TIM_SelectMasterSlaveMode(TIM2,TIM_MasterSlaveMode_Enable);

     /* TIM enable counter */

     TIM_Cmd(TIM2, ENABLE);

     /* Enable the CC2 Interrupt Request */

     TIM_ITConfig(TIM2, TIM_IT_CC2, ENABLE); 

The IRQ Handler is as below (note num_vists is a global variable and it never seems to increase ) - 

void TIM2_IRQHandler(void) {

 

  TIM_ClearFlag(PPM_TIM,TIM_FLAG_CC1);

  TIM_ClearFlag(PPM_TIM,TIM_FLAG_CC2);

  TIM_ClearFlag(PPM_TIM,TIM_FLAG_CC3);

  TIM_ClearFlag(PPM_TIM,TIM_FLAG_CC4);

  TIM_ClearITPendingBit(PPM_TIM, TIM_IT_CC2);

  TIM_ClearITPendingBit(PPM_TIM, TIM_IT_CC1);

  num_vists++;

}

Can anyone help me figure out what I have done wrong (i.e. why is the IRQ handler never visited).

Regards,

Srinath

#stm32f2-pwm-input-capture
2 REPLIES 2
Posted on November 13, 2011 at 13:08

     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; // Unclear on this setting

 

Slew-rate control for pin. ie Drive Strength or SPEED. Not of consequence for an input.

     TIM_ICInitStructure.TIM_Channel = TIM_Channel_3;

 

 

     TIM_SelectInputTrigger(TIM2, TIM_TS_TI2FP2);  

 

 

     /* Enable the CC2 Interrupt Request */

 

     TIM_ITConfig(TIM2, TIM_IT_CC2, ENABLE); 

 

 

What CHANNEL are you using/configuring?

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
csdominik
Associate III
Posted on November 14, 2011 at 01:44

1st change this:

TIM_ICInitStructure.TIM_Channel = TIM_Channel_3;

to:

TIM_ICInitStructure.TIM_Channel = TIM_Channel_2; // because channel 1 and 2 is used to detect a pwm input

 

Try if it works, if not, try to change :

     TIM_SelectInputTrigger(TIM2, TIM_TS_TI1FP1);

      TIM_SelectSlaveMode(TIM2, TIM_SlaveMode_Reset);

      TIM_SelectMasterSlaveMode(TIM2, TIM_MasterSlaveMode_Enable);

          

      TIM_Cmd(TIM2, ENABLE);

      TIM_ITConfig(TIM2, TIM_IT_CC1, ENABLE);