cancel
Showing results for 
Search instead for 
Did you mean: 

The clocks each command takes

Arman Ilmak
Senior
Posted on April 27, 2018 at 19:51

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.
21 REPLIES 21
henry.dick
Senior II
Posted on April 27, 2018 at 20:25

1. Time it with a scope, or

2. Look at the disassembly.

Arman Ilmak
Senior
Posted on April 27, 2018 at 21:18

How can I use disassembly to get the clock numbers?

Each disassembly line is just one clock?

Posted on April 27, 2018 at 23:24

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. 

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on April 28, 2018 at 08:41

What is the underlying problem you want to solve?

I guess you do not want to count the cycle to count the cycles...

Posted on April 28, 2018 at 20:28

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.

Posted on April 28, 2018 at 21:06

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.

Posted on April 28, 2018 at 21:43

I'm using stm8s.Are they able to generate us delays with timers?

Posted on April 28, 2018 at 21:50

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.

Posted on April 28, 2018 at 22:41

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

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