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

knowing cycle program time

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



Joined: 08 Mar 2017
Posts: 40

View user's profile Send private message

knowing cycle program time
PostPosted: Sun Mar 12, 2017 12:56 pm     Reply with quote

How the best way to measure the program run cycle time. PIC16F
Means how long a program takes to 1 cycle completed...
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Mar 12, 2017 1:21 pm     Reply with quote

This post explains how to use the MPLAB (vs. 8.92) Stopwatch feature
to find out how many cycles (and microseconds) it takes to execute a
block of code:
http://www.ccsinfo.com/forum/viewtopic.php?t=38351
temtronic



Joined: 01 Jul 2010
Posts: 9226
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Mar 12, 2017 1:33 pm     Reply with quote

PCM P's link is one 'best' way..
another is 'old school'.
Crack open the PIC datasheet, locate the instruction set, printout your code( the listing file), then lookup the instructions and tabulate the times to execute.
Yes, it'll take longer but you'll get a far better understanding on how PICs work.

Jay
jpts



Joined: 08 Mar 2017
Posts: 40

View user's profile Send private message

PostPosted: Sun Mar 12, 2017 2:15 pm     Reply with quote

can have this time to be printed ? available to use in program ?
ex:
clock = 4Mhz
int x, y, z

x = y * z;
x = y + z;
delay_ms(10);
x = x + 100;

Whats the time of each cycle program...??
printf ( program time cycle) ????
Ttelmah



Joined: 11 Mar 2010
Posts: 19513

View user's profile Send private message

PostPosted: Sun Mar 12, 2017 2:32 pm     Reply with quote

Not possible....

In the manual for the compiler, you will find a section giving, the times for the maths operations, for different numeric types. These are the 'core' times, but ignore any overheads, like converting between source types etc..

The printf will depend on the speed of whatever you send the data to, and how it is sent. Amount of buffer for serial etc..

Even with all of these calculated, the times will still change though. Things specific to your program. So (for instance), how much time it takes to load a variable may well differ, if a bank switch has to occur to access this variable.

Hence the MPLAB solution, or simple toggle a pin before and after the operation, and measure how long the pulse is this gives.
jpts



Joined: 08 Mar 2017
Posts: 40

View user's profile Send private message

PostPosted: Sun Mar 12, 2017 2:49 pm     Reply with quote

understand...but how to implement frequency for instance...where need pulse / second...or pulses / period of time...

for example:
setup_timer_0(RTCC_EXT_L_TO_H|RTCC_DIV_1|RTCC_8_bit);

pulse = get_timer0();

how measure the frequency pulse in ?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Mar 12, 2017 4:45 pm     Reply with quote

These threads tell how to use the CCP module to measure frequency:

Determining square-wave frequency input into pic:
http://www.ccsinfo.com/forum/viewtopic.php?t=29963

CCP / 24 bit timer / 1hz to 150 hz range:
http://www.ccsinfo.com/forum/viewtopic.php?t=33153
Rob1955



Joined: 25 Feb 2017
Posts: 6

View user's profile Send private message

PostPosted: Sun Mar 12, 2017 10:39 pm     Reply with quote

jpts wrote:
can have this time to be printed ? available to use in program ?
ex:
clock = 4Mhz
int x, y, z

x = y * z;
x = y + z;
delay_ms(10);
x = x + 100;

Whats the time of each cycle program...??
printf ( program time cycle) ????


new to PIC here but shouldn't this answer this specific query:


Code:


set_timer1(0);
.......
.......
.......
.......
int16 HowLong = get_timer1();

//printf value after converting it to (us) or (ms) if desired.
//and printf time is not included in above time.



and maybe extending the timer to 24 bit if suspect timer will overflow depending on the prescaler and clock being used. This way interrupt cycle time is also included in the overall time it took the PIC to cover measured section.
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