CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

How can I know how long time it use for 1 command in CCS?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
mmc01



Joined: 16 Jun 2010
Posts: 31

View user's profile Send private message

How can I know how long time it use for 1 command in CCS?
PostPosted: Fri Jun 22, 2012 2:54 am     Reply with quote

I try to use pulsin function from http://www.ccsinfo.com/forum/viewtopic.php?t=42353 . This function work when I use clock=4MHz but when I use clock=20MHz it's not work. I don't know why and how to correct it. May be I have to change at result * 10 but I don't know how can I read time which use for 1 command in CCS.
Ttelmah



Joined: 11 Mar 2010
Posts: 19541

View user's profile Send private message

PostPosted: Fri Jun 22, 2012 4:09 am     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group