Solved

Timer smaller than 1 milisecond(ms)? I need microseconds(us)!

Posted on 2002-05-17
8
379 Views
Last Modified: 2008-02-01
Dear friends,
I am buidind a small data aquisition program for a custom designed interface, through the LPT.
The A/D converter needs a start signal to convert a value. But before reading it, I must wait about 50-60 MICROSECONDS (about 0.05 miliseconds).
How can I do that in Visual Basic?
Thanks.
0
Comment
Question by:robertut
8 Comments
 
LVL 4

Accepted Solution

by:
RichW earned 70 total points
ID: 7016176
Public Declare Sub Sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)



Sleep 0.05
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 7016203
?->
0
 

Expert Comment

by:HobbitHouse
ID: 7016327
due to a hangover from the earliest days of PCs, the timer available to programmers has a resolution of 55 ms, so I think you're out of luck
0
 
LVL 4

Expert Comment

by:RichW
ID: 7016408
If you run the SLEEP you've got te 0.05 milliseconds pause without the need of a timer.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Expert Comment

by:hiranmaya
ID: 7016627
Sleep may not be the good suggestion.
0
 

Author Comment

by:robertut
ID: 7016770
I am planning to use sleep.
"Sleep may not be the good suggestion." - why is that?
Robert
0
 
LVL 4

Expert Comment

by:RichW
ID: 7016886
Robertut, the Sleep api is a good suggestion for a pause without using a timer object.  

It's really not much different from something like:

Dim x as Long

Do Until x = 500
   x = x + 1
Loop

0
 

Expert Comment

by:bal3x
ID: 23586140
I had the same problem a week ago, i needed to capture data from LPT in order of microseconds.

Try this way

If you don't need accurate timing (i dont think that SLEEP can help you, it is not very accurate)
better solution is to set your application in REALTIME level of process priority
next thing to do is to capture data from LPT with exact number of samples

Example: For i=1 to (number of samples)
                 {read from LPT]
                 {store value in array with same lenght as the number of samples]
               Next

When finished with reading return to normal level of priority.

Here is my source code

Private Sub SetProcessPriority(ByVal processname As String, ByVal priority As ProcessPriorityClass)
        Dim pl() As Process = Process.GetProcessesByName(processname)
        For Each p As Process In pl
            p.PriorityClass = priority
        Next
End Sub


Private Sub cmbRead_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbRead.Click
     
    SetProcessPriority("app name", ProcessPriorityClass.RealTime)
     
    For a = 1 To NoSamples
            pole(a) = "read from LPT"    'write command to read from lpt, i used external module to read'
    Next
   
    SetProcessPriority("app name"t, ProcessPriorityClass.Normal)

End Sub

HAVE FUN
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VBA: Add rows to listbox based on criteria 7 79
Using "ScreenUpdating" 6 55
Visual Studio 2005 text editor 10 35
IF ELSE Statement in Excel Macro VBA 16 36
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now