cancel
Showing results for 
Search instead for 
Did you mean: 

Delay in microseconds for stm32l0 cortex m0+

umesh_patil
Associate II

I Wanted to generate the microsecond delay function, I have tried below functions but these are not working, It will be good if someone knows the delay function.

static inline void delay_us( uint32_t micros)

{

   micros *= (SystemCoreClock / 1000000) / 5;

while (micros);

}

********************

void delay_us( uint32_t us)

{

volatile uint32_t counter = 7*us;

    while(counter--)

}

************************

void delay_us( uint32_t value)

{

SysTick->VAL = 8 * value;

       uint32_t temp = SysTick->VAL;

       while(temp) { temp = SysTick->VAL; }

}

5 REPLIES 5

Some of the above look broken.

Why can't you use the count value of a free running TIM, at 1 MHz , or faster?

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

Thank u very much.

can i generate it upto below 1 us ?

If you clock at CPU speed and account for entry/exit costs, you can achieve sub-microsecond timing.

Interrupt servicing will obviously distort that depending where you use the delay function.​

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

Thank u..I will try it

can you share code snippet please?

I am trying but it is not working properly?