PDA

View Full Version : Code execution time?



achilles03
- 24th February 2009, 14:43
I remember seeing a post regarding how to measure the elapsed time for some code, but after searching for it I can't find it. My application is for a radio modem, and I need to measure things in the microsecond range. Any help either pointing me to that thread or code examples is appreciated!

Thanks!
Dave

ScaleRobotics
- 24th February 2009, 15:18
Just saw that one myself.

http://www.picbasic.co.uk/forum/showthread.php?t=9350

LinkMTech
- 24th February 2009, 15:22
One simple way is to assign an unused pin to an output then have it go HI just before the portion of code you need to measure then go LOW immediately afterwards. This output is now your code elapsed time o-scope test point!
Simple example:


Test VAR PORTB.2 ' Assign a name to the unused pin
Test=0 ' Set pin low at top of program

'Some of your program

Test=1 ' Set output HI
Your chunk of program here to be timed
Test=0 ' Set output LO

Rest of program continues from here


I use this alot and the cool thing about it is I can move it anywhere and have it trigger multiple times when looking timer activity. I'm sure there are slicker ways but this works for me.

mister_e
- 24th February 2009, 16:07
This is one part of SteveB's implementation.
http://www.picbasic.co.uk/forum/showthread.php?t=365

Another version which also give you the codespace used and so on
http://www.picbasic.co.uk/forum/showpost.php?p=39033&postcount=9

The whole story of the above
http://www.picbasic.co.uk/forum/showpost.php?p=39049&postcount=13

If you have MPLAB, you could also use the StopWatch feature.

HTH