CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: Timers

  1. #1
    Join Date
    Jan 2006
    Posts
    35

    Timers

    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!

  2. #2
    Join Date
    Mar 2001
    Posts
    2,529

    Re: Timers

    http://www.codeguru.com/forum/showth...ormanceCounter
    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
    Last edited by ahoodin; February 20th, 2006 at 11:10 AM.

  3. #3
    Join Date
    May 2005
    Posts
    4,954

    Re: Timers

    Quote Originally Posted by eeboy
    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.

    Cheers
    If a post helped you dont forget to "Rate This Post"

    My Article: Capturing Windows Regardless of Their Z-Order

    Cheers

  4. #4
    Join Date
    Jan 2006
    Posts
    35

    Re: Timers

    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.

  5. #5
    Join Date
    Mar 2001
    Posts
    2,529

    Re: Timers

    Quote Originally Posted by eeboy
    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.

    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);
    Last edited by ahoodin; February 20th, 2006 at 02:21 PM.

  6. #6
    Join Date
    Jan 2006
    Posts
    35

    Re: Timers

    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!

  7. #7
    Join Date
    Mar 2001
    Posts
    2,529

    Re: Timers

    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
    Last edited by ahoodin; February 22nd, 2006 at 07:28 AM. Reason: funny

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured