Thread: Timer

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    3

    Question Timer

    How to Programm Timer with high resolution (not system timer)
    less 5 ms.
    Last edited by GNick; 04-05-2002 at 07:02 AM.

  2. #2
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    Read the system time, store that, then keep on reading it comparing with the original until the elapsed time required has happened?

    Outrageously crude and inefficient but best I can offer with so little to go on.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  3. #3
    Registered User
    Join Date
    Jan 2002
    Posts
    363
    Get a copy of the DDK and do it through interupts.
    Slightly less crude but still inefficant.

    [edit]
    oh and I forgot to mention difficult and not worth the effort
    [/edit]
    Last edited by shtarker; 04-05-2002 at 05:57 AM.
    If you own a piece of land and there is an volcano on it and it ruins a
    nearby town, do you have to pay for the property damage?

  4. #4
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    High performance timer you say? Try these, QueryPerformanceCounter and you will need QueryPerformanceFrequency to see if it's supported and if so what the frequency is. Look it up on MSDN, I think this is what you were looking for.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  5. #5
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    Perhaps you can use SetTimer to create a timer. The time-out value is in milliseconds.

    Code:
    UINT SetTimer
    (
      HWND hWnd,                   // handle of window for timer messages
      UINT nIDEvent,                // timer identifier
      UINT uElapse,                  // time-out value
      TIMERPROC lpTimerFunc  // address of timer procedure
    );

  6. #6
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    It depends how accurate you want it....if you want it to be roughly x milliseconds then SetTimer and the like will be ok......but if you want more accuracy it can be much harder (depending on the accuracy you want)
    Last edited by Fordy; 04-06-2002 at 03:16 AM.

  7. #7
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    And lying roughly in the middle in the 'accuracy stakes is the multimedia timer which you can get a 'time' with the timeGetTime fn. #include <mmsystem.h> and link with winmm.lib (msvc, borland, lcc-win32) or libwinmm.a (MinGW; can also use '-lwinmm').

  8. #8
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    He said he didn't want to use a system timer.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  9. #9
    Registered User xds4lx's Avatar
    Join Date
    Nov 2001
    Posts
    630
    If you dont want a system timer then dont post on the Windows board since this is for "Windows System Proramming!"
    "only two things are infinite, the universe and human stupidity, and im not sure about the former." - albert einstein

  10. #10
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    >>He said he didn't want to use a system timer.<<

    Major ooops! experience. One day i'll get this skim-reading right.

    Sorry for any confusion I may have caused.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. SIGALRM and timer
    By nkhambal in forum C Programming
    Replies: 1
    Last Post: 06-30-2008, 12:23 AM
  2. tic tac toe crashes :(
    By stien in forum Game Programming
    Replies: 4
    Last Post: 05-13-2007, 06:25 PM
  3. Need help with a count down timer
    By GUIPenguin in forum C# Programming
    Replies: 0
    Last Post: 07-07-2006, 04:18 PM
  4. Timer again.
    By geek@02 in forum Windows Programming
    Replies: 1
    Last Post: 05-04-2005, 10:19 PM