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.)