MICROCONTROLLERS IN THE LABORATORY
Ron Williams Department of Chemistry Hunter Laboratory Clemson University Clemson, SC 29634
The personal computer is now ubiquitous in modern chemical laboratories and has produced a small revolution in data handling and acquisition. Because there are many more people interested in word processing than in computer interfacing, however, the few software and hardware packages designed specifically for data acquisition are expensive and made for skilled users. In general, automating laboratory experiments and equipment involves a variety of confusing and expensive steps. A personal computer must be selected from the many brands available. A variety of software products must be purchased for data processing, word processing, graphics, and other functions. A compatible interfacing board with appropriate analog-to-digital converters, digital input/output (I/O), counters, and timers must be purchased and installed. Finally, the experiment must be connected to the computer through the interfacing board, and control software must be written. Learning to interface computers can be expensive, time-consuming, and frustrating, particularly for chemists with a limited background in electronics. Fortunately, experts in the electronics industry often produce easy-to-use devices to expand their markets. For example, the development of integrated circuits resulted in easy-to-use, high-gain, inexpensive operational amplifiers in the late 1950s and early 1960s, making it possible for scientists with only moderate experience in electronics to build sophisticated and useful circuits on their own. Similar developments have recently occurred in small computers. A separate class of computers known as microcontrollers has been created specifically to ease the problem of interfacing. Just as the operational amplifier integrates many discrete components into an easy-to-use amplifier, the microcontroller integrates many common inter0003-2700/89/0361-433A/$01.50/0 © 1989 American Chemical Society
facing peripherals into a usable data acquisition system. The microcontroller, just like the operational amplifier, is inexpensive and designed to be used by people with little training in electronics. This A/c INTERFACE will describe how microcontrollers work and how they can be used in the analytical laboratory. The microcontroller Commercially, microcontrollers provide the intelligence of "smart" consumer products such as microwave ovens, autofocus cameras, video games, and complex office copiers. The automotive industry uses microcontrollers
the forefather of these devices, the calculator is a good example. A calculator is a single integrated circuit that accepts commands from a keyboard, performs a variety of functions in response to this input (multiplication, division, sines, logs, etc.), and displays the result on an output device. The calculator chip contains all of the interfacing peripherals necessary to perform these functions. These on-chip peripherals distinguish the microcontroller from the microprocessor and make it ideal for laboratory applications. Microprocessors require external memory, control circuitry, a monitor program, and a serial
A/C INTERFACE for continuously tuning engines and antiskid braking systems. Because of the large consumer demand for microcontrollers, they are manufactured in quantity, which translates into reduced costs. Microcontrollers are descendents of circuits designed for hand-held calculators. A microcontroller, as the name implies, is simply a computational device designed to control something. As
interface as a bare minimum (1). The microcontroller, on the other hand, is a stand-alone, preinterfaced computer that has its own analog-to-digital converter (ADC). It bears a striking resemblance to the original laboratory computer built from discrete components by Parker and Pardue in 1972 just prior to the introduction of the microprocessor (2). A simplified block diagram of the
ANALYTICAL CHEMISTRY, VOL. 61, NO. 6, MARCH 15, 1989 · 433 A
A/C
INTERFACE
Figure 1. Block diagram of the Motorola MC68HC11 microcontroller.
Motorola MC68HC11 (Figure 1) illus trates the wide range of peripherals available on a modern microcontroller. The core of this device is a central pro cessing unit (CPU) that executes a su perset of Motorola 6800/6801 instruc tions. A set of five ports provides a full complement of interfacing peripherals. Ports A-D are multifunctional digital I/O ports; port Ε functions simulta neously as a multiplexed ADC and a digital input port. Two serial inter faces, as well as three types of memory and several other useful interfacing cir cuits, are provided on a chip the size of a postage stamp. The digital I/O on the MC68HC11 provides enough versatility to allow the designer to directly connect a wide va riety of devices to the microcontroller without ancillary electronics. The bits in ports C and D can be programmed as either inputs or outputs (in any combi nation), whereas the other ports have fixed directions. Some of these pins are tri-state, open collector, or transistortransistor logic compatible. Other mi crocontrollers, such as the Intel 8096, have Schmitt triggered inputs. The timing for the I/O pins on the MC68HC11 is very flexible, and several forms of strobed handshaking are pro vided. For example, port Β can talk di rectly to an Epson-compatible printer using strobed handshaking lines from port D. More advanced types of digital I/O are available on port A. Pulse-counting and period measurements can be made using bit 7 of port A. Two special types of I/O are also provided by this port: input captures and output compares. These are convenient ways to record the times at which digital signals change state, and, conversely, to force output pins on port A to change state at
programmable intervals. Along these same lines, the 8096 provides pulse width modulation to allow direct con trol of dc motors. Microcontrollers are available with different types and amounts of on-chip memories. The MC68HC11 has 8 Κ of monitor ROM that comes prepro grammed with a generic assembler/dis assembler or with a Forth development language. For large customers, Motor ola will program this ROM with userdeveloped programs. In addition, 256 bytes of internal static RAM are in cluded, but only about 80 bytes are available for user-written programs. Only a small amount of RAM is provid ed because microcontrollers usually compute transient quantities; they are not designed to be word processors. The most unusual type of memory available is electrically erasable pro grammable read-only memory (EE PROM), which can be used for data and programs. This type of memory can be thought of as RAM that retains its information even when power is re moved from the microcontroller (for up to 10 years) and is designed to hold small programs and data such as cali bration constants. Because both RAM and EEPROM can be modified easily, the system can be programmed to adapt automatically to changing condi tions. Two serial ports are provided to al low the microcontroller to communi cate easily with other computer sys tems: a serial communication interface, which is an RS 232-type interface for communicating with terminals or other computer systems, and a serial periph eral interface, which is designed for the relatively fast (1 MHz) serial commu nication between other MC68HC11 microcontrollers or compatible peri
434 A · ANALYTICAL CHEMISTRY, VOL. 61, NO. 6, MARCH 15, 1989
pherals. Special sleep modes are pro vided for both serial interfaces to sim plify networking. The microcontroller's unique fea ture, from a chemist's point of view, is the on-chip ADC. The MC68HC11 has an 8-channel multiplexed 8-bit succes sive approximation ADC with a sample-and-hold amplifier that requires 16 μβ for conversion. The ADC is ratiometric, which means reference voltages for 0 and 255 V are supplied by the user; these voltages can be changed dy namically to increase the range of the ADC to 9 bits. The Intel 8096 has a 10bit ADC, and the National Semicon ductor COP888CF uses a prescaler to extend the range of its 8-bit ADC up to 16 times. These systems have limited resolution because they are designed to operate in noisy environments where signal-to-noise ratios rarely exceed 256. When quantization noise does not dominate, the precision of the ADC can be effectively extended by signal aver aging. Because they are designed for hostile environments, microcontrollers have special circuitry to halt runaway pro grams. When operating, the user's pro gram must perform periodic house keeping functions or a special timer is sues a reset. This means that a runaway program, caused for instance by a large noise pulse, can be controlled. Similar ly, if the CPU attempts to execute a "nonsense" instruction, a reset is auto matically initiated. Other attractive features include complementary metal oxide semicon ductor fabrication to allow battery op eration and noise immunity as well as special low-power operating modes to further reduce current drain. All of the peripherals can be shut down easily when not in use, and even the system clock can be stopped for extended amounts of time with no loss of data or programs. The microcontroller can be awakened by one of 20 possible inter rupts, including the presence of data at the serial port. Because modern control theory re quires sophisticated computations, machine language multiply and divide instructions are provided. The MC68HC11 has a special fractional di vide that does fast (40 μβ) floating point divisions on integer numbers with about 5 digits of precision. (This same divide instruction is used by Mac intosh computers for fast computa tions of screen graphics.) A functioning microcontroller sys tem requires only external RS 232 volt age converters (such as the MC1488/89 pair) and a crystal oscillator. However, a system capable of developing soft ware for complex applications must in-
A/C
INTERFACE
elude external memory; an external ROM that allows the use of operating systems other than that provided by the internal ROM is also useful. These features are provided by evaluation boards (EVBs) that can be obtained at attractive prices. The MC68HC11, for example, comes on an EVB with an ex ternal monitor ROM, 8 Κ of static RAM with a socket for another 8 K, and RS 232 voltage converters. All that is required to operate the EVB is a power supply and a RS 232 terminal. A third-party vendor (New Micros, Dal las, TX) markets a single-board com puter with an MC68HC11 with Forth as its internal monitor and supplies Forth ROMs for the Motorola EVB at attractive prices. An astounding set of free software is provided by Motorola for its EVB products via an electronic bulletin board service. Anyone can dial in and get updated versions of the monitor software or an alternate BASIC moni tor for the external ROM. Cross-com pilers for either IBM or Macintosh computers are available, and the caller can post technical and marketing ques tions. Software written by other MC68HC11 users such as fast Fourier transforms and floating-point pack ages also are provided. All of these items are available 24 hours per day and cost only the price of a phone call. Similar bulletin boards are provided by other manufacturers.
and warn of impending failure. Second, the EEPROM allows for adaptation of the interface. The programs stored on chip can evolve as sensors age or envi ronments change. Third, the microcon troller's computational abilities and high speed allow for real-time process ing of signals (e.g., Kalman filtering), and, more importantly, real-time con trol of the experiment. The microcontroller also relaxes hardware constraints on interfacing. Because any RS 232 device can com municate with the microcontroller, the link between the personal computer and the experiment is severed; thus, PCs and interfaces can operate and evolve independently of one another. Troubleshooting becomes almost trivial with microcontroller interfaces because of the small number of chips used in the interface. A new microcon troller costs only $27, so chip swapping is not only feasible but also quick and inexpensive. Time and money are saved, and frustration is avoided. This is one of the most important aspects of microcontroller interfacing. Because the microcontroller is inti mately tied to the experiment and in fact becomes a part of it, two types of software must be written. The first is the actual control program for the ex periment, which is written on the mi crocontroller or, more often, crosscompiled on a PC and downloaded to the microcontroller. This software is
designed to execute commands sent from the host (i.e., the host sends com mands to the microcontroller to per form specific functions). Software must also be written for the host; this software must only know the proper set of commands to initiate any particular experiment and how to accept the data. The combination of these two types of software is the basis of object-orient ed programming, and, by extension, ar tificial intelligence (3), where the host knows what it wants done (e.g., read a photodiode array) but does not know how to do it. The microcontroller, on the other hand, knows how to read the diode array and does so when asked by the host. The host can ask for raw data, or the microcontroller can preprocess the data to provide information to the host instead. This is a true concurrent multipro cessor system; once the host issues a command, it is free to go about its busi ness. The microcontroller receives the command, performs the desired func tion, and then notifies the host when the experiment is complete. Microcontroller applications
Because microcontrollers are relatively new and are used mainly in the con sumer market, very few applications have appeared in the scientific litera ture. A microcontroller interfaced to a semiconductor gas sensor is presented in Figure 2. This microcontroller re-
Advantages of microcontrollers
Interfaces using microcontrollers are fundamentally different from their tra ditional counterparts. An interface is normally viewed as a buffer that trans lates signals between computer and ex periment; it is required because the digital computer is inherently incom patible with the analog world. With the microcontroller that is no longer true. Analog, frequency, and digital infor mation can be directly connected to and processed by the microcontroller. In effect, the interfacing has already been done; the user simply connects the microcontroller to the experiment using the necessary digital and analog lines. The microcontroller becomes a part of the experiment itself. With mi crocontroller-based interfacing, every experiment can now have its own dedi cated, full-time computer. This brings three new dimensions to interfacing. First, the microcontroller provides redundancy. With an 8-channel ADC and 24 other digital I/O sig nals dedicated to a single experiment, many previously unmonitored signals can be continually recorded. For exam ple, the microcontroller can monitor power supplies used by the experiment
Figure 2. Experimental interface used to control tin oxide gas sensor.
436 A · ANALYTICAL CHEMISTRY, VOL. 61, NO. 6, MARCH 15, 1989
gram and then signal averages at that point until a constant standard devi ation is obtained. The interferograms resulting from this algorithm are indis tinguishable from the detector noiselimited signals usually acquired only in the infrared regions. A promising future
The future of the microcontroller in analytical chemistry is very bright. Several devices with very high speeds (30 MHz) and on-chip floating point processors already have been devel oped. There is a continuing trend to longer word lengths with 16-bit sys tems currently available and 32-bit sys tems promised. The capabilities of fu ture microcontrollers seem destined to solve the most difficult interfacing problems of chemists in particular and scientists in general. References
Figure 3. Diagram of Hamamatsu diode array interface using a microcontroller.
quires only an 8-MHz crystal, RS 232 bus driver/receivers, and a low-fre quency reset switch. The total cost is less than $30. The gas sensor, whose resistivity is a function both of temperature and the concentration of specific classes of gas es, is heated with current from a 6-V regulator. The current through the reg ulator is controlled by the MC68HC11 through a 2N2219 transistor used as an on/off switch, providing temperature modulation of a semiconductor gas sensor (4). Because sensor response varies characteristically with tempera ture, this provides a means of quantitating and identifying gases simulta neously. The temperature of the sensor is monitored using an iron-constantan thermocouple. This interface can sup ply data in a number of useful manners simultaneously (e.g., instantaneous, in tegrated, and maximum concentra tions). Arymanya-Mugishaetal. (5) demon strated a microcontrolled source for atomic emission spectrometry based on the microarc as presented by Layman and Hieftje (6) with computer control of gas flows, microarc current flow, data acquisition and preprocessing, and sample injection timing. An MC68HC11 microcontroller regulates gas flows and microarc current with in expensive digital relays. The analyte signal is isolated by a monochromator, detected by a photomultiplier tube, and monitored using one channel of the ADC. A reference signal is also sup
plied to a separate channel of the ADC by using a photodiode to record the total emission signal (consisting mainly of helium lines). The two signals are digitized, multiplied together, and lowpass-filtered by the microcontroller. The microcontroller functions as a flexible lock-in amplifier with a total of eight input channels. In another application, Li and Wil liams (7) developed a microcontrollerbased photodiode array interface. The microcontroller provides all necessary timing signals to a Hamamatsu 512 ele ment photodiode array and digitizes the output voltages (see Figure 3). Not only is the diode array interface decou pled from the host computer by the microcontroller, but the ADC is also decoupled from the interface's clock. The clock is operated at the maximum rate allowed by the diode array (250 KHz) and stopped during conversion. The interface can therefore skip diodes at will in many complex fashions with a concomitant increase in data acquisi tion speed. Up to 16 complete scans can be acquired consecutively with memo ry available on the EVB. Microcontrollers can also be used to solve a traditionally intractable prob lem in interferometry (8). Shot noise, which is related to signal intensity, is particularly damaging in Fourier trans form spectroscopy. A process known as self-adaptive filtering has been devel oped in which the microcontroller esti mates the intensity of the shot noise at each sampled point in the interfero-
(1) Dessy, R. E.; Vuuren, P. J.; Titus, J. A. Anal. Chem. 1974,46, 917 A. (2) Parker, R. Α.; Pardue, H. C. Anal. Chem. 1972,44,1622. (3) Winston, P. H.; Horn, B.K.P. Lisp, 2nd éd.; Addison-Wesley Publishing: Reading, MA, 1984. (4) Shellman, R. L.; Williams, R. R. Scientific Computing and Automation, in press. (5) Arymanya-Mugisha, H.; Green, R. B.; Williams, R. R. Anal. Chem. 1988,60,891. (6) Layman, A. T.; Hieftje, G. M. Anal. Chem. 1975,47,194. (7) Li, Α.; Williams, R. R. Spectrochim. Acta, in press. (8) Williams, R. R. Appl. Spectrosc, in press.
Ron Williams is an associate professor of chemistry at Clemson University. He received his Ph.D. in analytical chemistry from the University of Georgia in 1981. After a year as a post doctoral fellow at the University of Al berta, he joined the faculty at Ohio University in 1982. He joined the Chemistry Department at Clemson University in 1988. His research inter ests include Fourier transform spec trometry and laboratory automation using small computers.
ANALYTICAL CHEMISTRY, VOL. 61, NO. 6, MARCH 15, 1989 · 437 A