I'am working with Systick for the first time with an samd21e15b, so my objective is to be able to count time between delay for example. So here is what I've try to do
SysTick->CTRL = 0;
SysTick->LOAD = 0x7A11FFul;
SysTick->VAL = 0;
SysTick->CTRL = 0x5;
while(SysTick->VAL == 0);
uint32_t start = SysTick->VAL;
delay_ms(1000);
uint32_t stop = SysTick->VAL;
uint32_t volatile temps = start - stop;
So I set SysTick->LOAD = 0x7A11FFul
beceause my CPU run at 8Mhz and I want 1s tick, so coming from this math
N = (SysTick delay time / System Clock Period ) - 1
=(SysTick delay time * System Clock Frequency) - 1
= (1s * 8MHz) - 1 = 8M - 1 = 7,999,99
So if my cpu runs at 8MHz I have one cpu cycle every 125ns is it right? But if I inspect temps
variable I have a value of 311
after delay of 1s and I don't understand this value