title: How to get an accurate 1ms Timer Tick under WinXP
body: <p>I try to call a function every 1 ms. The problem is, I like to do this with windows. So I tried the multimediatimer API. </p>
  
  <h2>Multimediatimer API</h2>
  
  <p>Source</p>
  
  <pre><code>idTimer = timeSetEvent( 
       1, 
       0,
       TimerProc, 
       0, 
       TIME_PERIODIC|TIME_CALLBACK_FUNCTION ); 
  </code></pre>
  
  <p>My result was that most of the time the 1 ms was ok, but sometimes I get the double period. See the little bump at around 1.95ms 
  <a href="http://www.freeimagehosting.net/uploads/8b78f2fa6d.png">multimediatimerHistogram http://www.freeimagehosting.net/uploads/8b78f2fa6d.png</a></p>
  
  <p>My first thought was that maybe my method was running too long. But I measured this already and this was not the case.</p>
  
  <h2>Queued Timers API</h2>
  
  <p>My next try was using the queud timers API with </p>
  
  <pre><code>hTimerQueue = CreateTimerQueue();
  if(hTimerQueue == NULL)
  {
  printf("Error creating queue: 0x%x\n", GetLastError());
  }
  
  BOOL res = CreateTimerQueueTimer(
  &amp;hTimer, 
  hTimerQueue, 
  TimerProc, 
  NULL, 
  0, 
  1,  // 1ms
      WT_EXECUTEDEFAULT);
  </code></pre>
  
  <p>But also the result was not as expected. Now I get most of the time 2 ms cycletime.
  <a href="http://www.freeimagehosting.net/uploads/2a46259a15.png">queuedTimer http://www.freeimagehosting.net/uploads/2a46259a15.png</a></p>
  
  <h2>Measurement</h2>
  
  <p>For measuring the times I used the method QueryPerformanceCounter and QueryPerformanceFrequency. </p>
  
  <h2>Question</h2>
  
  <p>So now my question is if somebody encountered similar problems under windows and maybe even found a solution?</p>
  
  <p>Thanks.</p>