Oct 8, 2005 - AbstractâThis paper describes a serially interfaced computer data acquisition system based on the PIC16f...
Serbia & Montenegro, Belgrade, November 22-24, 2005
PIC and PC Integration: Candidates for Low Cost Data Acquisition R.O. Ocaya, Member, IEEE
Abstract— This paper describes a serially interfaced computer data acquisition system based on the PIC16f877. It presents the interfacing and programming considerations made to maximize the performance to cost ratio. The results show that in spite of its deceptively simple hardware the system has a remarkable linearity and accuracy. Keywords— ADC, data acquisition, measurement, PIC, serial communications.
I. I NTRODUCTION OMPUTER based data acquisition in research and teaching has traditionally required the installation of complicated and expensive hardware. Installation has been synonymous with opening the computer, inserting an ‘interface’, and installing the software. While this approach has its advantages such as higher speed and less clutter, it often deters many prospective users because of the associated cost of the hardware and software. This puts the approach beyond the capabilities of, say, a school laboratory with limited means. Computers are standard equipment in all but the most archaic of laboratories. But in such environments they tend to be relegated to the tasks of document processing, internet, electronic mail, games, and so on, rather than to serious usage as tools for data acquisition and processing. In such an environment the true potential of a computer is lost. It is therefore of considerable interest to find a significantly cheaper and less technically demanding alternative in the environments mentioned above. This paper reports on work done on a low cost but precision solution that enables, with minor modifications where necessary, any relatively modern computer to function as a data acquisition system. This work has stimulated interest in many schools and laboratories where the author lives. The project is based on the PIC16f877 microcontroller.
II. PIC MICROCONTROLLERS A microcontroller is an electronic device that integrates several or all the features required to control a process with a minimum of additional devices. For this reason, it is often regarded as a “computer on a chip”. Considering the ease with which it can be programmed and reprogrammed in situ, it offers a dynamic upgrading This work is supported by Eskom Holdings, South Africa. R.O. Ocaya, Dept. of Physics, North West University, Mafikeng Campus, P. Bag X2046, Mmabatho 2735, South Africa. E-mail: [email protected]
Configuration for data logging.
solution to many interfacing and control problems. Of particular interest in this paper is the PIC16f877 device. The abbreviation PIC stands for programmable integrated circuit, a class of fast and highly popular processors made by Microchip Incorporated. This PIC is a natural choice if a high performance to cost ratio is desired. The features employed in this project are the eight analogue to digital inputs and the asynchronous serial port which enables a half-duplex serial communication with a personal computer using the RS232 standard. III. S ERIAL INTERFACING The serial port is convenient albeit slower because of the fewer interconnects and ease of programming. In the past, access to the hardware ports was not particularly difficult but as operating systems evolved, so did the urgency to guarantee system stability and security especially on networked computers . Many operating systems have placed constraints on direct port access. In such cases the operating system acts as the arbitration layer, generally making it more difficult to implement interfaces that were once easy to use. Fig. 1 shows the layout of the interrupt-driven 8channel serial data acquisition system connected for half-duplex communication with the host. The cycle of operation is as follows: the PIC receives a command from the host, decodes the command, carries out the command, and sends a response back to the host, which in the meantime would be engaged in other tasks. In order to maximize speed, all but the simplest processing is done on the sampled data immediately. Instead, data is accumulated into a spreadsheet file by the data storage block for later processing.
Times related to data acquisition
The controller implements a form of time keeping since commands from the host are periodic or directly related to the hosts own real time. This fact makes it unnecessary to implement real-time keeping on the PIC device itself, consequently simplifying programming and boosting speed. A. The Command and the Response Commands are sent to the controller from the host as ASCII character bytes, giving rise to 256 possible commands. The controller can be programmed easily to respond uniquely to each character command. For example, one character can put the converter into a state of reset, another can specify a channel to convert, another can set baud rate, etc. Normally, following a conversion command, all eight channels are sequentially converted and the responses are sent back to host, two bytes at a time. Two bytes are necessary on the PIC16f877 because the converter has 10-bit resolution, and the conversion yields a 2byte result. Once conversion is complete on a channel, the controller serially sends the high byte first and then the low byte, before starting to convert the next channel. The host is programmed in such a way that it is interrupted only when the 16-byte input buffer only when it is full. This parallel processing mechanism allows time-saving because the host continues with other tasks such as storing data from a prior buffer fetch to a disk drive. Disk writes tend to be slow and the parallel tasking is a welcomed bonus. IV. ACQUISITION TIME Most ADCs use a sample and hold (S&H) device that can be the source of undesirable problems if not used with care. For example, being usually a simple capacitor with non-ideal characteristics, the S&H may not be used immediately after a conversion. Charge leakage due to the resistance and inductance of the capacitor means that the ‘held’ voltage drops continually with time, whatever the rate. Capacitors also exhibit a limiting charge storage behaviour termed memorized dielectric absorption . This effect can be devastating in a converter but can be limited by complex neutralization in high performance converters. The PIC16f877 is not immune and needs to be used with care in a precision data acquisition system. Acquisition time, TACQ , is the time taken from the instruction to locate a channel to the when it is actually selected and conversion can begin. It should not confused with sampling time, TS , or with conversion time,
A typical ADC input model.
TC . TS is the time taken from the start of a conversion to the time a steady digital result is available, while TC is the time taken from the issuing of an acquisition request to the time a steady digital output is available. V. FACTORS DETERMINING PERFORMANCE Fig. 3 shows a typical analog input model of a PIC based converter. The model outlines the factors that modify the time constants related to acquisition . The diodes protect the port pin from inputs greater than the threshold, VT = ±(VDD + VD ), where VD is a diode drop. A. Determining acquisition time If the converter is to be within its specified accuracy the S&H capacitor should charge fully to the input voltage level. In general, acquisition time may be calculated according to Equation (1). TACQ = TAM P + TC + TCOF F ,
where TAM P = amplifier settling time, TC = hold capacitor charging time, and TCOF F = temperature coefficient of time. For a converter of M-bits and a bit error of 21 LSB, Equation (1) is arrived at by calculating the time taken for the S&H capacitor to change by a small amount that just causes the bit error: µ ¶ 1 VH = VREF 1 − M (1 − e−κTC ), (2) 2 where κ = 1/CHOLD RT , RT = RIC + RSS + RS , and M = number of bits in the converter. RT is the effective series resistance of the circuit due to source, wires and the sampling switch . Rearranging Equation (2) and assuming that VH = 0 at a time t = 0, then 1 . (3) −1 RT indicates an upper limit for the source impedance, which is the only factor normally open to the user to influence directly. For the PIC the maximum analogue TC = κ ln
8 9 10
RD7/PSP7 RD6/PSP6 RD5/PSP5 RD4/PSP4 RD3/PSP3 RD2/PSP2 RD1/PSP1 RD0/INT
RA0/AN0 RA1/AN1 RA2/AN2 RA3/AN3 RA4/TOCKI RA5/AN4
RC7/RX/DT RC6/TX/CK RC5/SD0 RC4/SDI/SDA RC3/SCK/SCL RC2/CCP1 RC1/T1OSI/CCP2 RC0/T1OSO/T1CKL
RE0/RD/AN5 RE1/WR/AN6 RE2/CS/AN7
30 29 28 27 22 21 20 19
U6 13 8 11 10
26 25 24 23 18 17 16 15
1 3 4 5 2 6
C2 0u1 C3 0u1
3 2 1
C+ C1C2+ C2V+ V-
12 9 14 7
R1OUT R2OUT T1OUT T2OUT
R1IN R2IN T1IN T2IN
3 2 1
OSC1/CLKIN OSC2/CLKOUT VDD2
11 C9 0u1
POWER IN ( >7V AC/DC )
C12 + 10u
(c) R O Ocaya Title
Serial ADC II
Document Number 1
The temperature coefficient is specified in microseconds per degree rise in temperature. TACQ is also affected by the settling time and slew rates of the amplifiers used in channel selection. For the PIC devices a minimum settling time of around 20µs must be allowed between selecting a channel and starting to convert it.
T∆θ = ∆θ × TCOF F
1 C10 + 220u
AC/DC 1 2
RX = RC7 TX = RC6
input source resistance allowed is 10kΩ. The worst case temperature dependent time drift can be estimated using Equation (4):
Saturday, October 08, 2005
Rev 2.0 Sheet
The converter schematic.
B. Estimating conversion time PIC ADCs use the successive approximation technique. If the conversion time per bit is denoted TAD then the total conversion time for M bits is approximately 1.2TAD × M . The converter clock has to be chosen in such a way that the minimum TAD is 1.6µs. C. Estimating minimum sampling time Fig. 4 shows the timing diagram that can be used to estimate the maximum sampling rate, TS . Time TP represents the total processing overhead on the host such as storage. TACQ is the acquisition time per channel, TC is the conversion time per channel and TCOM M S is the total time taken for all communications - from the command to response. N = 8, the number of channels to convert. The responses are sent as 10-bits, or one elementary data unit, EDU (for convenience). A serial connection of 9.6 kbaud, 8-bits, no parity, 1 stop-bit and 1 start bit has an EDU duration of 1.042 ms. This gives TCOM M S ≈ 18.8 ms. The minimum sampling time in Fig. 4 can then be estimated to be about 19.1 ms. At near maximum baud rate of the PIC (57.6 kbaud), the communications overhead would be about 3.3 ms. This yields a minimum total sampling time of about 3.6 ms. VI. T HE PIC HARDWARE Fig. 5 shows the circuity of the converter. It is simple and is within the means of most electronics enthusiasts. However, low noise printed circuit board techniques must be used for construction. It comprises only a single large scale integrated circuit and a handful of support devices for power, timing and communications.
2 3 4 5 6 7
1 2 3 4 5 6 7 8 9
Sampling rate determination.
40 39 38 37 36 35 34 33
RB7 RB6 RB5 RB4 RB3 RB2 RB1 RB0/INT
Fig. 6. Plot of converted Vin versus actual Vin . Also shown is the linear fit with its equation and Pearsons Coefficient of fit.
VII. P ERFORMANCE The converter was evaluated in two ways: 1) by correlating linearity, and 2) by running a sample temperature logging session over a 12 hour period. A. Linearity Linearity is tested by plotting converted channel voltage against actual input. The exact channel voltage is measured using a Yokogawa 7533-05 digital multimeter. The resulting plot is shown in Fig. 6. The graph shows a remarkable linearity and matches the precision but an offset of approximately 6 mV for each point. This term originates in the external amplifiers. B. A sample logging run A sample temperature logging session using the converter is shown in Fig. 7. The sensor is a high-grade precision temperature sensor from National Semiconductors, the LM35CZ.
A PPENDIX I S OFTWARE The controller and host programming templates in MPASM and VBasic 6 respectively can be provided upon written request to the author. ACKNOWLEDGMENT The author would like to express gratitude to Eskom Holdings Ltd, South Africa for its continued support through the TESP program. Fig. 7.
Data logging over a 12-hour period. TS = 10s.
VIII. C ONCLUSION
This paper has focussed on presenting the timing and input matching requirements rather than on programming optimization. The resulting computer data acquisition system has remarkable accuracy, linearity and acquisition time. In addition, it requires no modification of existing computer hardware, making installation manageable even by novices. The system has potential as a tool that provides an exciting way to make precision measurement accessible to many users, both learners and professionals alike.
R EFERENCES  R.O. Ocaya, A simple computer interface to time relatively slow physical events, Physics Education, Vol.35, No.4, p267-276, IOP Publishing, London, 2000.  P. Horowitz, & W. Hill, The Art of Electronics, 2nd Edition, p220, Cambridge University Press, 1989.  O. Gonzalez, M. Rodriquez, A. Ayala, J. Hernandez, & Rodriquez, S., Application of PICs and microcontrollers in the measurement and control of parameters in industry, International Journal of Electrical Engineering Education Vol. 41, No.3.  Microchip Technology Incorporated, PICmicro Mid-range microcontroller family, Datasheet DS31021A, p21-26 1997.  D.J. Allstot et. al., Analog MOS integrated circuits, Vol. II – Edited by Gray, P.R., et. al, IEEE Press, pp. 167–186, 1988.  R. Castello & P. Gray, Performance limitations in switched capacitor filters, IEEE Trans. Circuits and Systems, Vol. CAS-32, No. 9, pp. 865–876, 1985.  National Semiconductor Corporation, LM35 Precision Centigrade Temperature Sensors, Datasheet DS005516, 1997.