You are on page 1of 5

EE529 Embedded Systems

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
}

// The delay parameter is in units of the 48 MHz clock. (20.83 ns)


void SysTick_Wait(uint32_t delay){
SysTick->LOAD = delay-1; // number of counts to wait
SysTick->VAL = 0; // any value written to counter clears
while((SysTick->CTRL & 0x00010000) == 0){ // wait for count flag
}
}

// delay with 10ms units


void SysTick_Wait10ms(uint32_t delay){
uint32_t i;
for(i=0; i<delay; i++){
SysTick_Wait(480000); // wait 10ms
}
}
Bard, Gerstlauer, Valvano, Yerraballi 6-4
SysTick Timer in C (using Interrupt)

void SysTick_Init(uint32_t period, uint32_t priority){


SysTick->CTRL = 0; // 1) disable SysTick during setup
SysTick->LOAD = period - 1; // 2) reload value sets period
SysTick->VAL = 0; // 3) any write to current clears it
SCB->SHP[11] = priority<<5; // set priority into top 3 bits of 8-bit register
SysTick->CTRL = 0x00000007; // 4) enable SysTick with core clock and interrupts
}

void SysTick_Handler(void){
.... // Do stuff
}

Bard, Gerstlauer, Valvano, Yerraballi 6-5

You might also like