cancel
Showing results for 
Search instead for 
Did you mean: 

delay function and execution time

orn
Associate II
Posted on October 25, 2012 at 09:18

Hi, I wanted to create a delay function, and I thought of something classic like this:

whlile(n_count){
n_count--;
}

but how do you know how long it loses precisely my function? I believe that there should be a link between the value of n_count and sysclock but do not know which one. I would also like to understand how can I calculate how long it takes each instruction to be executed by STM32F4 and how long it takes my development board to run the entire program! anyone know how to do these things? #hll-timing-loop---just-say-no
3 REPLIES 3
Posted on October 25, 2012 at 13:04

Software delay loops are generally to be avoided. You could look at the code/instructions generated, there should be a y = mx + c type relationship with the core clock, where m is the number of cycles consumed per loop iteration, and c is the call/setup/return overhead.

You could use the cycle counter in the trace unit to a) calibrate/benchmark, or b) act as a delta comparison for time.

https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/DispForm.aspx?ID=11943&RootFolder=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Duration of FLOAT operations

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on October 27, 2012 at 21:45

''but how do you know how long it loses precisely my function?''

 

 

You cannot predict the timing of a High-Level Language. The best you can do is to compile it, and then inspect the generated code.

http://www.8052.com/forum/read/162556

Note that compiler optimisation can greatly affect the generated code - to the point of nothing being generated at all!

If you really want to write a timing loop of known duration, you will have to write it in assembler.

orn
Associate II