2024-06-11 6:52 AM
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?
Solved! Go to Solution.
2024-06-11 7:42 AM - edited 2024-06-11 12:17 PM
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
2024-06-11 7:30 AM - edited 2024-06-11 7:56 AM
You've already got a thread on this:
@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.
2024-06-11 7:42 AM - edited 2024-06-11 12:17 PM
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
2024-06-11 7:49 AM - edited 2024-06-11 7:54 AM
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.
We’re moving the ST Community to a new platform to give you a better and more reliable community experience.