Skip to main content
Visitor II
June 11, 2024
Solved

what is the smallest achievable delay in microseconds for a 16-bit and a 32-bit timer?

  • June 11, 2024
  • 3 replies
  • 1175 views

Hi, I want to generate a 1 microsecond (1 µs) timer interrupt on the STM32G0B1RCT6 microcontroller using its internal clock(16MHz). I am currently using a 16-bit timer to achieve a 5 microsecond delay, but I cannot achieve a 1 microsecond delay. My question is: what is the smallest achievable delay in microseconds for a 16-bit and a 32-bit timer?

    This topic has been closed for replies.
    Best answer by Tesla DeLorean

    This was already explained too you. You can't interrupt at this rate, you basically saturate the processors with busy work, and nothing gets done.

    What you can do is have a maximal counter, running as fast as the processor clock, so whatever quantum that factors out at.

    ie TIM->PSC = 0, TIM->ARR=0xFFFF

    For a TIM clock running at 48 MHz, TIM->CNT increments every 20.833 ns

    uint16_t start = TIM1->CNT;

    while((TIM1->CNT - start) < 48); // 1us at 48 MHZ

    3 replies

    Super User
    June 11, 2024

    You've already got a thread on this:

    https://community.st.com/t5/stm32-mcus-boards-and-hardware/how-to-generate-a-1-microsecond-1-%C2%B5s-timer-interrupt-on-the/m-p/684321#M19430

     


    @Berlin-raj123 wrote:

    Hi, I want to generate a 1 microsecond (1 µs) timer interrupt 


    In that thread, several people have already asked you why you feel the need to do that, and have explained that it's a Bad Idea.

    Graduate II
    June 11, 2024

    This was already explained too you. You can't interrupt at this rate, you basically saturate the processors with busy work, and nothing gets done.

    What you can do is have a maximal counter, running as fast as the processor clock, so whatever quantum that factors out at.

    ie TIM->PSC = 0, TIM->ARR=0xFFFF

    For a TIM clock running at 48 MHz, TIM->CNT increments every 20.833 ns

    uint16_t start = TIM1->CNT;

    while((TIM1->CNT - start) < 48); // 1us at 48 MHZ

    Technical Moderator
    June 11, 2024

    Hello @Berlin-raj123 

    Could you please tell why are you duplicating this thread from https://community.st.com/t5/stm32-mcus-boards-and-hardware/how-to-generate-a-1-microsecond-1-%C2%B5s-timer-interrupt-on-the/m-p/684321#M19430 ?

    Are all these answers didn't convince you?

    I agree with @Tesla DeLorean you will saturate the processor at this rate for nothing as you didn't explain the main reason for doing that!

    Otherwise the thread will be closed.