I have an application where i have created a separate thread to collect real-time data.
This thread contains a loop that runs forever, but most of it's code only is scanned for about 2 seconds at a time.
It collects data about every .8 milliseconds during those 2 seconds.
At the end of the 2 seconds, it saves the data to a CSV file.
In the CSV, I can examine the time "ticks" on each record of data.
Sometimes I see a difference of 10 to 250 milliseconds between records.
Normally the time difference between records is about .7 to .8 milliseconds.
My goal is to eliminate what is interfering with the consistent collection of data.
I'm using VB2005 on a quad core.
Here is some sample code that i put together to simulate the problem which is on a manufacturing production machine.
sub DAQ()
Dim Ctrl, Freq, StartTicks As Long
Dim Mytimerbit As Boolean = False
Do
QueryPerformanceCounter(Ctrl) 'grab the ticks every time we loop
'reset code goes here
If MyReset = True Then
QueryPerformanceCounter(StartTicks) ' get the beginning tick value.
QueryPerformanceFrequency(Freq) ' get the Freq value.
MyReset = False
CaptureIndex = 1
Index2 = 1
Displayme = ""
Summary = ""
Mytimerbit = True
ReDim CaptureData(100000, 15) 'redim should clear it's contents.
End If
'Here i'm trying to schedule the collection to once per millisecond.
If (((Ctrl - StartTicks) / Freq) * 1000) - CaptureData(CaptureIndex - 1, 0) >= 1 Then
Mytimerbit = True
End If
If MyRunBit = True And Mytimerbit = True Then
Mytimerbit = False
CaptureData(CaptureIndex, 0) = CDbl(Format(((Ctrl - StartTicks) / Freq) * 1000, "####.###"))
CaptureData(CaptureIndex, 1) = CaptureIndex
CaptureData(CaptureIndex, 2) = CDbl(Format(CaptureData(CaptureIndex, 0) - CaptureData(CaptureIndex - 1, 0), "####.###")) 'calculates the difference in time between this record and the previous one.
'Save the info in a string to later show on the form.
Displayme = Displayme & CaptureData(CaptureIndex, 0) & vbTab & CaptureData(CaptureIndex, 1) & vbTab & CaptureData(CaptureIndex, 2) & vbCrLf
' this saves the time difference to another string to only list the large time differences later.
If CaptureData(CaptureIndex, 2) > 3.1 Then
Summary = Summary & CaptureData(CaptureIndex, 2) & vbCrLf
End If
'increments the array
CaptureIndex = CaptureIndex + 1
End If
If MyDisplayBit = True Then
Me.Label1.Invoke(New MethodInvoker(AddressOf UpdateDisplay))
MyDisplayBit = False
End If
Loop
End Sub
Private Sub UpdateDisplay()
Me.TextBox1.Text = Displayme
Me.TextBox2.Text = Summary
End Sub
-------------------
The greatest obstacle to discovery is not ignorance -- it is the illusion of knowledge.
Daniel Boorstin
This thread contains a loop that runs forever, but most of it's code only is scanned for about 2 seconds at a time.
It collects data about every .8 milliseconds during those 2 seconds.
At the end of the 2 seconds, it saves the data to a CSV file.
In the CSV, I can examine the time "ticks" on each record of data.
Sometimes I see a difference of 10 to 250 milliseconds between records.
Normally the time difference between records is about .7 to .8 milliseconds.
My goal is to eliminate what is interfering with the consistent collection of data.
I'm using VB2005 on a quad core.
Here is some sample code that i put together to simulate the problem which is on a manufacturing production machine.
sub DAQ()
Dim Ctrl, Freq, StartTicks As Long
Dim Mytimerbit As Boolean = False
Do
QueryPerformanceCounter(Ctrl) 'grab the ticks every time we loop
'reset code goes here
If MyReset = True Then
QueryPerformanceCounter(StartTicks) ' get the beginning tick value.
QueryPerformanceFrequency(Freq) ' get the Freq value.
MyReset = False
CaptureIndex = 1
Index2 = 1
Displayme = ""
Summary = ""
Mytimerbit = True
ReDim CaptureData(100000, 15) 'redim should clear it's contents.
End If
'Here i'm trying to schedule the collection to once per millisecond.
If (((Ctrl - StartTicks) / Freq) * 1000) - CaptureData(CaptureIndex - 1, 0) >= 1 Then
Mytimerbit = True
End If
If MyRunBit = True And Mytimerbit = True Then
Mytimerbit = False
CaptureData(CaptureIndex, 0) = CDbl(Format(((Ctrl - StartTicks) / Freq) * 1000, "####.###"))
CaptureData(CaptureIndex, 1) = CaptureIndex
CaptureData(CaptureIndex, 2) = CDbl(Format(CaptureData(CaptureIndex, 0) - CaptureData(CaptureIndex - 1, 0), "####.###")) 'calculates the difference in time between this record and the previous one.
'Save the info in a string to later show on the form.
Displayme = Displayme & CaptureData(CaptureIndex, 0) & vbTab & CaptureData(CaptureIndex, 1) & vbTab & CaptureData(CaptureIndex, 2) & vbCrLf
' this saves the time difference to another string to only list the large time differences later.
If CaptureData(CaptureIndex, 2) > 3.1 Then
Summary = Summary & CaptureData(CaptureIndex, 2) & vbCrLf
End If
'increments the array
CaptureIndex = CaptureIndex + 1
End If
If MyDisplayBit = True Then
Me.Label1.Invoke(New MethodInvoker(AddressOf UpdateDisplay))
MyDisplayBit = False
End If
Loop
End Sub
Private Sub UpdateDisplay()
Me.TextBox1.Text = Displayme
Me.TextBox2.Text = Summary
End Sub
-------------------
The greatest obstacle to discovery is not ignorance -- it is the illusion of knowledge.
Daniel Boorstin