System Timer (SysTick)
System Timer (SysTick) Registers
It consist of the following three registers: SysTick Control and Status (SysTick_CTRL), SysTick Reload Value (SysTick_LOAD), & SysTick Current Value (SysTick_VAL):SysTick Control and Status Register (SysTick_CTRL), offset 0x010:
SysTick Reload Value Register (SysTick_LOAD), offset 0x014:
SysTick Current Value Register (SysTick_VAL), offset 0x018:
As a summary:
SysTick_CTRL register:
Bit 0: use to enable the counter with a clock signal.
Value 1 -> Enable
Value 0 -> Disable
Bit 1: use to enable the interrupt if needed.
Value 1 -> Enable
Value 0 -> Disable
Bit 2: allows you to select between two clock sources:
Value 1 -> System Clock (16 MHz)
Value 0 -> PIOSC (divided by 4)
Bit 16: use to read only (RO) the status of the counter. If:
Value 1 -> SysTick has reached zero. The COUNT flag is high.
Value 0 -> SysTick hasn’t reached zero. The COUNT flag is low.
SysTick_LOAD register:
Bit 23:0 - for you to set up the initial value that will eventually be stored in the SysTick_VAL register.
Value Range: 0x0 -> 0x00FF.FFFF (16,777,215)
Note: Because the SysTick_LOAD register is a 24-bit register you should be careful when assigning a value to this register. Remember, 0x00FF.FFFF (16,777,215) is the maximum value.
SysTick_VAL register:
Bit 23:0 - allow you to read the current value of the counter at the moment that it was accessed. Value Range: 0x0 -> 0x00FF.FFFF (16,777,215)
Correct Initialization Sequence
Example
Delay Time Calculation
Note: SysTick_LOAD register is a 24-bit register allowing a maximum value of 0x00FF.FFFF (16,777,215). 0x00F423FF (15,999,999) is less than 0x00FF.FFFF (16,777,215), so you are ok. But remember to always take this into consideration.
CODE
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
The following program show how to set up the Sistem Timer Tick (SysTick)
to blink the red LED with a delay time of 1 second using the
Tiva C Series TM4C123G LaunchPad.
All LEDs are high active (a "1" turns ON the LED).
PF1 - red LED 0x02
PF2 - blue LED 0x04
PF3 -green LED 0x08
*/
#include <stdint.h>
#include <TM4C123GH6PM.h> //Tiva C Series TM4C123G “Header File”.
void delay();
int main()
{
/*GPIOF Initialization*/
SYSCTL->RCGCGPIO |= 0x20;
GPIOF->DIR = 0x02;
GPIOF->DEN = 0x02;
while (1)
{
GPIOF->DATA |= 0x02;
delay();
GPIOF->DATA &= ~(0x02);
delay();
}
}
void delay() {
//SysTick Initialization sequence:
/*1. Program the value in the STRELOAD register.*/
SysTick->LOAD = 0x00F423FF; //Value for 1sec delay giving a system clock of 16 MHz.
/*2. Clear the STCURRENT register by writing to it with any value.*/
SysTick->VAL = 0x0; //Reset the SysTick counter value.
/*3. Configure the STCTRL register for the required operation.*/
SysTick->CTRL = 0x5; //Enable SysTick, no interrupt, use system clock
while((SysTick->CTRL & 0x10000) == 0){} //Here is the delay: wait until the Count flag is set
SysTick->CTRL = 0x0; //Stop the Counter
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | /* The following program show how to set up the Sistem Timer Tick (SysTick) to blink the red LED with a delay time of 1 second using the Tiva C Series TM4C123G LaunchPad. All LEDs are high active (a "1" turns ON the LED). PF1 - red LED 0x02 PF2 - blue LED 0x04 PF3 -green LED 0x08 */ #include <stdint.h> #include <TM4C123GH6PM.h> //Tiva C Series TM4C123G “Header File”. void delay(); int main() { /*GPIOF Initialization*/ SYSCTL->RCGCGPIO |= 0x20; GPIOF->DIR = 0x02; GPIOF->DEN = 0x02; while (1) { GPIOF->DATA |= 0x02; delay(); GPIOF->DATA &= ~(0x02); delay(); } } void delay() { //SysTick Initialization sequence: /*1. Program the value in the STRELOAD register.*/ SysTick->LOAD = 0x00F423FF; //Value for 1sec delay giving a system clock of 16 MHz. /*2. Clear the STCURRENT register by writing to it with any value.*/ SysTick->VAL = 0x0; //Reset the SysTick counter value. /*3. Configure the STCTRL register for the required operation.*/ SysTick->CTRL = 0x5; //Enable SysTick, no interrupt, use system clock while((SysTick->CTRL & 0x10000) == 0){} //Here is the delay: wait until the Count flag is set SysTick->CTRL = 0x0; //Stop the Counter } |
Comments