cancel
Showing results for 
Search instead for 
Did you mean: 

Am I understanding the SysTick timer correctly?

MMust.5
Senior II

Here

SysTick_Config(16 000 000)

takes one second to count down from 16 000 000 to zero?

That is, one tick has a duration of 1/16 000 000==62.5 ns ?

0.0000000625(one tick time) *16 000 000 ticks== 1 second

Correctly?

At the end of each count, an interruption is made, I know this, I just do not understand what I wrote above.

8 REPLIES 8

Would depend if SYSCLK is actually 16 MHz, where there are 16,000,000 cycles per second, and each is 1/16,000,000 seconds in duration.

The SysTick typically clocks at HCLK or HCLK/8, and the down count is 24-bits wide

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

I found SYSCLK and HCLK.

0693W00000NqnypQAB.pngWhich of these two parameters determines how long one tick will last?

>>The SysTick typically clocks at HCLK or HCLK/8, and the down count is 24-bits wide

24 bits is 16 777 215

This is more than 16 megahertz.

I know that the SysTick->LOAD register is 24 bits, but that's more than 16 megahertz.

0693W00000Nqnz4QAB.pngJW

I checked with this code what frequency SysTick uses as a reference for the duration of one tick.

#include "main.h"
uint16_t delay_count=0;
void SysTick_Handler(void)
{
 if(delay_count>0)
 {
  delay_count--;
 }
}
void delay_ms(uint16_t delay_temp)
{
 delay_count=delay_temp;
 while(delay_count)
 {
 }
}
int main(void)
{
RCC->AHB1ENR|=RCC_AHB1ENR_GPIODEN;
GPIOD->MODER|=1<<(2*12);
SysTick_Config(16000000);
 while (1)
 {
 GPIOD->ODR^=(1<<12);
 delay_ms(5);
 GPIOD->ODR^=(1<<12);
 delay_ms(5);
 }
}

The SYSCLK frequency is used as a reference for the duration of one tick.

That is, 1 tick is equal in my case to 1/16,000,000=62.5 ns

Probably the System Timer that you showed is also used somehow, I don't know how.

How is the System Timer you showed used?

MMust.5
Senior II

If I change the System Timer to 1 MHz, then the duration of the blinking of the LED does not change, which means that the System Timer most likely does not control the duration of one tick.

However, changing SYSCLK also does not change the blinking duration of the LED.

0693W00000NqoI1QAJ.png 

By clicking in CubeMX and using generated code, you should accept that CubeMX "does things".

If you want to understand them, look into those. In other words, read the CubeMX-generated and Cube-provided sources and act accordingly. They are open-source.

Ultimately, the mcu works out of the content of its registers, so if you want to really understand what's going on, read out those registers.

JW

Pavel A.
Evangelist III

@Community member​ 

Cube does not generate code for the divisor of SysTick, at least for one STM32 type.

So if you change it from 1 to 8 and re-generate it may not work.