Skip to main content
Vishay Patel
Associate II
February 19, 2018
Solved

STM32F072B-Discovery TIM3 input capture interrupt not working

  • February 19, 2018
  • 2 replies
  • 940 views
Posted on February 19, 2018 at 02:05

As the title says, I am using an STM32F072BDISCOVERY board and I am trying to implement input capture using timer 3. My input is a PWM signal with a 10% duty cycle, frequency = ~50Hz on port A pin 6. I am trying to generate an interrupt on both rising and falling edges, as well as an interrupt on counter reset (upcounting), I am clocking the counter with a period of 1us. I am only using CMSIS register definitions, no other HALs.

I configure clocks as follows:

RCC->APB1ENR |= RCC_APB1ENR_TIM3EN;

RCC->AHBENR |= RCC_AHBENR_GPIOAEN;

I configure GPIO as follows:

GPIOA->MODER = (GPIOA->MODER & (~(GPIO_MODER_MODER6))) | GPIO_MODER_MODER6_1;

GPIOA->AFR[0] |= 0x1000000;

I configure TIM3 as follows:

    TIM3->CCMR1 |= TIM_CCMR1_CC1S_0;

    TIM3->CCER |= TIM_CCER_CC1E | TIM_CCER_CC1P | TIM_CCER_CC1NP;

    TIM3->DIER |= TIM_DIER_CC1IE | TIM_DIER_UIE;

    TIM3->PSC = 0x7;

    TIM3->ARR = 0x61A7;

    TIM3->CR1 |= TIM_CR1_CEN;

Using the Peripherals System Viewer of Keil UV5 in debug mode, I can tell that all of the configuration bits are correctly set.

In my ISR I check the TIM->3 SR register for the UIF and CC1F flags, and toggle a different LED depending on what flag is set, then clear the flag. The UIF flag LED is the only LED that is toggled. Can anyone see why I am not getting an interrupt on the input capture channel?

    This topic has been closed for replies.
    Best answer by Vishay Patel
    Posted on March 12, 2018 at 18:53

    My problem ended up being a bad pin on the part, I switched to a new STM32F0 part and the issue went away.

    2 replies

    Vishay Patel
    Associate II
    February 19, 2018
    Posted on February 19, 2018 at 18:59

    I forget to mention, I also initialize the NVIC as follows:

    NVIC_EnableIRQ(TIM3_IRQn);

    NVIC_SetPriority(TIM3_IRQn,1);

    Vishay Patel
    Vishay PatelAuthorBest answer
    Associate II
    March 12, 2018
    Posted on March 12, 2018 at 18:53

    My problem ended up being a bad pin on the part, I switched to a new STM32F0 part and the issue went away.