J
John Lafrowda
Hi all,
after my last posting, I received some information that original windows
timers are limited by the internal clock precision which is normally set to
10 ~ 15 ms. I also learned that this can be changed by undocumented kernel
methods (NtSetTimerResolution). However, I have also found information that
describes a simpler way to generate a faster / more precise timer. According
to this information, the multimedia timers should do the job. The
MM-Timer-API looks quite basic to me - but nevertheless, I cannoz get it to
work properly. When I try to estabilsh a periodic timer on a 1 ms basis
(which was done by other people as they say in NGs), I still end up with a
timer that is directly called again after it is finished (--> with 0 ms
delay) or alternatively with the 15 ms delay of the original clock rate. The
result is the same as with standard timers: In _average_, the timer produces
a delay of 1 ms.
Below is my code. It creates an MM timer with a perodic event to be called
every 1 ms. After establishing the timer, the main thread is going to sleep
for half a second. Then, the timer is killed and the delay times that were
detected by the first 10 calls to the timer method are presented.
Can anyone tell me where I went wrong?
Regards,
John
#include <windows.h>
#include <stdio.h>
int d[1000];
int dc;
int OldTime;
int NewTime;
void CALLBACK TimerProc(UINT uID, UINT uMsg, DWORD dwUser, DWORD dw1, DWORD
dw2){
NewTime = GetTickCount();
d[dc] = NewTime-OldTime;
OldTime = NewTime;
dc++;
}
int main(){
int i;
TIMECAPS TimeCaps;
MMRESULT TimerID;
dc = 0;
timeGetDevCaps(&TimeCaps, sizeof(TIMECAPS));
printf("Min: %d, Max: %d\n", TimeCaps.wPeriodMin, TimeCaps.wPeriodMax);
OldTime = GetTickCount();
timeBeginPeriod(1);
TimerID = timeSetEvent(1, 0, TimerProc, 0,
TIME_PERIODIC|TIME_CALLBACK_FUNCTION);
Sleep(500);
timeKillEvent(TimerID);
timeEndPeriod(1);
for(i = 0; i < 10; i++){
printf("Delay[%d]: %d\n", i, d);
}
return 0;
}
after my last posting, I received some information that original windows
timers are limited by the internal clock precision which is normally set to
10 ~ 15 ms. I also learned that this can be changed by undocumented kernel
methods (NtSetTimerResolution). However, I have also found information that
describes a simpler way to generate a faster / more precise timer. According
to this information, the multimedia timers should do the job. The
MM-Timer-API looks quite basic to me - but nevertheless, I cannoz get it to
work properly. When I try to estabilsh a periodic timer on a 1 ms basis
(which was done by other people as they say in NGs), I still end up with a
timer that is directly called again after it is finished (--> with 0 ms
delay) or alternatively with the 15 ms delay of the original clock rate. The
result is the same as with standard timers: In _average_, the timer produces
a delay of 1 ms.
Below is my code. It creates an MM timer with a perodic event to be called
every 1 ms. After establishing the timer, the main thread is going to sleep
for half a second. Then, the timer is killed and the delay times that were
detected by the first 10 calls to the timer method are presented.
Can anyone tell me where I went wrong?
Regards,
John
#include <windows.h>
#include <stdio.h>
int d[1000];
int dc;
int OldTime;
int NewTime;
void CALLBACK TimerProc(UINT uID, UINT uMsg, DWORD dwUser, DWORD dw1, DWORD
dw2){
NewTime = GetTickCount();
d[dc] = NewTime-OldTime;
OldTime = NewTime;
dc++;
}
int main(){
int i;
TIMECAPS TimeCaps;
MMRESULT TimerID;
dc = 0;
timeGetDevCaps(&TimeCaps, sizeof(TIMECAPS));
printf("Min: %d, Max: %d\n", TimeCaps.wPeriodMin, TimeCaps.wPeriodMax);
OldTime = GetTickCount();
timeBeginPeriod(1);
TimerID = timeSetEvent(1, 0, TimerProc, 0,
TIME_PERIODIC|TIME_CALLBACK_FUNCTION);
Sleep(500);
timeKillEvent(TimerID);
timeEndPeriod(1);
for(i = 0; i < 10; i++){
printf("Delay[%d]: %d\n", i, d);
}
return 0;
}