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

Execution Time

Hello, I want to determine execution time required for a function which executes when a serial interrupt occurs. I am using Keil C compiler for it. Can anybody tell me procedure for the same.

Regards,
Abhijeet R. Mudgal.

  • If the function is written in C, then let the compiler generate assembly code and count the cycles needed for the assembly instructions. However, this will only be valid for this compilation run, if you change the program, the compiler, or the compiler settings, you'll have to do the calulcation again.

  • As Christoph suggested, you could count instructions and cycles. Sometimes that is impractical, i.e. when there are too many instructions, too many nested functions, too difficult to account for extra wait states and so on.
    You could also do direct measurement. For example, toggle an external port pin on entry to ISR, toggle it back on exit and use a scope to time it. You could also use a high-resolution on-chip timer if available. Of course, the extra instructions needed for the measurement will distort the result somewhat.

  • I want to determine execution time required for a function"

    Why do you want to do that?

    Have you simply been set this as an exercise, or is it an important requirement for your application for you to know this?

    If it is important for your application for you to know this, then you should not be writing in 'C' - because 'C' gives you absolutely no guarantee whatsoever that it won't change!

    If it is important for your application for you to know this, then you should be writing it in assembler - then you know exactly what you will get!

  • If it is important for your application for you to know this, then you should be writing it in assembler - then you know exactly what you will get!

    Why so categorical? I _always_ try to estimate execution time and expected rate of triggering of my ISRs. Just to make sure I don't overwhelm the CPU. Knowing that I have a good margin in CPU usage, I can be sure that minor modifications in compiler output will not change my estimate dramatically.

  • An estimate is one thing; trying to fully determine it is another.

    But maybe I misinterpreted the question - and all he wants is, as you say, an estimate.

    "I can be sure that minor modifications in compiler output will not change my estimate dramatically."

    Beware - aparently "minor" changes to the source code might cause major changes in the executable...!

  • I meant to add:

    If he made clear why he wants to do this - which was my question - it'd probably be clear whether or not I'd misinterpreted...