cancel
Showing results for
Did you mean:

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

Associate II

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?

1 ACCEPTED SOLUTION

Accepted Solutions
Guru

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

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
3 REPLIES 3
Evangelist III

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.

Guru

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

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
ST Employee

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.