Systick Timer
Systick Timer
1
2
3
SYSTEM TIMER (SysTick)
❑ 24-bit down counter
❑ Timer consists of three registers
▪ SysTick Control and Status Register (STCTRL)
▪ SysTick Reload Value Register (STRELOAD)
▪ SysTick Current Value (STCURRENT)
❑ When enabled, the timer counts down from the reload
value to zero on each clock cycle
❑ Reloads to a value in STRELOAD register on the next clock
edge when counter reaches zero
❑ COUNT status bit is 1, when the counter reaches zero
❑ Runs on either the system clock or the precision internal
oscillator (PIOSC) divided by 4
9
SysTick Initialization
❑ Define the addresses of the registers
10
SysTick Initialization
❑ Disable the counter by clearing ENABLE bit of STCTRL
▪ Clear enable bit to 0 to disable counter
▪ NVIC_ST_CTRL_R = 0x00000000
0 – Disable Counter
11
SysTick Initialization
❑ Program the value in the STRELOAD register
▪ Counter starts down counting from this value
▪ Maximum value is 0x00FF.FFFF
▪ NVIC_ST_RELOAD_R = 0x00FFFFFF ( Down count from the maximum
value)
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
12
SysTick Initialization
❑ Clear the STCURRENT register by writing to it with any
value
▪ Write any value to clear the counter
▪ Loads with STRELOAD register value, when counter reaches zero
▪ NVIC_ST_CURRENT_R = 0x00000000
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
13
SysTick Initialization
❑ Configure the STCTRL register for the required operation
▪ Set ENABLE bit to 1 to enable the counter
▪ Set CLK_SRC to 1 to select System clock
▪ Set INTEN to generate interrupt when counter reaches zero
▪ NVIC_ST_CTRL_R = 0x00000005
1 – System Clock
0 – Interrupt generation is disabled 1 – Enable counter14
System Timer
Example
15
Example Program to use Systick Timer
16
Step 1: Define the Addresses of registers to be used
17
Step 2: Initialize SysTick Timer
18
Step 3: Create Delay
19
Step 4: Larger delay
20
Step 5: Usage
21