Ttelmah
Joined: 11 Mar 2010 Posts: 19545
|
|
Posted: Fri Jun 22, 2012 4:09 am |
|
|
A search here will find lots of answers.
Basically:
1) Count the instruction cycles, and calculate it.
2) Use a tool to do this (stopwatch function in MPLAB for example).
3) Time it in the hardware. Pulse a pin before the instruction, then again after. Time the interval with a scope/logic analyser/stopwatch.
It is important to understand that the smallest things can have hundred of solutions. For example:
a=b+c;
Time needed will depend first, on the numeric 'types' used. int, int16, int32, and float will take successively longer. Then it'll also vary with the declarations of the variables. If (for instance), 'a' is a simple int variable, the function will take perhaps a dozen cycles longer if instead 'a' is an array entry. Then it'll even vary with the order the variables are declared, so the variables declared first in the program will tend to be stored in the first bank of RAM, moving up through the banks as you move to latter declarations. If in this example, 'a' is a global variable declared right at the start of the program, while b, and c are declared much further on, the code may well have to get involved in bank switching to access the variables, adding yet more cycles. Also, in some cases, if things are accessed consecutively to/from the same memory location, or code page, the optimiser is able to possibly carry the result 'forward' from it's previous access, reducing instruction cycles, or at the minimum, save bank switches.
Pulsin itself, will run fine whatever the speed, but the maximum pulse width supported, will drop directly with the clock, and the value returned rise directly with the clock rate, so the uSec time becomes *2, instead of *10 if your clock is five times faster.
Best Wishes |
|