RETURN to the CHEM 498C Home Page

Interfacing Computers to Laboratory Equipment

A. Analog Data acquisition
1. Types of Analog Data Acquisition Systems
It is convenient in dealing with interfacing to distinguish between high-level and low-level inter facing, much as we distinguish between high-level and low-level programming languages. High-level interfacing is employed on "computer-ready" instruments which already have a standard computer interface built in, most commonly an RS-232 or an IEEE-488 interface. Built-in computer interfaces are not available on all instruments, particularly older models. In many cases only a analog voltage output signal may be available, such as might be displayed on a strip-chart or X-Y recorder. In such cases you will have to use a low-level approach, using analog-to-digital converters (ADC) for data acquisition, and digital-to-analog converters (DAC) and digital input/output for control.

A number of data acquisition systems are commercially available for popular microcomputers; these commonly incorporate digital-to-analog conversion, signal conditioning, digital-to-analog conversion and digital input/output in one package. Most of these systems are rather general purpose devices and can be used for a wide range laboratory interfacing projects in spectroscopy, chromatography, electro chemistry, etc. Most vendors supply software for their systems, which varies from rather general-purpose data logging programs, to program language enhancements which allow cus tomers to design their own application software, to stand-alone application programs which support various spectroscopy and chromatography experiments. There are two basic types of data acquisition hardware: add-in boards the plug into to the computer's internal bus and outboard boxes that connect to the computer via a high-level interface port. The former are less expensive but are specific to one computer bus type. Outboard boxes can more easily be moved between different computers.

2. Characteristics of and use of analog-to-digital converters
Many laboratory instrument have a signal voltage output for the purpose of displaying the signal on a strip-chart recorder, X-Y plotter, or oscilloscope. The purpose of an analog-to-digital converter (ADC) is to convert the analog voltage output into a discrete digital representation of that voltage so that the signal can be read by a computer. ADCs are commercially available for most popular brands of microcomputers either as plug-in boards or as part of a outboard data acquisition hard ware system. A typical commercial converter product includes a multiplexer to provide multiple input channels and a variable gain amplifier. The important characteristics include:

a. Resolution, expressed in terms of the number of bits. The most commonly encountered resolu tions and the approximate corresponding reading precisions are 8 bits (1/256), 12 bits (1/4096), 14 bits (~ 1/16000), and 16 bits (~ 1/65000). Higher resolution gives better precision and greater dynamic range but are more costly. Generally, 12 bits is considered adequate for most laboratory work. A 12 bit ADC with a 0 to 10 volt range would be able to read voltages to the nearest 0.0024 volts. This means a signal near full-scale (10 volts) could be read to a relative precision of 1 part in 4096, but a signal at one-tenth of full-scale (1 volt) could be read only to a precision of 1 part in 410, and a signal at one-hundredth full-scale (0.1 volt) could be read only to a precision of 1 part in 41.

b. Speed, expressed as the conversion time in u sec or msec, determines the maximum number or read ings that may be taken per second, although in most cases the speed of execution of the software is the limiting factor. Typical conversion times range from a few u sec to several msec.

c. Conversion method. Successive-approximation ADCs are the most common. Integrating (dual-slope) types are typically much slower, but exhibit better noise rejection, especially of 60 Hz line noise. Flash converters are the fastest (100's of MHz/sec) but are expensive and are not available in the higher resolutions.

d. Coding. Coding refers to the way the input voltage is converted into a binary number. Most ADCs output an integer number between 0 and 2n-1, where n is the number of bits (resolution) of the ADC. The simplest coding is straight binary (monopolar). For example, a 12 bit ADC with a 0 to 10 volt range and straight binary polar coding would give the following output:

input volts output number
0.0 0
0.00244 1
1.0 410
10.0 4095

Voltages outside of the nominal voltage range can not be measured. Input voltages below zero simply give an output of zero, and input voltages above 10 volts give an output of 4095, usually without warning. Therefore you can't trust a reading of zero or of full-scale. If you need to be able to read both positive and negative voltages, you need a bi-polar range, e.g. +/- 5 volts or +/- 10 volts. In this case pay close attention to the way the ADC converts voltages to numbers, which can vary from one model of ADC to another. Consult the manual for details.

e. Number of input channels. Most commercial ADC`s have 8 or 16 input channels which can be connected to different signal sources. They can actually read only one at a time, but switching from one input to another can be done very quickly so as to give the effect of monitoring several signals simultaneously. The channels can be selected under software control. Some ADCs have an auto-scanning mode in which the hardware cycles through all the channels automatically.

f. Input sensitivity refers to the input signal voltage which gives a full-scale response on the ADC. Ideally this should be able to be changed by the user in order to accommodate different instrument output voltages. Some ADC`s set the input sensitivity by means of hardware jumpers or switches, but it is more convenient if the input sensitivity is software programmable. That way, the software can be written to switch ranges automatically as needed to handle large changes in input voltage level. If you want to measure a larger voltage than the range of the ADC (e.g. to read 0 - 1000 volts with a 0 - 10 volt converter), you must add a voltage divider before the input. If you want to measure a smaller voltage than the range of the ADC (e.g. to read 0 - 0.1 volts with a 0 - 10 volt converter), it's best to add an amplifier before the input, in order to make best use of the resolution of the ADC.

Here are some simple operational amplifier circuits that can be useful for pre-amplifying a signal to make it compatible with an ADC input voltage range. Suitable operational amplifiers can be bought as integrated circuit chips for $1.00 to $5.00 from any electronics store or catalog (even Radio Shack). Use better quality (more expensive) units for very low input signal voltages (10 mV or below). They require an external power supply or batteries to operate. In each case the input would come from a transducer or instrument and the output would go to a ADC input.

Non-inverting amplifier. The gain is (R1+R2) / R1, i.e., Eout = Ein(R1+R2) / R1

Inverting amplifier. The gain is - R2 / R1, i.e., Eout = - EinR2 / R1

Current-to-voltage converter, often used to convert the signal current from a phototube or amperometric cell into a readable voltage. Eout = - IinRf . Often Rf is very large (1 M[[Omega]] to 1000 M[[Omega]] ) so that a very small input current gives a readable output voltage.

These circuits can also serve as simple low-pass ("anti-aliasing") filters if you put a capacitor across (in parallel with) R2 or Rf . The cut-off frequency is 1/2[[pi]] RC.

g. Programming. You can write your own data acquisition routines in any language you like such as assembly (fastest), BASIC, C, Pascal, etc. Most commercial ADCs come with software examples and data acquisition subroutines in one or more popular languages. Writing your own data acquisition routines to access the hardware directly directly is the most flexible approach, but requires that you handle some details yourself. For example, you need to know how to start a conversion (using the the strobe bit) and to determine when the converter is finished with a conversion and can be read (by reading the end-of-conversion or busy bit). The ADC's instruc tion manual will have the details. In most cases the data acquisition is controlled point-by-point into RAM, and then saved to disk as a separate operation. Obviously in this case the maximum number of data points that can be taken without interruption is limited by free RAM available for data. For a 10 - 16 bit converter, each data point will take 2 bytes, so for each 1000 bytes (1 KBytes) of available RAM you will be able to store 500 readings. So if your PC has 200K of RAM available, you have enough space for 100,000 readings. Software supplied with some ADCs includes advanced capabilities such as data streaming to disk, which allows continuous uninterrupted data acquisition of more data points than can be held in memory, and support for direct memory access (DMA), in which whole blocks of data are acquired and transferred to memory directly to RAM for very high-speed data acquisition.

h. Control of the sampling rate. The sampling rate, i.e. how many ADC conversions are made per second, is important if the signal is changing. (If the signal is steady-state, i.e. a DC voltage, such as from an ion-selective electrode in a fixed solution, then a single reading is enough ideally, although multiple DC readings can be taken and averaged to reduce the influence of random noise). For changing signals (chromatograms, spectra), it is important to take data fast enough to define the signal adequately. The greater the number of points per peak, the more accurately you will be able to measure peak position, height, and width, but of course the more memory will be required to store the raw data. As a rough rule of thumb, for a signal consisting of more-or-less symmetrical (e.g. Gaussian) peaks, 10 to 20 points per peak is enough. (Measuring peak area requires fewer points than measuring peak height). The sampling rate is controlled by either the computer's or the ADC board's "real-time clock". The details vary from system to system, but most computer languages have commands for reading the computer's clock (e.g. QuickBASICs TIMER function). If neither the ADC board nor the computer has a clock, then you are reduced to writing timing loops in software (i.e. do-nothing loops whose purpose is simply to take time) to control the speed of sampling.

3. Characteristics of and use of digital-to-analog converters
In some cases it is desired to have the computer generate a variable output voltage which can be used to control some part of the experiment. This can be done with a digital-to-analog converter (DAC). These are basically the reverse of ADCs and, like ADCs, come in various resolutions. They are usually faster and cheaper that ADCs of the same resolution, and are available from the same companies that make ADCs. (Even 16-bit DACs are relatively inexpensive, but 16-bit ADCs are fairly expensive). Programming is simpler than for ADCs; there is no strobe or EOC to worry about. The output of a DAC is usually a voltage that varies over a specified range (e.g. 0 to 10 volts, or -10 to +10 volts, etc) depending on the number sent to the DAC. A 12 bit DAC with a range of 0 to 10 volts will allow you to set the voltage to the nearest 10/4096 = 2.4 mV. You will have to add a voltage divider to the output if you want a smaller steps over a smaller voltage range. Or you will have to add an amplifier to the output if you want the output to cover a larger range than the DAC itself or if you need to supply a significant current.

B. Digital interfacing (on-off control)
Parallel digital inputs and outputs are commonly available on computers, either built-in or as an optional card. Each wire of a parallel interface carries a binary (off/on) signal which can be used individually to control or sense an event which is naturally off/on in nature. Most commonly these utilize so-called "TTL" levels, meaning that they take off to be a low voltage (typically between 0 and 0.2 volts) and on to be a voltage between 3 and 5 volts. If required, the off/on sense can be reversed with a very simple logic circuit element called an inverter.

A common requirement in automating equipment is to have the computer activate a switch or pushbutton on an instrument. Figure 2 shows a few approaches which can be used. First, use a voltmeter or oscilloscope to determine the voltage between each terminal of the switch and ground. If one end of the switch is grounded and the other end is positive with respect to ground by no more than 50 volts when the switch is open, then you can use a simple NPN transistor as shown. Just about any NPN silicon transistor will work. Be sure the connect the grounds of the instrument and the computer together. A more general solution, which will work under more circumstances, involves the use of a relay. Relays which operate directly from TTL voltage levels are available, or a transistor switch can be used to drive a 12 or 24 volt relay, as shown at the bottom of Figure 2. However, a relay is slower and less reliable than a transistor switch; like any mechanical device with moving parts, it will eventually wear out.

To get the computer to turn off an on 115 volt AC power to some device (e.g. hotplate or heating mantle), you can't use a simple transistor switch. You could use a heavy-duty relay, one whose contacts are rated for the voltage and current of the controlled device. But the best way is to buy an electronic power controller or "solid state relay", a commercially available module that allows a TTL signal to control a 115 volt AC power connection without moving parts.

To generate a TTL output from a computer to control a transistor switch, relay, or power controller, you need to have a parallel output port. Some computers have such a port built-in, and most commercial ADC cards have one or more parallel output ports.

C. RS-232 serial interfacing
"Computer-ready" instruments most commonly use the RS-232 serial interface. In such cases the actual interfacing often involves nothing more that obtaining the proper cable with suitable connectors and an interface card for the computer. Almost all computers have a built-in RS-232 port, which was intended originally intended to be used to interface a printer or a modem.

1. Hardware. The most common type of connector used for RS-232 interfacing is the DB-25 connector, but the DB-9 and the round DIN connectors are also widely used. The pin assign ments of the DB-25 are well standardized: pin 7 is ground, the actual serial data are carried on pins 2 and 3, and the other pins are "handshaking" lines that may or not be used on any one particular piece of equipment. There are two classes of RS-232 devices: DTE ("data terminal equipment") and DCE ("data terminal equipment "), which differ in the assignments for pins 2 and 3. A DTE transmits data on pin 2 and receives data on pin 3, whereas a DCE transmits data on pin 3 and receives data on pin 2. Thus a DTE and a DCE can be connected up directly with a "straight" cable that connects pin n on one end to pin n on the other end and it will work. However to connect two devices of the same class, i.e., a DTE to a DTE or a DCE to a DCE, you need to switch pints 2 and 3. This can be done with a so-called "null modem" cable or adaptor or in some cases by flipping a switch or moving a jumper on one of the devices to change it into the other class. To troubleshoot all this, it's useful to have a "breakout box", a small gadget with an RS-232 connector that brings out the lines to external terminals so you can more easily check for voltages and waveforms on the lines. Also, there is the matter of connector "sex", i.e. male or female: if you're lucky, things will mate, but you may need to use a so-called "sex changer" adaptor to convert male connector to female or vice versa. All these things are available from computer and electronics catalogs and stores.

2. The ASCII code. Information transmitted via an RS-232 interface can either be text or binary. Text data are almost universally represented by the The (American Standard Code for Information Interchange) code, which assigns a 7-bit binary number to each character of the Roman alphabet, including numerals and some punctuation. It's important to realize that there also ASCII codes for non-printing "characters" that don't make a mark on your terminal screen or printer but can be very important. These include the space, carriage return, line feed, tab, escape (esc), and many others. See the ASCII code chart on another page. Normal ASCII has only 128 distinct characters (27 = 128), but sometimes you will encounter extended ASCII codes that use 8 bits (256 characters) to introduce additional characters (European language characters, for example).

3. Communications parameter settings. For RS-232 communication to work, both sides have to agree on a number of essential communications parameter settings, the most important of which is the baud, or bit rate, that is the number of bits per second. Standard bit rates are 300, 1200, 2400, 4800, 9600, and 19,200 bits per second. Some devices have a fixed bit rate; others allow selection of one of several bit rates. If you have the choice, make the bit rate as fast as possible while still achieving reliable communication. The other bit-level parameters are: the number of data bits (7 or 8) , the number of stop bits (usually 1 or 2) and parity (None, Odd, or Even).

4. RS-232 diagnostics with an oscilloscope. There are quite a number of ways that RS-232 can be set up, both with respect to the wiring of the cable and connectors (especially the "handshaking lines") and with respect to the baud rate, parity, and number of data and stop bits. If you are dealing with poorly documented equipment, sometimes the only alternative is to use an oscilloscope to look at the waveforms on the pins of the RS-232 connector of the device in question. From this you can determine which pin is sending data and which of the handshaking pins are low and which are high, and you can determine the bit rate and the other communi cations parameters.

5. Communications Software Services. Once you have the correct cable and connector hooked up between an instrument and a computer, you can test a interface easily by running a "terminal program" on the computer. A terminal program allows direct manual control of the serial port. It gives you a convenient way to change the computer's bit rate, number of data bits and stop bits, parity, and other parameters. Anything typed on the keyboard is sent out through the serial port and all characters received through the serial port are displayed on the screen. Thus you can easily try different parameters until things seem to work. In some cases, a terminal program may be all you need to acquire data from an instrument and you won't have to write a custom data acquisition program. All terminal programs have the ability to capture incoming text to disk and to send text files from disk. You could send a set of pre-written commands to the instru ment in one operation and then capture its output as a text file on disk for reading into another program, such as a spreadsheet or plotting program. Often it will be necessary to edit the text file to put it into a format suitable for other programs. You could do that with any text editor or word processor, but it may be easier to write a custom program to handle the data capture and re-formatting in one operation. Some terminal programs have a "character translation table" that automatically substitutes all occurances of one character for another character in an incoming stream of text; this can often be used to reformat data by removing or substituting offending characters.

6. Programming the serial port. The RS-232 interface is character-oriented, meaning that programming is simply a matter of sending and receiving alphanumeric characters. Thus, sending a command to the instrument through the interface is like sending output to a printer, which is also a character-oriented device. For example, you would simply execute a PRINT or OUTPUT in BASIC or a Writeln in Pascal. Similarly, getting input from the instrument through the interface is like getting input from the keyboard; you would execute and INPUT or ENTER command in BASIC or a Readln in Pascal. All high-level languages support character-oriented input and output, although the details naturally depend on the system; in particular there has to be some way to distinguish which port you are communicating with.

7. Instrument commands. How do you know what commands to send to the instrument? This depends only on the instrument itself and must be found in the manufacturer's documentation. For example, the Shimadzu model 250 u.v.-vis spectrophotometer recognizes a large set of simple alphanumeric commands, a sub-set of which is listed here:

Shimadzu spectrophotometer commands
W 	Set wavelength
S	Set slit width
D	Read absorbance
V	Set mode
J	Set scan speed
A 	Begin scan
H	Set start wavelength
I	Set end wavelength

For example, to set the spectrophotometer to a wavelength of 500 nm, you send the characters "W500". To set the slit width to 1 nm you would send "S1". To read the absorbance, you send the letter "D" and then read the input as a string.

The format of the output data send by the instrument to its RS-232 port also varies widely from instrument to instrument and has to be handled on a case-by-case basis. In most cases numerical data are send as decimal ASCII strings, which can be read directly by many programs. For example, an absorbance of 0.232 would be sent as the ASCII characters "0", ".", "2", "3", and "2", usually followed by a carriage return (and possibly a line feed character also). Sometimes the numeric data are accompanied by alphabetic characters, e.g. "A=0.232", which have to be removed in order to convert the data into a valid numeric variable. This can be done by reading the data into a string variable initially, then stripping the offending characters using the string manipulation commands of the language, and finally converting into a numeric variable.

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