Skip to main content
sam239955
Associate III
November 22, 2011
Question

Delay function in ms how?

  • November 22, 2011
  • 2 replies
  • 1210 views
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
    This topic has been closed for replies.

    2 replies

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

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

     

     

    Erik

    Tesla DeLorean
    Guru
    November 22, 2011
    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 VenmoUp vote any posts that you find helpful, it shows what's working..