Delay Less Than 1ms

otherside

Centurion
Joined
Mar 16, 2003
Messages
127
Location
UK - Greece
Hey guys anyone has any idea how to provide a delay less than 1ms, by using threading or any other way ?

Here what i need to do
i have a USB device that i control through VB.NET using an activex cotrol.
This is a "USB to 16bit I/O" i'm using it in a sense of parallel data input. I need to read this device every 1us (0.001 ms) . by using an infenent "for" i can read it fast but there is no way to know how fast, and i need to know the samples timing.

i using a simple thread, the sleep or wait option accepts only integer of miliseconds, any ideas how i can do this ?

thanks
 
Windows platform invoke with the [api]QueryPerformanceCounter[/api] and [api]QueryPerformanceFrequency[/api] functions:

Visual Basic:
Declare Function QueryPerformanceCounter Lib "kernel32" (ByRef lpPerformanceCount As Int64) As Int32
Declare Function QueryPerformanceFrequency Lib "kernel32" (ByRef lpFrequency As Int64) As Int32

Dim pcFrequency As Int64
Dim pcStart As Int64
Dim pcCurrent As Int64
Dim pcElapsed As Double

'In class constructor:
QueryPerformanceFrequency(pcFrequency)

'When start timing:
QueryPerformanceCounter(pcStart)

'To get elapsed time since start:
QueryPerformanceCounter(pcCurrent)
pcElapsed = Convert.ToDouble(pcCurrent - pcStart) / Convert.ToDouble(pcFrequency)
pcElapsed *= 1000000 'Time diff. in microseconds

Hope this at least provides a starting point. AFAIK there is no higher resolution timing that these functions.
 
Last edited:
Back
Top