Skip to main content
salvatore
Associate II
Nov 15, 2011 1:39 PM UTC
Question

Systick doesn't fires up as expected

Posted on November 15, 2011 at 14:39

I programmed the systick timer in order to get 1ms delay but I seem to get a 10us delay instead.

From the reference manual RM0008

''The SysTick calibration value is set to 9000, which gives a reference time base of 1 ms with the SysTick clock set to 9 MHz (max HCLK/8).''

I configured the system clock at 72Mhz and the AHB prescaler at 1. The clock source of the systick is also set to 1, thus clock core. Although I don't understand what it means by ''external reference clock''. I loaded up 9000 into the systick reload value.

I wrote this simple routine to get a delay

static uint32_t gCounter = 0;

void sys_tick_timer()

{

  if (gCounter)

    gCounter--;

}

static void delayms(uint32_t millisecond)

{

  gCounter = millisecond;

  while (gCounter > 0);

}

but the interrupt seems to be fired much faster then 1ms. I have to load 100*1000 value

to get a delay of about 1 second.

Any suggestions would be appreciated.

S.
    This topic has been closed for replies.

    4 replies

    amin23
    Visitor II
    Nov 15, 2011 3:33 PM UTC
    Posted on November 15, 2011 at 16:33

    There is an example under STM32F10x standard peripheral library: the systick programmed in order to get 1ms delay:

    http://www.st.com/internet/mcu/product/221026.jsp

    Tesla DeLorean
    Guru
    Nov 15, 2011 9:46 PM UTC
    Posted on November 15, 2011 at 22:46

    Well SysTick certainly should work, without seeing exactly how you're setting it, and building the project, I can't see an obvious reason why it would be so fast.

    One thing you definitely want to do is have the counter stored in a volatile, not a static, otherwise the delay loop might compile into something unusable.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    salvatore
    salvatoreAuthor
    Associate II
    Nov 16, 2011 10:18 AM UTC
    Posted on November 16, 2011 at 11:18

    I totally missed the volatile keyword there. Thanks for pointing it out.

    The systick is simply enabled by placing 9000 into the reload register value (that's also what is into the calibration register) and enabling the timer by writing 3 to the control status register, as follow

    *gkSysTickReloadValue = (*gkSysTickCalibrationValue & 0x00FFFFFF); 

    *gkSysTickControlStatus |= 0x03;

    The clock of the system is at 72mhz and the AHB prescaler is at 1. Clock should then divided by 8. I checked and the values are correctly written.
    salvatore
    salvatoreAuthor
    Associate II
    Nov 16, 2011 8:48 PM UTC
    Posted on November 16, 2011 at 21:48

    The reload counter was incorrectly set.

    Those were uint8_t* pointers and I forgot to cast them.

    Thanks for the help.