2011-11-22 5:14 AM
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 alex2011-11-22 6:09 AM
The answer is right there tick Systicks (happens every 10 ms)
Erik
2011-11-22 8:15 AM
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.We’re moving the ST Community to a new platform to give you a better and more reliable community experience.