• Advertisement
Sign in to follow this  

using winio.dll to read 8253 timer

This topic is 4832 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'd like to get accurate timer by using read 8253 directly,I'm now using winio.dll to do this,the code is like this: if (InitializeWinIo()) { // Under Windows NT/2000/XP, after calling InitializeWinIo, // you can call _inp/_outp instead of using GetPortVal/SetPortVal DWORD dwCount = 0; DWORD dwBegin = GetTick(); LARGE_INTEGER liQ,liC1,liC2; DWORD dw1 = GetTickCount(); QueryPerformanceFrequency(&liQ); QueryPerformanceCounter(&liC1); DWORD dwOldProcessP = GetPriorityClass(GetCurrentProcess()); DWORD dwOldThreadP = GetThreadPriority(GetCurrentThread()); SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS); SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL); do { //printf("%d\n",dwBegin); DWORD dwTick = GetTick(); dwCount += dwBegin > dwTick ? dwBegin - dwTick : 65535 + dwBegin - dwTick; dwBegin = dwTick; QueryPerformanceCounter(&liC2); }while((liC2.QuadPart - liC1.QuadPart) / (double)liQ.QuadPart < 1.000000); SetThreadPriority(GetCurrentThread(), dwOldThreadP); SetPriorityClass(GetCurrentProcess(), dwOldProcessP); printf("QueryPerformanceCounter : %f\n",(liC2.QuadPart - liC1.QuadPart) / (double)liQ.QuadPart); printf("8253 Tick : %d\n",dwCount); DWORD dw2 = GetTickCount(); printf("GetTickCount : %d\n",dw2 - dw1); ShutdownWinIo(); } this is a test program,I loop one second,and count the 8253 ticks,that result should be ~1193177. it works on many machines,but on my machine,the result is ~2386362,twice the right value! can anyone help me?

Share this post


Link to post
Share on other sites
Advertisement
Be aware that depending on what mode they're set up in, some timers count by twos instead of ones. Check the count mode selection?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement