Timing Data Acquisition in QuickBASIC

The built-in QuickBASIC functions TIMER and ON TIMER can be used to measure time
in data acquisition applications. The TIMER function is a real number
function
that returns the number of seconds since midnight. Here are some examples using the Protek
digital multimeter with RS-232 interface as an example.

1. This program prints out a table of 20 time and temperature readings, with the
elapsed time (seconds since the beginning of the run) in the first column and
temperature (read from the Protek multimeter via the RS-232 port) in the second column.
The variable time0 is set to the initial value of TIMER before the data acquisition
loop. Then, for each measurement read in the data acquisition loop, the elapsed time
in seconds is calculated by subtracting the initial time0 from the current value of
TIMER and assigning to the variable time. The precision of the times is limited by the
resolution of TIMER, so if the meter makes readings faster than the resolution of
TIMER, two or more adjacent readings might have the same time label.

2. This program produces a table much like the first program, except that in this case
the N temperature readings are stored in an array as they are being measured (rather
than being printed out immediately). (The number of readings N can be as large as
1000, limited here by the DIM statement). The elapsed time for the group of N readings
is calculated using the same technique as above; that is, the variable time represents
the time for N readings. Then the number of readings per second is calculated by
dividing time/N. Finally, the time, temperature table is printed out, with times for
each measurement calculated by assuming that the readings are equally spaced in time (a
good assumption). This is a better technique for higher-speed measurements, because
the data acquisition loop is not slowed down by printing to the screen and because the
calculated timing resolution is improved to 1/N of the resolution of the TIMER
function.

3. This program also produces a table like the above programs, except that in this
case the variable interva controls the time interval between readings to a
pre-determined value, which can be 1, 2, 3, or any number of seconds (but not less than
1 second). This is done by using the ON TIMER(interval) GOSUB TakeReading statement. When the
program gets to this statement, it sets up a timed interrupt condition for the
remainder of the program. This has no immediate effect; the program goes on to execute
the following lines. But once each interval seconds (every 2 seconds in the example),
the program interrupts whatever it is doing and jumps to the TakeReading subroutine,
which takes one time-temperature reading and stores the results in arrays before
returning to where it left off. Between executions of this subroutine, the program
spends its time in the line labeled "repeat" and the two following IF statements. The
purpose of these lines is to stop the program when 20 readings have been taken or when
the user presses the "q" key (to Quit data acquisition). When either of these happen,
the program goes to the line labeled "done", which prints out the table of data and ends
the program. Note the use of the INKEY$ statement to read the keyboard "on the fly" to
detect when the user press "q". Also, note that an END statement is required to
separate the end of the main program from the subroutine(s).

This page is maintained by Tom O'Haver
, Department of Chemistry and
Biochemistry, The University of Maryland at College Park.
Comments, suggestions and questions should be directed to
Prof. O'Haver at to2@umail.umd.edu.