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.
OPEN "com1:1200,E,7,1" AS #1 PRINT "time, sec temperature, ¡C" time0= TIMER FOR J=1 TO 20 PRINT #1," " INPUT#1,A$ time=TIMER-time0 temp= VAL(MID$(A$,6,4)) PRINT time,temp NEXT J
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.
DIM temp(1000) OPEN "com1:1200,E,7,1" AS #1 time0= TIMER N=20 FOR j=1 TO N PRINT #1," " INPUT#1,A$ temp(j)= VAL(MID$(A$,6,4)) NEXT j time=TIMER-time0 PRINT N;" readings in" ;time; "seconds." PRINT N/time;" readings/second." PRINT time/N;" seconds/reading" PRINT "time, sec temperature, ¡C" FOR j=1 TO N time(j)=j*time/N PRINT time(j),temp(j) NEXT j
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).
DIM temp(1000) DIM time(1000) TIMER ON interval=2 OPEN "com1:1200,E,7,1" AS #1 PRINT "Press Q to abort data acquisition." ON TIMER(interval) GOSUB TakeReading j =0 repeat: key$=INKEY$ IF j=20 THEN GOTO done IF key$<>"q" THEN GOTO repeat done: PRINT "time, sec temperature, ¡C" FOR k=1 TO j PRINT time(k), temp(k) NEXT k END TakeReading: PRINT #1," " INPUT#1,A$ j=j+1 time(j)=TIMER temp(j)= VAL(MID$(A$,6,4)) RETURN