View Single Post
  #11   Spotlight this post!  
Unread 09-02-2004, 11:33
Chris Hibner's Avatar Unsung FIRST Hero
Chris Hibner Chris Hibner is offline
Eschewing Obfuscation Since 1990
AKA: Lars Kamen's Roadie
FRC #0051 (Wings of Fire)
Team Role: Engineer
 
Join Date: May 2001
Rookie Year: 1997
Location: Canton, MI
Posts: 1,488
Chris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond reputeChris Hibner has a reputation beyond repute
Re: How to measure execution time? And code size?

Quote:
Originally Posted by Chris Hibner
To measure the time, you should toggle a digital I/O pin every cycle. Then, hook an oscilliscope up to that pin. Using the scope, you can measure your timing very accurately.

Some example code (place this at the very beginning of your code):

static char TimingFlag;

if (TimingFlag)
TimingFlag = 0;
else
TimingFlag = 1;

Then immediately set the digital I/O pin equal to TimingFlag.

This code will produce a square wave on the scope. The time that the wave is high (or low) is your cycle time. I hope this helps.

-Chris
Oh yeah, I forgot one thing.

My first post only works if you're running the loop time as fast as possible. It doesn't work if you're setting your loop time with an interrupt. To measure this way do the following:

1) At the VERY BEGINNING of your loop, set a digital I/O pin high.
2) At the VERY END of your loop, set the same digital I/O pin low.
3) Measure the pin voltage on a scope.

The amount of the the pin stays high is the amount of time that your code takes to run.

(By the way, this is how code time is usually measured in industry.)
__________________
-
An ounce of perception is worth a pound of obscure.