Hello, I'm using an stm32f103C8 and trying to produce a precise delay funcion. I'm using a HSE of 72Mhz so a I supposed the clock cycle is equal to 13.8ns. The delay function is simply a while(count--) where count has the specific number of times for looping to gain the requested time. I made an hypothese that while(count--) takes 3 cycles to execute. So when I need to make 1µs delay I put 24 in count.
But I found that I make 4us with count =24 that means 4 times the desired time. Please can you help identify this problem?
Any assumption of the timing of HLL statements is likely to be seriously flawed You see the reason, why i prefer Hardware TIMERS
Timers are designed on-chip hardware peripherals and hence very powerful. They generate precise time delays (needless to say, if configured properly).