cancel
Showing results for 
Search instead for 
Did you mean: 

Setting sysyTick Timer to 1ms

santosh
Associate II
Posted on June 04, 2014 at 14:22

Hi All,

May I know how to set Systick Timer to set for 1ms. The code in which I noticed was  like this

if (SysTick_Config(SystemCoreClock / 1000))

  { 

    /* Capture error */ 

    while (1);

  }

Is it set to 1ms. If so how is that calculated and what is the value to set SysTick for 1s. Thanks 
2 REPLIES 2
chen
Associate II
Posted on June 04, 2014 at 15:32

Hi

''May I know how to set Systick Timer to set for 1ms.''

''SysTick_Config(SystemCoreClock / 1000)''

SystemCoreClock is a constant (or vairable) defined somewhere, it is usually defined in a file related to he processor type/family eg system_stm32f4xxx.c

It defines the clock rate the processor is running at.

The 'sysTick' is just a timer peripheral, provided by ARM.

The timer counts to the number you set and then triggers the SysTick interrupt when it reachs the trigger number and then the count resets.

That is what SysTick_Config() does - sets the count trigger number.

''SystemCoreClock / 1000''

Since, the sysTick timer is being clocked at the same rate as the processor,

setting the sysTick trigger number to CPU freq/1000 will cause it

to triger 1000 times a second - ie 1ms.

''how is that calculated and what is the value to set SysTick for 1s.''

It may be as simple as

''SysTick_Config( SystemCoreClock )''

BUT

1) check what value SystemCoreClock  is

2) check that the register size (number of bits) is large enough for the value of SystemCoreClock

(If it is not - you will have to investigate using a pre-scaler)

Posted on June 04, 2014 at 16:02

The ''/ 1000'' is determining the tick for 1/1000th of a second, a millisecond

The SysTick counter is only 24-bit, so you won't be able to do 1 second when clocking at over 16 MHz

Having a 1ms ticker is quite useful, you can also count the number of times being called, and every 1000 call  Task1Hz()

Most OS implementations provide a 1 KHz value of time
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..