View previous topic :: View next topic |
Author |
Message |
jpts
Joined: 08 Mar 2017 Posts: 40
|
knowing cycle program time |
Posted: Sun Mar 12, 2017 12:56 pm |
|
|
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
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Sun Mar 12, 2017 1:33 pm |
|
|
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
|
|
Posted: Sun Mar 12, 2017 2:15 pm |
|
|
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
|
|
Posted: Sun Mar 12, 2017 2:32 pm |
|
|
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
|
|
Posted: Sun Mar 12, 2017 2:49 pm |
|
|
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
|
|
|
Rob1955
Joined: 25 Feb 2017 Posts: 6
|
|
Posted: Sun Mar 12, 2017 10:39 pm |
|
|
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. |
|
|
|