cancel
Showing results for 
Search instead for 
Did you mean: 

Timer resolution question

PPopo
Senior

Hello,

I have a project in which I use an external timer module. I want to measure the time that a function takes. I have a function say _time returnTime() which is configured in such a way that it returns a time with 10 microsecond resolution.

In the function that I want to test how long it takes to execute I do something like this:

myFunction()
 
{
 
time1 = returnTime();
 
 ...
 
time2 = returnTime();
 
time_elapsed = time2 - time1;
 
}

When I do this function time elapsed is a value of 5. Is that possible. Since the returnTime() function returns a time with 10 microsecond resolution shouldn't time_elapsed be a value which is a multiple of 10?

2 REPLIES 2

> I have a function say _time returnTime() which is configured in such a way that it returns a time with 10 microsecond resolution.

Who wrote that function?

What does it return, number of microseconds, or number of 10s of microseconds?

JW

Jack Peacock_2
Senior III

Since you are reading time from an external peripheral you have to account for the overhead when accessing that module. Also, what is the size of the time returned? You'll have to handle the overflow condition when calculating the difference between two samples: for example 0xffffff00 - 0x00000012, where the timer has wrapped at 32 bits.

What happens if there's an interrupt while you're measuring the elapsed time?

Jack Peacock