Click to See Complete Forum and Search --> : Timers


eeboy
February 20th, 2006, 09:53 AM
I need a timer with resolution less than 1 millisecond. I have found the QueryPerformanceCounter API. It WOULD work great however the ticks between two successive QueryPerformanceCounter calls is far to great.

Is this because the app is only allowed a small sliver of processor time before it goes on to other processes? If so is there any way to give this application an extremely high priority so this time delta will decrease?

Thanks!

ahoodin
February 20th, 2006, 10:06 AM
http://www.codeguru.com/forum/showthread.php?t=311607&highlight=QueryPerformanceCounter
Perhaps there is something happening that is taking up time between the two counter calls like poorly framed socket communications or calls to cout or printf.
HTH,

ahoodin

golanshahar
February 20th, 2006, 10:30 AM
I need a timer with resolution less than 1 millisecond. I have found the QueryPerformanceCounter API. It WOULD work great however the ticks between two successive QueryPerformanceCounter calls is far to great.

Is this because the app is only allowed a small sliver of processor time before it goes on to other processes? If so is there any way to give this application an extremely high priority so this time delta will decrease?

Thanks!

Look at Multimedia Timers (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/multimed/htm/_win32_multimedia_timers.asp).

Cheers

eeboy
February 20th, 2006, 10:56 AM
That's just it... there is nothing executing in the background (except for any services). It's a modern PC (Pentium 4) as well.

Based on what I read with multimedia timers the best achievable time period is 1 ms. I need a time period on the order of 10 us.

ahoodin
February 20th, 2006, 01:19 PM
That's just it... there is nothing executing in the background (except for any services). It's a modern PC (Pentium 4) as well.

Based on what I read with multimedia timers the best achievable time period is 1 ms. I need a time period on the order of 10 us.

Please simpley admit that you do not understand QueryPerformanceCounter(). It returns effectively the number of counts per second of the high performance counter. These are not clock ticks.
Here is your code.


LARGE_INTEGER ntime1,ntime2;
LARGE_INTEGER freq;

QueryPerformanceFrequency(&freq);//counts per second

QueryPerformanceCounter(&ntime1);
//do your op here
QueryPerformanceCounter(&ntime2);

nmicrosecs = ntime2.QuadPart-ntime1.QuadPart)/(freq.QuadPart/1000000);

eeboy
February 20th, 2006, 02:03 PM
Well, I do understand the QueryPerformanceCounter() API. Ticks may not be the most appropriate wording... but a tick is a clock cycle which is quantified by the QueryPerformanceFrequency() function.... even though it's not the actual clock of the processor.

Your code yields the same results as mine.... around 100 us. I would expect to be able to achieve values right around or a little less than 1us since my frequency is 3579545 Hz.

Any more suggestions?

Thanks!

ahoodin
February 22nd, 2006, 06:20 AM
eeboy...

Sounds like you should post your code. You mean when you stuck your code inside the code I provided, it gave you the same results. I have gleaned sub 100 us data from that code, so it can't possibly be that code, so something else must be going on.

Remove all un-necessary files. Only include your .dsp and your source files. No class wizzard files, ncb files or any other junk. Zip it and attach it. Must have a small footprint or CG will reject.

ahoodin