cancel
Showing results for 
Search instead for 
Did you mean: 

I set the MCU STM32F103C8 to 72 MHz (8 MHz external oscillator). However, the function does not give exactly 1 ms of time, but a value approximately 4 times larger. Any suggestion?

WRain.1
Associate

0693W00000Bc4cEQAR.pngvoid delay_ms ( unsigned int i ){

  unsigned int temp;

  SysTick-> LOAD = 9000 * i; // if subtle, the SysTick-> LOAd = 9 * i;

  SysTick->CTRL = 0x01;

  SysTick->VAL = 0;

  do{

 temp = SysTick-> CTRL; // read the current countdown value

  }while ( ( temp & 0x01 ) && ( !( temp & ( 1 << 16 ) ) ) );

 SysTick-> CTRL = 0x00; // Close counter

 SysTick-> VAL = 0; // counter is cleared

}

2 REPLIES 2

Try doing this with a simple free-running TIM clocking at 1 MHz, 16-bit maximal mode

SysTick counts DOWN

Review what actual code is executing with the RCC/PLL settings.

Output the internal clock via MCO (PA8) and scope that.

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

For sub-microsecond granularity look at DWT CYCCNT, 32-bit up-count at core frequency

SysTick can clock at SYSCLK(HCLK,) or the SYSCLK DIV8, 24-bit down-count

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