A microcontroller-based data acquisition system ... - Semantic Scholar

2 downloads 0 Views 107KB Size Report
Raphael Mukaro and Xavier Francis Carelse. Abstract— The hardware design and operation of a battery- powered microcontroller-based data acquisition ...
1232

IEEE TRANSACTIONS ON INSTRUMENTATION AND MEASUREMENT, VOL. 48, NO. 6, DECEMBER 1999

A Microcontroller-Based Data Acquisition System for Solar Radiation and Environmental Monitoring Raphael Mukaro and Xavier Francis Carelse

Abstract— The hardware design and operation of a batterypowered microcontroller-based data acquisition system (herein referred to as the DAS) for unattended remote measurements are presented. The system was designed around the ST62E20 8-bit microcontroller and applied for solar radiation monitoring. The measurement system uses the SolData silicon-cell pyranometer as the solar radiation sensor. The data from the sensor is collected by means of on-chip A/D converter and stored in a serial EEPROM until uploaded to a portable computer. Keeping the DAS in a low-power mode, which is only interrupted when measurements are to be taken or when a computer is connected to retrieve the stored data, minimizes power consumption. An on-chip timer provides an interrupt to awaken the system from its low-power wait mode at 10-min intervals to sample and store the data. At the end of each data collection period, the acquired data will be transmitted to the computer through the RS232 serial port for subsequent analysis. Only unprocessed data is stored in EEPROM. Quality control and data analysis is done off-line in the laboratory to minimize system cost, complexity and system downtime. Field tests and comparisons of this measurement system against the standard Eppley precision spectral pyranometer (PSP) have shown a slightly nonlinear correlation and that the accuracy of this measurement system as applied to solar radiation monitoring is fairly good, typically 613 W/m2 : Index Terms—Communication, data acquisition, digital, interface, interrupt, microcontroller, programmable, serial.

I. INTRODUCTION

W

HILE quantitative information on global solar radiation and other environmental parameters is needed in many studies such as meteorology and the design of solar systems, it is difficult to obtain these data in remote areas where relevant data are required. This is mainly because such studies cover wide areas and also generate large amounts of data, such that the efficient acquisition, management and analysis of the data become tedious, time consuming and above all expensive. In most cases researchers enter these large volumes of monitored data manually into computer files for subsequent analysis [1]. Given the labor intensiveness of this procedure and the potential for transcription errors, it is important to computerize the acquisition of data, data-file creation and analysis of the data [5]. Hence a low-cost battery operated microcontroller-based data acquisition system that runs unattended was developed and applied to continuously monitor solar radiation on a

Manuscript received November 17, 1996; revised September 16, 1999. This work was supported by the United Nations University through the Microprocessor Laboratory, ICTP, Italy. The authors are with the Physics Department, University of Zimbabwe, Harare, Zimbabwe. Publisher Item Identifier S 0018-9456(99)09595-9.

horizontal surface. Monitoring as described herein deals with collection, recording and transmission of the measured data to the computer for archival storage and off-site analysis of the data acquisition system performance. This data is sampled and recorded as a function of lapsed time of the experiment. This improved the quality of data since small errors are involved in digital data handling compared to conventional manual methods. This system is well suited for monitoring meteorological or environmental parameters at remote stations, particularly in developing countries where electrical power and telephone lines for telemetric data transfer are not readily available [5]. One operator with one portable computer is all what is required to collect acquired data from many such systems scattered around an area of interest. II. HARDWARE DESIGN The data acquisition system developed is a compact (70 50 30 mm), low cost, 8-bit system with 8 analog input channels designed for automatic long-term data collection. Fig. 1 shows the block diagram of the basic elements of the design. The system was designed to be versatile and all operations are under software control. This will allow for future expansion or modifications without the need for major hardware changes. The system is connected to a computer through the RS232 serial link to allow user communications and to download recorded data to the computer for subsequent analysis. The main component of the data acquisition system is the ST62E20 microcontroller that is driven by an 8 MHz crystal oscillator. The microcontroller is an HCMOS integrated circuit computer designed for embedded control applications which is here used to control measurement and data storage sequences. It has 4 kb of program space (EPROM), 64 bytes of scratch pad RAM and a true LIFO hardware eliminating the need for a stack pointer. It was chosen for this purpose because of its low-power consumption, low-cost and an inbuilt 8-bit A/D converter with up to 8 single-ended analog inputs. The ADC has a conversion time of 70 s when an 8 MHz oscillator is used. With a 5 V supply the converter has a resolution of 20 mV. Fig. 2 shows the hardware details of microcontroller-based data acquisition system. Two HCF4066BE quad switches (by SGS Thomson Microelectronics) are used in conjunction with the A/D converter to sample signals from the silicon-cell sensor and the 2.5 V reference derived from the LM336 voltage reference. These two switches provide this design with 8 single-ended analog input channels, four of which are dedicated for the reference voltage necessary for calibration purposes. The proper operation of

0018–9456/99$10.00  1999 IEEE

MUKARO AND CARELSE: MICROCONTROLLER-BASED DATA ACQUISITION SYSTEM

Fig. 1. Block diagram of the data acquisition system.

Fig. 2. Circuit diagram of the data acquisition system.

1233

1234

IEEE TRANSACTIONS ON INSTRUMENTATION AND MEASUREMENT, VOL. 48, NO. 6, DECEMBER 1999

each analog input line is verified by connecting the reference through one of the switches to the A/D converter. voltage, A digital conversion is made and the results transmitted to the computer and compared against an expected digital output. To ensure optimum system use and minimum power consumption, nearly all control lines of the microcontroller are used effectively. Seven lines from port B are used: four (PB1, PB2, PB3 and PB4) for analog inputs and two (PB5 and PB6) for data exchange with the memory chip. The other port B line, PB0, together with port A line, PA3 are used for RS232 communication with the computer for receiving command messages and for uploading acquired data to the computer respectively. Two other lines of port A, PA0 and PA1, are used as control lines for the quad switches. Analog input line PB1 is used for measuring both solar radiation and battery status if appropriate signals are applied to the control lines. A logic low on the control line turns off the selected switch shutting off all its analog inputs. A logic high placed on line PA1 selects quad switch SW1 so that four analog input lines connected to this switch can be sequentially sampled. Similarly a logic high placed on PA0 selects SW0 so that the reference voltage can be sampled. In this application, when PA1 is high and PA0 is low, solar radiation will be measured (which gives by sampling the signal on PB1. Similarly information on battery status) will be sampled through the same analog input line PB1, if PA0 is now high while PA1 is low. The other three analog input lines are not used here, but could be used for other environmental parameters such as ambient temperature and humidity. An LED shows the status of the system. The LED is illuminated when measurements are being taken and while data is being transferred between the data acquisition system and the computer. Line PA2 capable of sinking 20 mA current is used for directly driving this indicator LED. The status LED is lit when a logic 0 is placed on this line and is turned off by a logic 1. The SolData pyranometer is the most expensive component of the system, costing about U.S $300. The rest of the data acquisition system components cost less than U.S. $60. The sensor produces a voltage between 0 and 100 mV. An LM358 low power dual operational amplifier (SGS-Thomson Microelectronics) with a gain of 34 was used for signal amplification. It was chosen because both its offset current and offset voltage are very low (2 nA and 2 mV respectively). The only other major component connected to the microcontroller is the Microchip 24C65, an HCMOS 8-pin and 64-kbit serial EEPROM. This memory is used to sequentially store acquired data. It has the following attractive features: 1) has a data retention of over 40 years without the need for a power source; 2) has filtered inputs for noise suppression; 3) has got power on/off data protection circuitry; 4) has an electrostatic discharge protection of over 4 kV so it can withstand power surges caused by lightning which is a common hazard in this region during the rainy season. The 24C65, which is described by the manufacturer as a Smart Serial EEPROM, uses only two lines, namely the serial data

line, SDA, and the serial clock line, SCK, to communicate with the microcontroller. The 24C65 data line, SDA, and the HCF4066BE switch control lines are both open drain terminals so 10 k pull-up resistors have been used. The 3-bit address (chip select) of the memory chip is hard-wired at the pins A0, A1 and A2 which are connected to ground to set the address at 000 (binary). However up to eight such EEPROMS, giving a total of 64 kilobytes may be connected in parallel when the address pins are appropriately hardwired to obtain addresses ranging from 000 to 111 (binary). Serial interfacing between the data acquisition system and the computer is implemented using the MAX232 line driver/receiver which is used to convert TTL (0–5 V) voltages required by the data acquisition system to the 12 V and 12 V needed by the computer for RS232 communication. Only three RS232 lines are used for serial communication in this application. PB0, PA3 and ground from the microcontroller are connected to the controlling computer’s RS232 Transmit Data (Tx), Receive Data (Rx) and logic Ground lines respectively. The 5 V supply for the interface circuit is derived from the data acquisition system. The MAX232 serial interface chip is incorporated in the detachable module, which acts as a data transfer interface between the data acquisition system and the computer. It is only powered when a computer is connected to the data acquisition system to retrieve the collected data. Capacitors C3, C4, and C7 are provide power supply filtering to the ST6220, the 24C65 memory chip and the MAX232 respectively. The reset pin on the microcontroller is active low and is held to a positive voltage by a 2.5 k pull-up resistor. A touch of the push button brings down the potential of the reset pin to ground thereby causing a system reset. Capacitor C8 is used to eliminate debouncing of the push button which causes the microcontroller to reset many times. Diode D1 is used for protecting the system against damage due to accidental battery polarity reversal.

III. SOFTWARE DESIGN AND DATA ACQUISITION SYSTEM OPERATION The control program, written in ST62 family assembly language, oversees the operation of the entire system under interrupt control. This measurement system utilizes two of the microcontroller interrupts. The timer interrupt is used for data collection and storage while the PC interrupt is used to trigger the process of data transfer between the computer and the system. These interrupts are nonpreemptive, however the PC interrupt has the higher priority. The main program of this system does nothing except to wait for these two interrupts. So this system is interrupt driven. The major roles of the data acquisition task include regular storage of monitored data to the EEPROM, keeping a record of lapse time relative to the first measurement and transferring measured and acquired data to the memory and later to the computer respectively. The system makes full use of the computer not only for subsequent data analysis and presentation of results after retrieving the stored data, but also for initial setting of the start date and time of the system before it is left to run independently. In this investigation, the system monitors horizontal global

MUKARO AND CARELSE: MICROCONTROLLER-BASED DATA ACQUISITION SYSTEM

1235

Fig. 3. State diagram for the data acquisition system.

solar radiation at 10 min intervals. The software and complete operation of the system can be understood from Fig. 3. which shows the state machine diagram for the measurement system. The system has four modes of operation: 1) acquisition or measurement; 2) storage; 3) wait mode; 4) listen mode. The microcontroller was programmed to be in a lowpower mode, except at specific times when data acquisition or communication with the computer is in progress. The operation of this data acquisition system is similar to the one described by Lou et al. [2]. When power is first applied or a reset is signaled, the first state entered is the Initialize state. This state ensures that all internal variables have a defined initial value and that the input/output lines are properly configured. The system then goes into the Wait state. In this mode the oscillator remains active to keep track of time but the system does nothing except to wait for the interrupts. Instruction execution is stopped, internal power consumption is decreased, however, and internal RAM contents are preserved. The program then starts the timer and reads channel PB0 to check if a computer is connected to the data acquisition system. If the computer is not connected the timer awakens the system from the Wait mode. A set of readings is then taken and stored after which the data acquisition system goes back into the Wait state to wait for another data acquisition and storage cycle. If the computer is connected, the system makes a transition into the Listen mode in which the operator uses the computer

keyboard to communicate with the data acquisition system. The data acquisition system does not have a real-time clock so the operator via the computer keyboard supplies the start time for measurement before the system is left to run. This data is stored in the first five bytes of the EEPROM. When the system start time has been entered, data and reference voltage corresponding to this start time is immediately sampled and stored. Thus data acquisition and storage is triggered from the computer keyboard after the operator has specified start time and date. After taking this initial set of readings, the data acquisition system goes back into the Wait state to wait for another data acquisition and storage cycle. A Turbo serial communication software running on the computer C at this point instructs the user to disconnect the controlling computer. Every 24 ms thereafter, the timer interrupt wakes up the microcontroller to check if 10 min have elapsed. If 10 min have elapsed, which happens after 25 000 such interrupts, the microcontroller goes into the Measure state where the system increments lapse time and lights an LED to indicate that samples are being taken. In this Measure state, reference voltage is sampled and 20 A/D converter readings from the sensor are taken and averaged. If the data from sensor is less than ten (equivalent to an irradiance of 65 W/m the system assumes it is night time and does not record this data. This was done to save memory. Only lapsed time is recorded, and the data acquisition system returns to the Wait mode. The system repeatedly sleeps, awakens and keeps track of time until the data are valid. If the sampled value is above ten, the system goes into the Store state where the data are written in the external EEPROM chip. Upon completion of

1236

IEEE TRANSACTIONS ON INSTRUMENTATION AND MEASUREMENT, VOL. 48, NO. 6, DECEMBER 1999

Fig. 4. Typical calibration graph for the DAS.

data storage the system switches off the LED to indicate that the acquisition and storage processes are complete. It then returns to the main program where it will go back into the Wait mode again to wait for the next PC inquiry or data acquisition. Following every 10 min time, the reference and sensor signals are sampled and written to memory with each parameter using one byte. With this sampling frequency, 18 bytes of memory are used per hour during the day and only one byte for lapse time during the night. So the system can run for about a month before the 8 Kbytes of memory are filled up. The data acquisition and storage processes go on until the computer again interrupts the system. This time when the PC interrupt is noted, the measurement system goes into the Listen mode in which a series of commands are entered from the computer keyboard to either 1) download data to PC; 2) erase EEPROM for another recording cycle; 3) check the operation of each of the four analog input lines; 4) reset the system. Serial communication between the computer and the data acquisition system operates in the half duplex asynchronous mode at 600 baud. The MS-DOS MODE COM1: 600, N, 8,1 command placed in the autoexec.bat file configures the serial port with required communication parameters of 600 baud rate, no parity, data width of 8 bits and one stop bit, at boot-up. A programming language was software program in Turbo C developed to facilitate communication between this system and the computer through the RS232 serial port [5]. Through this program the computer is able to send start date and time to the data acquisition system or retrieve the acquired data for subsequent analysis. The data acquisition system through the PC interrupt routine reads and decodes the command bytes

sent by the PC and performs the appropriate operation. After the successful completion of operation, the system returns an acknowledge signal back to the computer. Acquired data could be retrieved by one of the following methods. 1) One storage module (24C65 chip) remains with the data acquisition system, stores data and is then replaced by a “fresh” storage module during a site visit. The filled module is returned to the office and the data is downloaded to a computer. 2) The data logger is interrogated on-site by a battery operated IBM compatible lap-top computer through the RS232 serial port and acquired data transferred to it followed by a fast clearing of the whole storage module for another storage routine. IV. RESULTS The data acquisition system was first calibrated against a first-class, factory calibrated reference, the Eppley PSP thermopile pyranometer. The data acquisition system was mounted outdoors on a horizontal surface alongside the Eppley PSP Pyranometer. Global horizontal irradiance readings from the two instruments were taken simultaneously at 1-min intervals for intensity levels between 65 and 1200 W/m Synchronization was achieved by taking the Eppley reading when the LED on the data acquisition system was lit up, showing that data acquisition readings were being recorded. The Eppley output was then regressed against the corresponding data acquisition output and showed a slight nonlinearity. Measurements were made throughout the year, so data covering an almost complete range of atmospheric conditions in Harare were used to derive the calibration coefficients. The average empirical first and second order quadratic calibration

MUKARO AND CARELSE: MICROCONTROLLER-BASED DATA ACQUISITION SYSTEM

1237

Fig. 5. Comparison of radiation as measured by the Eppely PSP pyranometer and the DAS.

coefficients of 6.40 and 0.0034 respectively were obtained [6]. So the empirical function for this system as applied to solar radiation monitoring is (1) where is the calculated global irradiance and is the digital data value recorded by the acquisition system. A typical calibration graph is shown in Fig. 4. In order to examine the correctness of the fit, the data acquisition system readings were recorded against corresponding Eppley pyranometer readings and (1) used to estimate the radiation. Fig. 5 shows how well the DAS fit compares with the data from the Eppley pyranometer. There is very close agreement with an error of about 13 W/m [6]. However, during partly cloudy days, relatively wide scatters were obtained. This is mainly due to the difference in response times of the two instruments, with the Eppley PSP pyranometer less able to respond quickly to rapid changes in irradiance levels. The data acquisition system takes about 2 ms to do 20 A/D conversions compared to a response time of about 1 s for the Eppley. So the wide scatters were primarily due to the Eppley being unable to follow rapid changes of radiation associated with clear-cloudy transitions during partly cloudy conditions. Consequently some significant calibration errors occurred during the transition period. This aspect is discussed by Michalsky et al. [3] and Suereke et al. [4]. The data acquisition system operates from a rechargeable fluctuates with battery pack so that the supply voltage, time and state of charge. As the analog-to-digital conversion depends on this voltage, all conversions were checked against a reading obtained from a 2.5 V reference derived from the LM336 voltage reference and the following correction procedure was applied. When the battery pack is fully charged

and the supply produces a regulated 5.0 V, the digitized reference from a reference of 2.5 V, was found to be 127 1. The 1 count uncertainty derives from the fact that the AD converter has a conversion error of one least significant is bit. Thus the corrected digital output at any instant, given by (2) is the digital voltage obtained from the sensor. where This digital correction of the signal, which is done by means of an autocalibration procedure on the computer as the data are retrieved, substantially improved the accuracy of the data [6]. V. CONCLUSION A low-cost microcontroller-based data acquisition system that automatically takes measurements and records the data has been designed, developed and programmed and applied to monitor solar radiation. It has been successfully interfaced to a computer for initial setup of the system and for data retrieval. The data stored are sent to a computer by a serial link upon request, and subjected to graphical analysis. In spite of the insensitivity of the SolData silicon-cell for large wavelengths, the use of it as a solar radiation sensor resulted in good correlation with the Eppely PSP pyranometer. Field tests and comparisons against the standard Eppley PSP pyranometer have shown that the accuracy of this measurement system is fairly good, typically 13 W/m This error is acceptable for a lot of applications in solar energy. The overall quality of the data is good due to intrinsically small errors involved in digital data handling compared to conventional manual measurements. Moreover, the system is easily operated and does not require any programming expertise. The system

1238

IEEE TRANSACTIONS ON INSTRUMENTATION AND MEASUREMENT, VOL. 48, NO. 6, DECEMBER 1999

is could be used to monitor various other environmental parameters. ACKNOWLEDGMENT The following people have significantly contributed to the work presented here: Prof. A. Colavita, Director of the Microprocessor Laboratory, and all staff at the Microprocessor Laboratory, and R. B. Ijadoula of the Agriculture University, Abeokuta, Nigeria.

Raphael Mukaro was born on August 31, 1968 in Harare, Zimbabwe. He received the B.Sc. and B.Sc.(Hon.) degrees in physics from the University of Zimbabwe, Harare, in 1992 and 1993, respectively. He is currently pursuing the Ph.D. degree in physics at the same university. He joined the Physics Department, University of Zimbabwe, in 1993, and has been working as a Teaching Assistant since then. His current interest is microprocessor/microcontroller applications in physics and environmental monitoring and assessment.

REFERENCES [1] P. S. Dahl, “A PC and Lotus-based data acquisition/reduction system for an ICP spectrometer,” Comput. Geosci., vol. 16, no. 7, pp. 881–892. [2] E. Lou, N. G. Durdle, V. J. Raso, and D. L. Hill, “A system for measuring pressures exerted by braces in the treatment of scoliosis,” IEEE Trans. Instrum. Meas., vol. 43, pp. 661–664, Aug. 1994. [3] J. J. Michalsky, R. Perez, L. Harrison, and B. A. Lebaron, “Spectral and temperature correction of silicon photovoltaic solar radiation detectors,” Solar Energy, vol. 47, pp. 299–305, 1991. [4] H. Suereke, C. P. Ling, McCormick, “The dynamic response of instruments measuring instantaneous solar radiation,” Solar Energy, vol. 44, pp. 145–148, 1990. [5] R. Mukaro and X. F. Carelse, “A serial communication program for accessing a microcontroller-based data acquisition system,” Comput. Geosci., vol. 23, no. 9, pp. 1027–1032, 1997. [6] R. Mukaro, X. F. Carelse, and L. Olumekor, “First performance analysis of a silicon-cell microcontroller-based solar radiation monitoring system,” Solar Energy, vol. 63, no. 5, pp. 313–321, 1998.

Xavier Francis Carelse was born in South Africa. He is Lecturer with the Department of Physics, University of Zimbabwe, Harare. He has qualifications in physics and electronic engineering and has worked for eight years in industrial research and development in the U.K. and, in addition to lecturing in four universities in Africa, has also served as a Visiting Lecturer at three universities in the U.S. His specialty is electronic instrumentation and he is mainly interested in the development of undergraduate laboratory experiments.

Suggest Documents