This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Measuring the clocks

Is there any way to measure the number of clocks taken by a part of my code.

I can measure the time taken by the part of my code and divide it sys clk. But I dont want to do it,b'cos using a timer itself consume some clocks in the form of ISR, if it overflows.

Any suggestion pls

Parents
  • Find an unused timer, start it at the beginning of the code block you with to profile, stop it after the code block you wish to profile. No ISR is necessary, works for cycle counts up to 65535.

    For longer pieces of code, you need to count how often the timer overflows, which also gives you the information how often the ISR was called. Since the ISR should be fairly short, it is easy to determine for how many cycles the ISR runs, which you can then subtract from your total.

    Alternatively, you can of course count the cycles necessary for the instructions, but this is probably only practical for short pieces of code.

Reply
  • Find an unused timer, start it at the beginning of the code block you with to profile, stop it after the code block you wish to profile. No ISR is necessary, works for cycle counts up to 65535.

    For longer pieces of code, you need to count how often the timer overflows, which also gives you the information how often the ISR was called. Since the ISR should be fairly short, it is easy to determine for how many cycles the ISR runs, which you can then subtract from your total.

    Alternatively, you can of course count the cycles necessary for the instructions, but this is probably only practical for short pieces of code.

Children