2021-10-25 04:24 AM
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;
}
}
2021-10-25 04:45 AM
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.
And it's not a single cycle..
2021-10-25 06:08 AM
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
2021-10-25 07:19 AM
Thank you very much!