AnsweredAssumed Answered

TIMERS used as DELAY Function For Beginners on STM32F3

Question asked by Niks on Dec 19, 2013
Latest reply on Dec 20, 2013 by Niks
Function works for TIM6 basic timer used as delay on STM32F303 , with suitable modifications can work on any STM8,32 variants


void TIMER_DELAY(uint16_t value)
{
     RCC->APB1ENR |= RCC_APB1Periph;//value is 0x10
        TIM6->ARR = value;       // delay in ms
     TIM6->PSC = 36000-1;  // APB1 = 36Mhz so eqn :  CLK_CNT = (36000000)/36000,i.e. CLK_CNT = 1Khz
     TIM6->CR1 = 0x01;         // ENaBle TIMER 
     while(!((TIM6->SR & 0x01) == 0x01));  // Check for Update Event
     TIM6->CR1 &= ~(0x01);                      // Disable timer
     TIM6->SR &= ~(0x01);                        // Reset the update event
}



For eg. TIMER_DELAY(100) would provide me 100ms delay.

Outcomes