Timer < 1ms

otherside

Centurion
Joined
Mar 16, 2003
Messages
127
Location
UK - Greece
Hey guys, does anyone know a way to measure time with intervall less than 1ms ?
I need to measure some signals comming from an input device and the pulses are between 100 us (microseconds) and 2 ms ?
thanks
 
You'll need to use the performance counters from the Win32 API. Here's some sample code that doesn't do anything, but shows you the functions. You can search Google for more help (search on the function names):

C#:
[System.Security.SuppressUnmanagedCodeSecurity]
[DllImport("kernel32")]
private static extern bool QueryPerformanceFrequency(ref long PerformanceFrequency);

[System.Security.SuppressUnmanagedCodeSecurity]
[DllImport("kernel32")]
private static extern bool QueryPerformanceCounter(ref long PerformanceCount);


long qwTicksPerSec; // Number of ticks per second. Based on your computer, only set this once
long qwTime;

// If bUsingQPF returns false, you can't use these - you'll have to use timeGetTime. 
// I think it's for Win98 or Win95 and earlier (can't remember which versions don't support them)
bool bUsingQPF = QueryPerformanceFrequency(ref qwTicksPerSec);
QueryPerformanceCounter(ref qwTime);

// Use QueryPerformanceCounter to get the current time. Subtract
// from previous calls to get the difference.
// Use qwTicksPerSec to get how many ticks per second you have.

-Nerseus
 
Back
Top