QL Data Interface 4

See all articles from QZX v7 n8
Author(s): Alex Burr (K5XY)
Publication: QZX
Pub Details: QZX v7 n8 (Volume 7, Issue 8)
Date: July 1989
Pages: 6-8

This article is a continuation of the articles, QL Data Interface 1,2, and 3 from past issues, about the Prairie Digital Data Acquisition System for the QL. This is the last article in the series. All the hardware features have been covered in previous articles, including the one last month which reported on the actual use of the board. This article will mention some programing possibilities.

The analog to digital converter (ADC) requires a very specific control sequence in order to complete and write out a conversion. Below is a BASIC program which performs all of the necessary I/O instructions to take a reading of the voltage at channel 0. (This is pin 21A of the user connector.) If you look at the schematic from one of the previous articles, you will see that channel 0 os connected to the ADC chip input because lines A, B, and C of the multiplexor (MUX) are grounded. BASIC performs all the required steps at approximately three conversions per second. For faster reading rates, the equivalent routine could be compiled or written in assembler.

Simple BASIC ADC program

100  CLS
110 POKE 81923,131 :REMark set up I/O port, A=out, B=in,
C-low=in, C-hi=out.
120 POKE 81922,192 :REmark chip select high, clk high
170 R = 0
180 POKE 81922,64 :REMark clk high
190 FOR J = 7 TO 0 STEP -1
200 R = R + ((PEEK (81922)&&8)/8)*2^J :REMark read port C, mask
D0-D6 construct reading
210 POKE 81922,0 :REMark clk low
220 POKE 81922,64 :REMark clk high
230 NEXT J
240 PRINT INT((R*500/256))/100 REMark convert to voltage
250 GOTO 170

In the above program, line 100 just clears the screen of whatever was on it before the ADC program was run. Line 110 sets up the computer to control the ADC card and to read the digital value that it measures. The number poked into memory location 81923 sets up the port as shown in the REMark according to the scheme detailed in a previous article. Line 120 initializes the ADC chip. The ADC chip reads its measurment out serially one bit at a time according to the signal on the clk input. Line 170 initializes the voltage reading to zero. Line 180 insures that the clk line is high here. Line 190 sets up the loop which clocks the voltage reading out of the ADC one bit at a time. Line 200 is a key line. It builds up the voltage reading bit by bit. Here it first reads port C. The reading is then “anded” with 8 to mask off bits 0 to 6. The result is then divided by 8 which will only leave a 1 or a 0. This is then properly weighted by multiplying by 2 raised to the power of J and finally added to the previous value of R to get a value for the voltage. Lines 210 and 220 clock the next bit out for use in line 200. Line 230 ends the loop, with R containing a number proportional to the decimal equivalent of the voltage on the input to the ADC card. One of the tasks of line 240 is to take R and convert it to units of voltage. The 500 in the line represents the highest voltage which the ADC chip will accept (5.00). The 256 represents the 256 different values that this 8 bit chip can assign the measured voltage. The 100 just sets the decimal point. Then the line prints the answer in very unadorned fashion. On the empty screen the number appears in the upper left corner and subsequent readings are printed on the line below at the rate of about three readings per second. When the line of numbers reaches the bottom of the screen, the old numbers start scrolling off the top as new readings are put in the lower left corner.

This program just reads the voltage on one of the eight possible input lines. A few additional program lines will permit as many of the other seven input lines as you wish to be read in turn. To read the voltage applied to the other channels, all that is needed is to add the necessary MUX program statements and configure the user connector. The MUX inputs (A0, A1, ans A2) are not connected internally on the printed circuit board in order to leave the user the most flexibility. In the example below the MUX inputs A0, A1, and A2 are tied to PA0, PA1, and PA2 on the user connector to receive signals from the computer as commanded by the lines in the programming addition shown below. These additional lines replace original lines or add to the original program.

Additions to the simple program

130  POKE 81922,0:  POKE 81922,64
140 FOR CHANNEL = 0 TO 7
150 POKE 81920,CHANNEL: REMark set up the MUX
160 FOR Z = 0 TO 7: POKE 81922,0: POKE 81922,64: NEXT Z

240 AT CHANNEL * 2,16: PRINT " VOLTS"
250 AT 2 * CHANNEL,5: PRINT "CHANNEL ";CHANNEL;" = "; INT ((R *
500/256))/100
260 NEXT CHANNEL
270 GOTO 140

(Adjust CHANNEL and Z as required.) Note that the more channels which are read, the longer the time between readings of a given channel. Also note that the PRINT statements are a little more complicated to provide labels for the voltage readings. Of course, the labels could be made more meaningful for your particular application.

Many more complicated programs could be written. The data could even be graphed. The first useful addition that comes to mind is a program which would print the voltage reading in large numbers in the center of the screen. One would then have a very nice demonstration voltmeter.

If any reader creates a more sophisticated program, QZX would be glad to hear of it.

The final product can be used wherever a voltmeter is used, (Perhaps with an appropriate voltage divider to keep the input less than 5 volts. If an attenuator is used, changing the 500 in line 240 will cause the ADC card to give the answer in terms of the unattenuated input. The end result could be used as an S meter, FM receiver deviation meter, line voltage monitor, or even a monitor of the QL power supply. Write up your use and share it with other QZX readers.