cancel
Showing results for 
Search instead for 
Did you mean: 

I have STM32F427 with SYSCLK set to 18OMHz, what should be the frequency of the main while loop?

MSHAL.1
Associate

I tried to test the main while loop frequency with short code that throw the HAL_GetTick() through uart (baudrate of 115200) and present it every 18000000 (18M) main while loops, I also measured the time between each loop and I got the same value of 2800 millisecond.

the calculation show the the frequency is:

18000000/2.8 = 6428571Hz

the main while loop should really be at 180Hz if the SYSCLK set to 18OMHz?

is there maybe something with my clock configuration that make it slower?

is it the uart make the loop slower?

is there other way to test the main loop frequency?

this is my code:

volatile uint64_t counter = 0;

volatile uint32_t time = HAL_GetTick();

volatile uint32_t delta = 0 ;

while (1)

{

counter++;

if (counter>=18000000){

delta = HAL_GetTick() - time;

time = HAL_GetTick();

sprintf(msg, "%ld", delta);

//HAL_UART_Transmit(&huart7, (uint8_t*) msg, sizeof(msg), 10);

mComm->SendLog(slidar::INFO,msg,sizeof(msg));

counter=0;

}

}

3 REPLIES 3

I think it's more probable that you don't understand how compilers convert C code​ to machine code, how many machine cycles a 64 bit add, a pair of load/store, and a branch cost.

A​nd it's not a single cycle..

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

You can view the disassembly to determine how many cycles the loop will take, although it's not a very useful number know, and it will change as you add more things to the main loop.

Chancing optimization settings typically changes how many cycles the loop takes, with higher optimization settings creating faster loops.

Cycles per instruction can be seen here:

https://developer.arm.com/documentation/ddi0439/b/CHDDIGAC

If you feel a post has answered your question, please click "Accept as Solution".
MSHAL.1
Associate

Thank you very much!