Skip to main content
kounst
Associate II
September 28, 2009
Question

Timer 2 CC ISR is triggered twice!?

  • September 28, 2009
  • 5 replies
  • 1068 views
Posted on September 28, 2009 at 19:42

Timer 2 CC ISR is triggered twice!?

    This topic has been closed for replies.

    5 replies

    kounst
    kounstAuthor
    Associate II
    May 17, 2011
    Posted on May 17, 2011 at 13:22

    yes I did.

    The ISR is only called twice after each edge- so I think the problem can't be related to the interrupt flag.

    guyvo67
    Associate III
    May 17, 2011
    Posted on May 17, 2011 at 13:22

    kounst,

    Did you reset you CC flag in the interrupt routine like:

    TIM_ClearITPendingBit(TIM2, TIM_IT_CC2);

    ?

    kounst
    kounstAuthor
    Associate II
    May 17, 2011
    Posted on May 17, 2011 at 13:22

    Hello,

    I'm trying to measure the PWM signal of a rc receiver.

    The falling edge of the signal triggers the tim 2 cc isr.

    My problem is that for some reason the ISR is triggered again only 2usec later. There are no rising nor falling edges for at least 1msec.

    Thanks for any help!

    /*******************************************************************************

    * Function Name : main

    * Description : Main program

    * Input : None

    * Output : None

    * Return : None

    *******************************************************************************/

    int main(void)

    {

    #ifdef DEBUG

    debug();

    #endif

    /* System clocks configuration -----------*/

    RCC_Configuration();

    /* NVIC configuration ---*/

    NVIC_Configuration();

    /* GPIO configuration */

    GPIO_Configuration();

    /* TIM2 Configuration */

    TIM2_Configuration();

    while (1)

    {

    }

    }

    /*******************************************************************************

    * Function Name : GPIO_Configuration

    * Description : Configure the used I/O ports pin

    * Input : None

    * Output : None

    * Return : None

    *******************************************************************************/

    void GPIO_Configuration()

    {

    GPIO_InitTypeDef GPIO_InitStructure;

    /* Configure capture compare input for pwm measurement */

    /* TIM2 channel 2 pin (PA.01) configuration */

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;

    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;

    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

    GPIO_Init(GPIOA, &GPIO_InitStructure);

    /* Toggle Pin */

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;

    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;

    GPIO_Init(GPIOA, &GPIO_InitStructure);

    }

    /*******************************************************************************

    * Function Name : TIM2_Confgureation()

    * Description :

    * Input : None

    * Output : None

    * Return : None

    *******************************************************************************/

    void TIM2_Configuration(void)

    {

    TIM_ICInitTypeDef TIM_ICInitStructure;

    //TIM_ICInitStructure.TIM_ICMode = TIM_ICMode_ICAP;

    TIM_ICInitStructure.TIM_Channel = TIM_Channel_2;

    TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Falling;

    TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;

    TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;

    TIM_ICInitStructure.TIM_ICFilter = 0x0;

    TIM_ICInit(TIM2, &TIM_ICInitStructure);

    TIM_SelectInputTrigger(TIM2, TIM_TS_TI2FP2);

    TIM_InternalClockConfig(TIM2);

    TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;

    TIM_TimeBaseStructure.TIM_Period = 0xFFFF;

    TIM_TimeBaseStructure.TIM_Prescaler = 72;

    TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;

    TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;

    TIM_TimeBaseInit(TIM2, & TIM_TimeBaseStructure);

    /* TIM enable counter */

    TIM_Cmd(TIM2, ENABLE);

    /* Enable the CC2 Interrupt Request */

    TIM_ITConfig(TIM2, TIM_IT_CC2, ENABLE);

    }

    /*******************************************************************************

    * Function Name : RCC_Configuration

    * Description : Configures the different system clocks.

    * Input : None

    * Output : None

    * Return : None

    *******************************************************************************/

    void RCC_Configuration(void)

    {

    /* RCC system reset(for debug purpose) */

    RCC_DeInit();

    /* Enable HSE */

    RCC_HSEConfig(RCC_HSE_ON);

    /* Wait till HSE is ready */

    HSEStartUpStatus = RCC_WaitForHSEStartUp();

    if(HSEStartUpStatus == SUCCESS)

    {

    /* Enable Prefetch Buffer */

    FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);

    /* Flash 2 wait state */

    FLASH_SetLatency(FLASH_Latency_2);

    /* HCLK = SYSCLK */

    RCC_HCLKConfig(RCC_SYSCLK_Div1);

    /* PCLK2 = HCLK */

    RCC_PCLK2Config(RCC_HCLK_Div1);

    /* PCLK1 = HCLK/2 */

    RCC_PCLK1Config(RCC_HCLK_Div2);

    /* PLLCLK = 8MHz * 9 = 72 MHz */

    RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);

    /* Enable PLL */

    RCC_PLLCmd(ENABLE);

    /* Wait till PLL is ready */

    while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)

    {

    }

    /* Select PLL as system clock source */

    RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);

    /* Wait till PLL is used as system clock source */

    while(RCC_GetSYSCLKSource() != 0x08)

    {

    }

    }

    /* Enable peripheral clocks ----------------*/

    /* GPIOB Periph clock enable */

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);

    /* TIM2 clock enable */

    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);

    }

    /*******************************************************************************

    * Function Name : NVIC_Configuration

    * Description : Configures Vector Table base location.

    * Input : None

    * Output : None

    * Return : None

    *******************************************************************************/

    void NVIC_Configuration(void)

    {

    NVIC_InitTypeDef NVIC_InitStructure;

    #ifdef VECT_TAB_RAM

    /* Set the Vector Table base location at 0x20000000 */

    NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);

    #else /* VECT_TAB_FLASH */

    /* Set the Vector Table base location at 0x08000000 */

    NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);

    #endif

    /* Enable the TIM2 global Interrupt */

    NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQChannel;

    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;

    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;

    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

    NVIC_Init(&NVIC_InitStructure);

    }

    [ This message was edited by: kounst on 01-09-2009 21:19 ]

    kounst
    kounstAuthor
    Associate II
    May 17, 2011
    Posted on May 17, 2011 at 13:22

    Hi,

    yes I solved it!

    I figured out that if I turn off my laptop everything works fine.

    So I added a Schmitt Trigger. Problem solved!

    Regards,

    smithdexter
    Associate
    May 17, 2011
    Posted on May 17, 2011 at 13:22

    Kounst,

    Did you find a reason for this as I am seeing this now?