cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to vary timer overflow time

ANNU CHERIAN
Associate II
Posted on February 15, 2018 at 10:59

We are using stm32f051r4t6 IC for a new project  and IDE used is Keil V5 . We are using Timer_3 running at 8MHz internal clock to generate a timer delay but , by varying PSC and ARR registers we always obtain nearly 4us .  How could we vary the timer overflow time . Any help would be greatly appreciated .

void Timer3_Init()

{

    RCC->APB1ENR |= RCC_APB1ENR_TIM3EN;                                                                                                        

    TIM3->ARR = 0xFFFF;                                                                            

    TIM3->PSC = 0x0000;                                                                   

    TIM3->EGR |= TIM_EGR_UG;

    TIM3->CR1 |= TIM_CR1_ARPE  | TIM_CR1_CEN;   

    

   TIM3->DIER |= TIM_DIER_UIE; 

    NVIC_EnableIRQ(TIM3_IRQn); 

}

void TIM3_IRQHandler(void)

{

    if((TIM3->SR & TIM_SR_UIF))

    {

        TIM3->SR &=~ TIM_SR_UIF;

        TIM3->EGR |= TIM_EGR_UG;

      

        // toggle gpio pin

    }

}

#stm32f0-timer #stm32f0 #stm32f0-counter
1 REPLY 1
Posted on February 15, 2018 at 13:07

Remove this line from the IRQHandler:

TIM3->EGR |= TIM_EGR_UG;

This line means 'simulate update', i.e. it fires the interrupt immediately again.

JW