How do I measure time spans accurately?

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I have a VB.NET application that executes a test when the user clicks a "Start" button. The application communicates back and forth with a USB device and eventually stops when the USB device sends back a specific trigger, or if the user chooses to cancel
the test. I would like to measure the time elapsed during each test and display it to the screen.
The program is significantly complex and I have several timers that control sampling rate, the frequency of the output, the frequency of signals in a calibration method, etc.
I tried two approaches so far, both of which led to invalid time measurements. I say theyre invalid because I used several stopwatches I know to be accurate in addition to the system clock (the clock with a second hand that pops up when you double click
the time in the bottom right hand corner of Windows XP) to measure the actual time of each test. Consistently, my program will indicate more time has passed than actually has.
<ol>
I tried simply dividing the number of samples I took by the the sampling frequency. I got back a time that was about 1.33 times greater than the actual time. This ratio would change with different frequencies, and even with the same frequency from day to
day. I tried using the DateTimePicker in my main form to measure the time passage. At the start of the test Id record the start time, startTime = DateAndTimePicker1.value, at the end of the test Id record the end time, endTime = DateAndTimePicker1.value, and
then Id set the text of a label equal to their difference, TestDurationLabel.text = (endTime - startTime).ToString. I initialized startTime and endTime as Dates. I get back a time that is about 1.2 times greater than the actual time.
</ol>
Does anyone know a better way to get the elapsed time? Or does anyone know why my second method isnt working? Any help would be greatly appreciated.

View the full article
 
Back
Top