AnsweredAssumed Answered

accurate delay_ms function for the STM32F0 processor

Question asked by pandey.piyush.001 on Sep 28, 2014
Latest reply on Sep 28, 2014 by Clive One
Hi

I was doing a small project using the STM32F0 processor and IAR Embedded Workbench toolset.

There I was trying to customize the example source code available in the IAR examples section.

The path is to that example on my system:

C:\Program Files\IAR Systems\Embedded Workbench 6.5\arm\examples\ST\STM32F05x\STM32F0-DISCOVERY\Project\src\EvalTest

In this source code example there are two functions defined in the main.c file for creating the delay in millisecond.

One is loose type and another one is accurate.

While the working of loose type of the delay is pretty clear but the accurate one is not that mush clear to me.

I mean I am not able to get the idea that how it is going to work instead it must end in an
infinite while loop.

I am pasting the body of that delay routine over here:

void delay_ms(uint32_t n_ms)
{
  // SysTick interrupt each 1000 Hz with HCLK equal to 32MHz
  // - 30 to compensate the overhead of this sub routine
  SysTick_Config(8000*PLL_MUL_X - 30);
  // Enable the SysTick Counter

  TickValue = n_ms;
  while(TickValue == n_ms)
    ;

  // SysTick interrupt each 1000 Hz with HCLK equal to 32MHz
  SysTick_Config(8000*PLL_MUL_X);
  while(TickValue != 0)
    ;

}


Also in my code its not working and get stuck in the first while loop.

So please tell me if I am missing something.

Thanks


Outcomes