Skip to main content
leventeyigel52
Associate III
May 27, 2013
Question

Delay Function Without SysTick_Handler Interrupt

  • May 27, 2013
  • 6 replies
  • 1370 views
Posted on May 27, 2013 at 15:58

Hello ,

I want to try use a function that is without  SysTick_Handler Interrupt :

I wrote this function  :

void DelayUs(int us)

{

unsigned int cnt;

while(us-- >0)

{

   cnt = SysTick_GetCounter(); // get systick counter, ticking each 500nS

   while( (SysTick_GetCounter()-cnt) < 2); // repeat till 2 ticks

}

}

but cnt value is zero , i can't see any value from SysTick_GetCounter() ;

How can i solve this problem ?

Does anyone have any advice  ?

    This topic has been closed for replies.

    6 replies

    emalund
    Associate III
    May 27, 2013
    Posted on May 27, 2013 at 16:41

    show how you initialize the systick

    zzdz2
    Associate
    May 27, 2013
    Posted on May 27, 2013 at 17:04

    I use this:

    #define TICKSGN ((SysTick_VAL_CURRENT_Msk+1)>>1)
    #define WAITMAX (SysTick_VAL_CURRENT_Msk >> 1)
    static inline void waittick(uint32_t step)
    {
    static uint32_t tick0;
    if (!step)
    {
    tick0 = SysTick->VAL;
    return;
    }
    tick0 -= step;
    while ((tick0 - SysTick->VAL) & TICKSGN)
    {
    __NOP();
    __NOP();
    }
    }
    static inline void sleep(uint32_t delay)
    {
    waittick(0);
    delay++;
    while (delay > WAITMAX)
    {
    waittick(WAITMAX);
    delay -= WAITMAX;
    }
    waittick(delay);
    }

    leventeyigel52
    Associate III
    May 27, 2013
    Posted on May 27, 2013 at 17:04

    SysTick_Config(SystemFrequency / 1000);

    I only use this initializition function.

    zzdz2
    Associate
    May 27, 2013
    Posted on May 27, 2013 at 17:26

    Try my code above and initialize SysTick like this:

    SysTick->LOAD = 0xffffff;
    SysTick->CTRL = SysTick_CTRL_ENABLE_Msk;

    Edit: Thismay be better:

    SysTick->LOAD = SysTick_VAL_CURRENT_Msk;
    SysTick->CTRL = SysTick_CTRL_ENABLE_Msk;

    leventeyigel52
    Associate III
    May 28, 2013
    Posted on May 28, 2013 at 11:01

    SysTick_VAL_CURRENT_Msk;
    SysTick_CTRL_ENABLE_Msk;

    I couldn't find these variables on my project. which library does include these variables?
    zzdz2
    Associate
    May 28, 2013
    Posted on May 28, 2013 at 13:47

    It's defined in core_cm3.h