0% found this document useful (0 votes)
10 views

Systick Timer

Uploaded by

3ddevindu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Systick Timer

Uploaded by

3ddevindu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

System 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

*More features at page no 123 4


SysTick Timer Register Map
❑ Base address of the core peripherals: 0xE000.E000
❑ Offset address of the registers is given in table 3.8

❑ Address of the STCTRL register: 0xE000.E010


❑ Address of the STRELOAD register: 0xE000.E014
❑ Address of the STCURRENT register: 0xE000.E018
*More at page no 134 5
SysTick Timer Register Descriptions
❑ SysTick Control and Status Register (STCTRL)

1 – Counter reaches zero


0 – Otherwise

0 – Precision Internal Osc. divided by 4


1 – System Clock

0 – Interrupt generation is disabled


1 – Interrupt is generated 0 – Disable Counter
1 – Enable counter
*More at page no 138 6
SysTick Timer Register Descriptions
❑ SysTick Reload Value Register (STRELOAD)
▪ Only 24 bits are allowed
▪ Maximum value is 0x00FF.FFFF
▪ STCURRENT registers loads to the content of STRELOAD when
COUNT bit is 1

*More at page no 140 7


SysTick Timer Register Descriptions
❑ SysTick Current Value Register (STCURRENT)
▪ Contains the current value of the SysTick counter
▪ Loads with value of STRELOAD when counter reaches zero (wrap- on-
zero)
▪ Any write to this register clears the counter (clear on write)

*More at page no 140 8


SYSTEM TIMER INITIALIZATION

1. Define the addresses of the registers


2. Disable the counter by clearing ENABLE bit of STCTRL
3. Program the value in the STRELOAD register
4. Clear the STCURRENT register by writing to it with any
value
5. Configure the STCTRL register for the required operation

9
SysTick Initialization
❑ Define the addresses of the registers

#define NVIC_ST_CTRL_R (*((volatile unsigned long *)0xE000E010))


#define NVIC_ST_RELOAD_R (*((volatile unsigned long *)0xE000E014))
#define NVIC_ST_CURRENT_R (*((volatile unsigned long *)0xE000E018))

▪ Address of the register = Base address of core peripherals + offset of


the register
▪ Address of CTRL Register = 0xE000E000 + 0x010 = 0xE000E010
▪ Address of RELOAD Register = 0xE000E000 + 0x014 = 0xE000E014
▪ Address of CURRENT Register = 0xE000E000 + 0x018 = 0xE000E018

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

❑ Write a Program to create a delay using system tick 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

You might also like