Basic question regarding timers and generating a simple delay
Hi there,
Let say I want to generate a 1 ms delay using a timer. I set my prescaler to have a 1ms granularity
TIMx->PSC = (uint16_t)((SystemCoreClock / 1000U) - 1);Now if I want to generate a 2ms delay I usually do it like this (assuming the UIF flag is already cleared and that the timer is not running).
TIMx->ARR = 2 - 1;
TIMx->CR1 = TIM_CR1_CEN; // Enable the TIM Counter
while((TIMx->SR & TIM_SR_UIF) == 0) ; // Wait for Timer overflowEverything works as it should for any delay except if I want to generate a 1ms delay. Using the same method I have to change the prescaler to something.
My question is : is there a way to generate a 1ms delay with a 1ms prescaler ?