2018-04-27 10:51 AM
Hi.
I wanted to know that for example how many clocks a while loop takes.
Do you have any ideas or any articles on this matter?
Note: this post was migrated and contained many threaded conversations, some content may be missing.2018-04-27 11:25 AM
1. Time it with a scope, or
2. Look at the disassembly.
2018-04-27 12:18 PM
How can I use disassembly to get the clock numbers?
Each disassembly line is just one clock?
2018-04-27 04:24 PM
You'd need to review the processor documentation as to how many cycles each different instruction takes, and multiply that by the loop iterations.
If you want to know how many cycles different processors take you'll need to study the design and functionality.
2018-04-27 11:41 PM
What is the underlying problem you want to solve?
I guess you do not want to count the cycle to count the cycles...
2018-04-28 01:28 PM
Yeah.I have a four digit 7 segments that I have to refresh it all the time to show the numbers.But the problem is that I'm using DS18B20 for temperature and it needs about 700 ms to finish conversion and give me the result.I just wanted to know every time I call the display subroutine that refreshes the 7 segments how many cycles it takes and use the display subroutine instead of the delay subroutine.
The other is that I want to write my own delay subroutine and I don't know how many whiles or fors should I use for example to get 1 us delay.
2018-04-28 02:06 PM
Probably when you have STM32 MCUs with abundance of timers it would be easier to use timers to measure microseconds reliably.
Counting cycles might not be working reliably because the compiler optimizes the code and the code size (and consequently number of cycles) depends of the compiler configuration - see Ox settings for compilers.
2018-04-28 02:43 PM
I'm using stm8s.Are they able to generate us delays with timers?
2018-04-28 02:50 PM
I have not noticed that the post was opened in the STM8 section.
I am sorry but I do not know the STM8 family. For 8 bitters it might be the way to go.
2018-04-28 03:41 PM
If you don't want to count instruction cycles use a GPIO pin, drive it High as you enter, drive it Low as you leave, and then trigger on an oscilloscope and measure the pulse width.
To measure on the chip side, have a free running 16-bit TIM, perhaps a 1 MHz, or slower if it overflows, and read TIM->CNT at entry and exit, then compute the delta ticks. ie delta = finish_tick - start_tick