Lec6 SysTickTimer
Lec6 SysTickTimer
Lec6 SysTickTimer
Lecture 6:
SysTick Timer
6-1
SysTick Timer
Timer/Counter operation
24-bit counter decrements at bus clock
frequency
o With 48MHz bus clock, decrements every 20.83 ns
Counting is from n 0
o Setting n appropriately will make the counter a
modulo n+1 counter. That is:
next_value = (current_value-1) mod (n+1)
Sequence: n,n-1,n-2,n-3… 2,1,0,n,n-1…
6-2
SysTick Timer
Address 31-24 23-17 16 15-3 2 1 0 Name
0xE000E010 0 0 COUNT 0 CLK_SRC INTEN ENABLE SYSTICK_STCSR
0xE000E014 0 24-bit RELOAD value SYSTICK_STRVR
0xE000E018 0 24-bit CURRENT value of SysTick counter SYSTICK_STCVR
Initialization (4 steps)
Step1: Clear ENABLE to stop counter
Step2: Specify the RELOAD value
Step3: Clear the counter via SYSTICK_STCVR
Step4: Set SYSTICK_STCSR
o CLK_SRC = 1 (bus clock is the only option)
o INTEN = 0 for no interrupts
o ENABLE = 0 to enable
6-3
SysTick Timer in C (using Polling)
void SysTick_Init(void){
SysTick->CTRL = 0; // 1) disable SysTick during setup
SysTick->LOAD = 0x00FFFFFF; // 2) maximum reload value
SysTick->VAL = 0; // 3) any write to current clears it
SysTick->CTRL = 0x00000005; // 4) enable SysTick with core clock
}
void SysTick_Handler(void){
.... // Do stuff
}