cancel
Showing results for 
Search instead for 
Did you mean: 

Delay function in ms how?

sam239955
Associate II
Posted on November 22, 2011 at 14:14

Hi,

I need a delay(uint) function for my stm32f103ze project.

My IDE is KEIL with STM32 Std.Periph. v3.5.0

I found a snipped in a KEIL example but I don't understand it and I dont know if its correct.

volatile unsigned long TimeTick;

/*------------------------------------------------------------------------------

  Delay function

  delays number of tick Systicks (happens every 10 ms)

*------------------------------------------------------------------------------*/

void Delay (unsigned long tick)

{

    unsigned long timetick;

    timetick = TimeTick;

    while ((TimeTick - timetick) < tick);

}

Do you guys would help me please to find a solution?

with regards

alex
2 REPLIES 2
emalund
Associate III
Posted on November 22, 2011 at 15:09

The answer is right there tick Systicks (happens every 10 ms)

 

 

Erik

Posted on November 22, 2011 at 17:15

You would set up a SysTick interrupt with a period that is suitable for your timing requirements. If it was ticking at 1ms, you end up with about +/-1ms of slop depending on when you enter your delay routine.

The library examples should contain a complete SysTick example, and the interrupt code is in a separate file within the project.

Another approach, which doesn't require interrupts, would be to use the Core's cycle counter, which at 72 MHz would give you about 14 nanosecond granularity.

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