PDA

View Full Version : Chip speed



The Master
- 21st November 2007, 06:16
Hi. Is it possible to find out how long it takes to run a certain block of code?

mister_e
- 21st November 2007, 06:30
Yes indeed!

at least 3 method
use MPLAB sim or else simulator
toggle a led and measure it with a scope
use a PIC timer and show it on LCD or via SerialComm

i like the Timer option as it measure the real stuff in a real environment. Have a look at the followings

instruction execution time
http://www.picbasic.co.uk/forum/showthread.php?t=365

Now a collection of pretty nice and usefull tools...


Embedded Strings in your Code Space (http://www.picbasic.co.uk/forum/showthread.php?t=1999)
While we're on the subject of optimization... (http://www.picbasic.co.uk/forum/showthread.php?t=5445)
The EXT (external) modifier. (http://www.picbasic.co.uk/forum/showthread.php?t=3891)
How much code would a code hog hog (http://www.picbasic.co.uk/forum/showthread.php?t=2418)
instruction execution time (http://www.picbasic.co.uk/forum/showthread.php?t=365)


Example how to mix them all together...
The Best Solution post #9
http://www.picbasic.co.uk/forum/showpost.php?p=39033&postcount=9

The Best Solution --- The whole thread
http://www.picbasic.co.uk/forum/showthread.php?t=6419&highlight=stuff+handy

Once again... Thanks Darrel!

HenrikOlsson
- 21st November 2007, 06:36
Hi,
You have a couple of options:
** Run it and time it in the simulator in MPLAB.
** Set a pin high when you enter the code section and low when you exit it. Look at the output with an oscilloscope.
** Use one of the PIC's timers to measure the execution time. Start it when you enter the section of code and stop it when you exit it. Someone (Darrel perhaps??) posted some code that was perfect for that but I can't seems to find it right now. I'll take another look.

/Henrik Olsson.

EDIT: OK Steve beat me to it. With nicer layout AND links to the code I was thinking about, and then some....

mister_e
- 21st November 2007, 06:44
;) even much funny, you said it in same order as me :D

Darrel Taylor
- 21st November 2007, 08:23
Oh stop,

You're making me blush. :o

EDIT: What am I saying ??
&nbsp; &nbsp; Bring it on.<br>

The Master
- 21st November 2007, 09:26
Wow. Thats a lot of stuff to be looking at. An oscilloscope is deffo out because i dont have one and i think they are expensive. Ive never used the simulator before but im guessing it runs on the PC and could be affected by other programs that are running. I will try out the timer method because it seems best. Ive just gotta have a good read through those links to find out how to use one.

Thanx for the optimization bits too. I like things to be as optimized as possible.