Objective

In this tutorial we will discuss how to configure lpc1768 systick timer for 1ms tick.
At the end of the tutorial we will see how to use the ExploreEmbedded sysTick libraries.



Systick Module

The System Tick Timer is an integral part of the Cortex-M3. The System Tick Timer is intended to generate a fixed 10 millisecond(user configurable) interrupt for use by an operating system or other system management software.

The System Tick Timer is a 24-bit timer that counts down to zero and generates an interrupt. The intent is to provide a fixed time interval between interrupts.

In order to generate recurring interrupts at a specific interval, the STRELOAD register must be initialized with the correct value for the desired interval.



Registers

Register Address Description
STCTRL 0xE000 E010 System Timer Control and status register
STRELOAD 0xE000 E014 System Timer Reload value register
STCURR 0xE000 E018 System Timer Current value register
STCALIB 0xE000 E01C System Timer Calibration value register





STCTRL
31-17 16 15-3 2 1 0
RESERVED COUNTFLAG RESERVED CLKSOURCE TICKINT ENABLE

Bit 0 - ENABLE
This bit is used to enable/disable the systick counter.
0-Disable the systick timer. 1-Enables the systick timer.


Bit 1 - TICKINT
This bit is used to enable/disable the systick timer interrupt. When enabled the SysTick_Handler ISR will be called.
0-Disable the systick timer Interrupt. 1-Enables the systick timer Interrupt.


Bit 2 - CLKSOURCE
This bit is used to select clock source for System Tick timer.
0-The external clock pin (STCLK) is selected. 1-CPU clock is selected.


Bit 16- COUNTFLAG
System Tick counter flag. This flag is set when the System Tick counter counts down to 0, and is cleared by reading this register.



STRELOAD
31-24 23 - 0
RESERVED RELOAD

Bit 23:0 - RELOAD
This is the 24-bit timer value that is loaded into the System Tick counter when it counts down to 0.


STCURR
31-24 23 - 0
RESERVED CURRENT

Bit 23:0 - CURRENT
Reading this register returns the current value of the System Tick counter. Writing any value clears the System Tick counter and the COUNTFLAG bit in STCTRL.

Timer Calculation

SysTick timer calculatoion for 1ms with 100 Mhz CPU clock (cclk).
cclk = 100 Mhz
Ticks = 1000/sec

RELOAD = (cclk / Ticks) - 1 = (100 Mhz / 1000) - 1 = 100,000 - 1 = 99,999 = 0x1869F


Code

Using ExploreEmbedded Libraries

00 Lpc1768 Timer.jpg