Henry Yiu

How to estimate clock cycles?

Discussion created by Henry Yiu on Jan 5, 2011
Latest reply on Jan 7, 2011 by Henry Yiu

Hello, I am using the MC9S08AC128 and want to have a simple way to find out the number of clock cycles to execute from one C program line to another C program line.  There might be a big for loop within this C code segment, and it could take up to one second to execute. 


I tried studying the LST file with the generated assembly instructions and clock cycles, but I have to manually add up the number of clock cycles to run a loop, and multuiply it by the loop count, which seem not a very smart method.  Then I try to use an internal timer to find out the clock cycles, but the timer is only 16-bit which cannot go beyond a few tens of milliseconds.  Besides, I don't want to waste a hardware timer just for this purpose.  Then I tried using the profiling, which is very hard to use, and the trace buffer seems to be only 300 cycles, which is less than what I need.  Moreover, the trace only trace result only shows the execution, it does not add up the clock cycles.  It also seems to slow down the normal execution of the program which is not acceptable as I have to interface run it with hardware drivers together.  Shouldn't there be a more simple way to do this?


I have use another IDE environment, and they have a clock counter.  All I need to do is set two breakpoints at A and B locations.  Execute the code to location A, reset the clock counter, then execute the code to location B, and it will show the number of clock cycles.  This is the simple thing I am talking about.


BR - Henry