This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

debugging timer interrupt delay in KEIL

Hello MrChips I have written the following code for microsecond delay ,i just use delay(1000) to have 1milisecond delay.
I cant see the dinammic of the the delay.
my APB1 clock is 21Mhz ,ARR=21 makes the counter to overflow every 1MHz and call the TIM4_IRQHandler function which will increase myticks by 1.
but how in parralel the delay function will check if myticks<us, as i see it ,we will be stuck on the delay "while"
how in paralel the TIM4_IRQHandler will run timer overflow?
Can i see it in KEIL debugging? because debugging is not time based,its sequential.
Thanks.

 void delay(int us)

    {

        TIM4->CR1|=TIM_CR1_CEN;

        myticks=0;

        while(myticks<us);

        TIM4->CR1&=~TIM_CR1_CEN;

          

    }

void TIM4_IRQHandler(void)

{

    myticks++;

  TIM4->SR&=~TIM_SR_UIF;

}   

  

int main(void)

{

    RCC->APB1ENR|=RCC_APB1ENR_TIM4EN;

    TIM4->PSC=0;

    TIM4->ARR=21;

    TIM4->CR1|=TIM_CR1_URS;

    TIM4->DIER|=TIM_DIER_UIE;

    TIM4->EGR=TIM_EGR_UG;

    NVIC_EnableIRQ(TIM4_IRQn);