Skip to main content
Arman Ilmak
Senior
April 27, 2018
Question

The clocks each command takes

  • April 27, 2018
  • 21 replies
  • 3593 views
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.
    This topic has been closed for replies.

    21 replies

    henry.dick
    Associate II
    April 27, 2018
    Posted on April 27, 2018 at 20:25

    1. Time it with a scope, or

    2. Look at the disassembly.

    Arman Ilmak
    Senior
    April 27, 2018
    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?

    Tesla DeLorean
    Guru
    April 27, 2018
    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 (See Profile) Up vote any posts that you find helpful, it shows what's working..
    Bogdan Golab
    Lead
    April 28, 2018
    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...

    Arman Ilmak
    Senior
    April 28, 2018
    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.

    Bogdan Golab
    Lead
    April 28, 2018
    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.