tinydaq a microcontroller based daq device vikent woon universiti
Transcription
tinydaq a microcontroller based daq device vikent woon universiti
i TINYDAQ A MICROCONTROLLER BASED DAQ DEVICE VIKENT WOON UNIVERSITI TEKNOLOGI MALAYSIA ii I declare that this thesis entitled “ title of the thesis “ is the result of my own research except as cited in the references. The thesis has not been accepted for any degree and is not concurrently submitted in candidature of any other degree. Signature : .................................................... Name : .................................................... Date : .................................................... iii ACKNOWLEDGEMENT In the process of carrying out this project, commencing from the title deciding until the completion of project, I was in contact with many people such as academicians, postgraduate researchers and lab assistants. They have rendered their assistant in various aspects and contributed towards my understanding and thoughts. In particular, I wish to grab this opportunity to express my sincere appreciation to my project supervisor, PROF DR SHAMSUDIN HJ MOHD AMIN for his advice, guidance and encouragement that have led to the success of this project. I am also indebted to University Technology Malaysia for providing me the facilities to carry out my project. Librarians at UTM also deserve special thanks for their assistance in the process of my project information obtaining. My fellow friends should also be recognized for their continual support and encouragement. My sincere appreciation also extends to my entire course mate and others who have provided assistance at various occasions. Their views and tips are useful indeed. Unfortunately, it is not possible to list all of them in this limited space. I am grateful to all my family members. iv ABSTRACT DAQ (Data Acquisition) is simply the process of bringing a real-world signal, such as voltage, into the computer, for processing, analysis, storage or other data manipulation. A Physical phenomenon represents the real-world signal you are trying to measure. In order to optimize the characteristics of a system in terms of performance, handling capacity and cost, the relevant subsystem can be combined together. Analog data is generally acquired and transformed into the digital form for the purpose of processing, transmission and display. Rapid advances in Personal Computer (PC) hardware and software technologies have resulted in easy and efficient adoption of PCs in various precise measurement and complex control applications. A PC based measurement or control application requires conversion of real world analog signal into digital format and transfer of digitized data into the PC. A data acquisition system that performs conversion of analog signal to digital data and the digital data to analog signal is interfaced to a pc to implement the functions of a measurement and control instrumentation applications. v ABSTRAK DAQ (data acquisition) adalah suatu proses untuk mengambil isyarat daripada luar dunia seperti isyarat voltan dan simpan ke komputer untuk proses, analisis, penyimpanan data dan pengawal data. Fizikal fenomena adalah salah satu isyarat dari luar dunia. Untuk optimise ciri-ciri sistem DAQ dalam segi prestasi, kapasity pengendalian dan kos , semua sistem yang berkenaan boleh digabung bersama untuk mencapai tujuan tersebut. Isyarat Analog dikendali dan ditukar ke Isyarat Digital untuk tujuan proses, penghantaran, dan memaparan. Kemajuan pesat dalam Komputer Peribadi (PC) perkakasan dan perisian teknologi telah menyebabkan penggunaan mudah dan berkesan dalam pelbagai ukuran yang tepat dan aplikasi kawalan kompleks. Satu ukuran atau kawalan aplikasi berasaskan PC memerlukan penukaran sebenar isyarat analog dunia ke dalam format digital dan pemindahan data digital ke PC. Satu sistem perolehan data yang melaksanakan penukaran isyarat analog kepada data digital dan data digital kepada isyarat analog adalah diantaramukakan kepada pc untuk melaksanakan fungsi-fungsi pengukuran dan aplikasi peralatan kawalan. vi TABLE OF CONTENT CHAPTER 1 2 TITLE DECLARATION ii ACKNOWLEDGEMENTS iii ABSTRACT iv ABSTRAK v TABLE OF CONTENTS vi LIST OF TABLES vii LIST OF FIGURES x LIST OF APPENDICES xi INTRODUCTION 1.1 Background 1 1.2 Objectives 2 1.3 Project Scope 3 1.4 Problem Statement 4 LITERATURE REVIEW 2.1 3 PAGE Researchers’ Project 5 2.1.1 DAQ by AT89C52 6 2.1.2 FPGA Based DAQ 7 METHODOLOGY 3.1 Hardware Design 8 vii 3.1.1 Microcontroller unit 3.1.1.1 RCM3010 features 10 DAC chip 11 3.1.3 ADC chip 12 3.2 Circuit Design 13 3.3 Software design 3.1.2 4 5 9 3.3.1 Programming on controller 14 3.3.2 Software for programming 15 3.3.3 Programming for DAC 16 3.3.4 Programming for ADC 18 3.3.5 Serial peripheral interfaces 22 3.3.6 Programs Implementation 22 3.3.7 Programs Algorithms 23 3.3.8 Explanation of Main Programs 29 3.3.9 Explanation of Execute instruction Programs 33 3.3.9.1 DAC Output 33 3.3.9.2 ADC Input 35 3.3.9.3 ADC and DAC Calibration 37 3.3.9.4 Digital I/O 38 DISSCUSION 4.1 Introduction 39 4.2 4.3 Experiments on Analog Input Range Comparison of Output DAC voltage 40 45 4.4 Accuracy of ADC Input Signal 46 CONCLUSION AND RECOMMENDATION 5.1 Conclusion 48 5.2 Problems 49 5.3 Recommendations 51 viii WORK SCHEDULE 52 REFERENCES 53 APPENDICES 54 ix LIST OF TABLE TABLE TITLE PAGE 3.1 RCM3010 Features 9 4.1 Experimental Results for Vin Range -10V to 10V 39 4.2 Experimental Results for Vin Range -20V to 20V 40 4.3 Experimental Results of Output Voltage DAC comparison 42 4.4 Accuracy of Single Ended Unipolar Mode 44 4.5 Accuracy of Single Ended Bipolar Mode 44 4.6 Accuracy of Differential Mode 45 x LIST OF FIGURE FIGURE TITLE PAGE 2.1 Data Acquisition System by AT89C524.1 5 2.2 FPGA Based Data Acquisition System 6 3.1 3.2 Process Design of TINYDAQ RCM3010 Pin Diagram 7 9 3.3 3.4 3.5 TLV5630 TLV5630 Block Diagram ADS7870 Pin Diagram 10 11 11 3.6 ADS7870 Block Diagram 12 3.7 Circuit Design of TINYDAQ 13 3.8 RCM3010 Rabbit Core 14 3.9 Clock Cycles for Fetching Instruction Code 15 3.10 Clock Modes for RCM3010 16 3.11 Instruction Bytes 17 3.12 Timing Diagram for an 8-Bit Read Operation 19 3.13 Output Codes versus Input Voltage 19 3.14 Serial Peripheral Interfaces 20 3.15 Main Program Algorithms 22 3.16 Execution Instruction Algorithms Part 1 23 3.17 Execution Instruction Algorithms Part 2 24 3.18 LABVIEW User Interfaces Algorithms 25 3.19 Connection test using Hercules 26 3.20 LABVIEW User Interfaces 26 xi 3.21 SPI Initialization code 27 3.22 TCP/IP Connection Initialization code 27 3.23 Digital I/O Initialization programming code 28 3.24 Clock Initialization programming code 28 3.25 EEPROM save Structure 29 3.26 TCP listen programming code 29 3.27 TCP read programming code 30 3.28 DAC main function programming code 31 3.29 ADC calibration programming code 32 3.30 ADC output type programming code 33 3.31 ADC fetch instruction programming code 33 3.32 DAC and ADC calibration data structure 34 3.33 DAC and ADC calibration equation 34 3.34 Configure digital output programming code 35 3.35 Configure digital input programming code 35 4.1 Circuitry Design of Signal Conditioning 37 4.2 Linear Graph with Vadc =0-5V and Vin =±10V 38 4.3 Graphs on Single Ended Unipolar 45 4.4 Graphs on Single Ended Bipolar 46 4.5 Graphs on Differential Input 46 xii LIST OF SYMBOLS DAQ - Data Acquisition SPI - Serial Peripheral Interfaces I/O - Input or Output ADC - Analog to Digital Converter DAC - Digital to Analog Converter V - Voltage R - Resistor Vadc - Input Voltage Signal of Analog to Digital Chip Vref - Reference Voltage Vdac - Output Voltage Signal of Digital to Analog Chip Vin - Input Voltage MOSI - Master Out Slave In MISO - Master in Slave Out SCLK - Clock Frequency FS - Chip Select TCP - Transmission Control Protocol IP - Internet Protocol RCM - Rabbit Core Module USB - Universal Serial Bus PC - Personal Computer xiii LIST OF APPENDICES APPENDIX TITLE PAGE A Parts ADC Programming Code 54 B Schematic Design of ADC 57 C PCB Design of TINYDAQ 58 D Casing design of TINYDAQ 60 E LABVIEW design of TINYDAQ User Interfaces 61 F Structure of TINYDAQ 62 1 CHAPTER 1 INTRODUCTION 1.1 Background Data acquisition is process of converting the samples signal into digital form to analyze. With the advance of the technology nowadays, many types of high capabilities data acquisition devices have been developed to corporate with others highly advanced devices. Data acquisition (DAQ) systems basically change the input analog signal to output the digital signal for processing the collected data. Data acquisition has a wide range of application which include military use, heavy and light industry, and security and surveillance technology. In the recent past, Data acquisition system has been greatly use in manufacturing company. Data acquisition system work with the system it’s attach with to perform several function. In addition, data acquisition system also contain digital input and output to help control the electric devices it’s attached in order to smoothed the progress of controlling the devices. Data acquisition hardware usually comes with a PC which using to display the result of collected data. It usually has a build in serial port connection, USB connection or Ethernet port connection to interface with PC. In my case, I will use the Ethernet port which has already built in to interact with PC and the data acquisition devices. The data acquisition hardware named TINYDAQ will use RCM3010 rabbit core as the motherboard to be programed as a DAQ devices 2 incorporate with external circuit. TINYDAQ will be designed in small structure yet with lot of configurable digital Input and output and analog input and output. TINYDAQ capable of convert analog signal into digital signal and also configure digital input and output. TINYDAQ use Ethernet port to interface with PC. PC will transfer instruction to TINYDAQ and also display converted result signals. 1.2 Objectives This project aimed to enhance the data acquisition capabilities. There are 3 main objectives to achieve in this project: 1. Reduce the size, cost and weight of TINYDAQ. 2. Friendly User interface using LABVIEW 3. Build TINYDAQ in small size yet many digital I/O port which enough to operate in huge electric devices. 1.3 Project Scopes TINYDAQ aimed to be able to perform following function: 1. Able to perform ANALOG TO DIGITAL CONVERTER (ADC) 2. Communicate between TINYDAQ and PC 3. Able to configure digital input and output. 4. Able to calibrate ADC. 5. Able to save the calibration data for ADC. 6. Able process unipolar, bipolar and differential analog signals. 7. Able to manipulate the software based gain to perform ADC in wide range of analog signals. 3 1.4 Problem Statement Traditional DAQ hardware needs PC for interfacing, fetching instruction and reading measured data. There have been many type of DAQ hardware build in small structure but contrary it has limited digital I/O port which is insufficient for some huge electric equipment. The Traditional DAQ hardware is expensive and the connector which uses to communicate with PC is not stable. Most of previous DAQ hardware uses USB connection for PC interaction yet the PC sometimes has difficulties in detecting the connected DAQ device. This result in the user will has a hard time to fetch the instruction to DAQ hardware or reading the measured data from PC. 4 CHAPTER 2 LITERATURE REVIEW There are many similar and relevant project can be found throughout the internet and library. There will be some explanation about the relevant information about data acquisition hardware and it’s functionality in this discussion. Data acquisition system is the data collected on-site processing, transmission, storage, display and other operations. Data acquisition system's main function is the analog signals into digital signals, and analysis, processing, storage and display. Many companies large and small multi-national development of data acquisition products and cards and the like, which makes digital information to provide a great convenience. Today, the PC can automatically process and analyze data; there are many alternative methods to collect data. The choice of which depends on many factors, including task complexity, the required speed and accuracy, you want evidence of information and so on. Whether simple or complex, the appropriate data acquisition system can run and play its role. (Hai Feng Zhou February, 2012) 5 2.1 Researcher’s Project 2.1.1 Data Acquisition System by AT89C52 Figure 2.1 Data Acquisition System by AT89C52 The design using AT89C52 microcontroller as the core of the data acquisition system control, data acquisition system is divided into modules, A / D converter module, system control module, keyboard module, display module and other parts. Multi-channel system can capture the data stream, after treatment on the LED display. The data acquisition card, AT89C52 microcontroller as the core component with a data acquisition, object control, display, keyboard and many other more complex features a complete automation system. Use RS-232 serial communication to communicate with the microcontroller.(Hai Feng Zhou February, 2012) 6 2.1.2 FPGA Based Data Acquisition System Figure 2.2 FPGA Based Data Acquisition System Aiming at a storage system of high-speed data acquisition, it is designed with 6 channel, 16-bit AD converter chip AD7656 and a programmable logic device EP2S90F102. The K9W8G08U1M chip made in SAMSUNG is selected as storage unit, and FPGA controls the needed logic for FLASH and AD converter. At the end of data acquisition, the stored data can be transmitted to the host through the USB2.0 interface. (Ning, Guo et al. 2012) 7 CHAPTER 3 METHODOLOGY AND APPROACHES Generally, building data acquisition system required knowledge from various aspect, discipline and studies, thus a systematic approach is crucial in the development process. In this chapter, I will explain and descript the methodology and guidelines in designing data acquisition system which is able to perform analog to digital conversion, communication with PC and configurable digital I/O ports. There will be 5 major parts in developing data acquisition system. HARDWARE DESIGN CIRCUIT DESIGN SOFTWARE DESIGN INTERGRATION OF HARDWARE AND SOFTWARE TESTING AND CALIBRATION FIGURE 3.1 Process Design of TINYDAQ 8 Choosing the right hardware and parts for data acquisition system is very important. After research have been done, the suitable hardware and parts are chosen and circuit will be design to connect the whole system together in order to make the system work as one. Hardware design and software design will be separated at the beginning and integrated after both design have been completed. Testing and experiment will be conducted to ensure the prototype function properly. 3.1 Hardware Design 3.1.1 Microcontroller Unit RCM3010 RABBITCORE will be chosen to act as core for my data acquisition system. RCM3010 RABBITCORE is selected based on several advantages over others controller: 1. Has internal Flash memory and Static RAM which are huge in capacity. 2. Low power consumption 3. Small structure 4. Low cost embedded microprocessor module 5. Sufficient digital I/O ports and 6 serial ports 6. Support Ethernet port connection 9 FIGURE 3.2 RCM3010 Pin Diagram 3.1.1.1 RCM3010 Features TABLE 3.1: RCM3010 Features MICROPROCESSOR EMI REDUCTION ETHERNET PORT FLASH MEMORY SRAM GENERAL-PURPOSE I/O TIMERS PULSE WIDTH MODULATORS INPUT CAPTURE SERIAL PORTS SERIAL RATE REAL TIME CLOCK POWER RABBIT 3000 at 30 MHz SPETRUM SPREASER FOR REDUCE EMI(RADIATED EMMISIONS 10 BASE-T INTERFACE 256K 128K 52 parallel digital I/O TEN 8 -BIT TIMERS 10-BIT-FREE -RUNNING COUNTER AND FOUR PUSE-WIDTH REGISTERS 2-CHANNEL INPUT CAPTURE 6 shared high speed, CMOS compatible ports MAXIMUM ASYCHRONOUS BAUD RATE = CLCK/8 YES 3.3V 10 3.1.2 DAC Chip FIGURE 3.3 TLV5630 In order for my data acquisition system able to perform analog-to-digital conversion, DAC chip is necessary to include in my hardware design. TLV5630 is chosen for DAC chip because it features eight voltage output DACs in one package. It is compatible with SPI SERIAL PORTS which I will use it to interact TLV5630 with RCM3010 to fetch and execute instruction. TLV5630 is monotonic over temperature and has low power consumption which only consumed 48 mW at 3V. The reference voltage for the DAC chip can be either internal or external. The internal voltage can supply up to 2V and if 2V is insufficient, external voltage can be added to increase the reference voltage at my desire level. Pin LDAC able to simultaneously update all the output voltage. The data format for programming is in 16 bit serial string. 4 bits for the address of the selected output voltage port and the remaining 12 bits are for data bits which are the amount of output voltage. 11 FIGURE 3.4 TLV5630 Block Diagram 3.1.3 ADC Chip FIGURE 3.5 ADS7870 Pin Diagram ADS7870 is the ADC chip I chosen for data acquisition. The reason for using ADS7870 over other ADC chip because of it’s a complete low power data acquisition in a single chip. Additional, it’s also features programmable gain amplifier which provide high impedance output, noise reduction and accurate gain. It can be programs to adjust any desire gain from 1, 2, 4,5,8,10,16 and 20V. It also consists of programmable inputs 12 which are 4 differential inputs and 8 single ended inputs. Serial interface allow me to programs ADS7870 from RCM3010 through SPI. The programming instruction code for ADS7870 is 8 bits code consisting two kind of mode which direct mode and register mode. Direct mode allow user to direct convert the selected input into digital signal while register mode allow user to read or write the register of ADS7870 for further modification. FIGURE 3.6 ADS7870 Block Diagram 13 3.2 Circuit Design TLV5630 POWER SUPPLY RCM3010 RABBIT CORE PC ADS7870 FIGURE 3.7 Circuit Design of TINYDAQ As above figure, the circuit has been designed after all the consideration has been made. DAC and ADC chip will use SPI connection to interact with Rabbit Core to fetch instruction. The whole system is then connected to PC through Ethernet port to send instruction code and observed measure data. Since RCM3010 does not have power supply in it, hence extra power supply circuit is added to power up the circuit. 14 3.3 Software Design 3.3.1 Programming on Controller FIGURE 3.8 RCM3010 Rabbit Core RCM3010 is the core for data acquisition systems. In order to control TLV5630 and ADS7870, the SPI ports in RCM3010 are used. SPI will perform MISO and MOSI during transferring instruction code. The SPI ports in RCM3010 cannot directly use, it should have to initialize before using. A lot of consideration should be made during programming RCM3010, SPI require CLCK and CHIP ENABLE to execute but CLCK for RCM3010 consist of 4 types of mode while TLV5630 and ADS7870 will only receive the instruction in the correct CLCK mode. The following shows the function of RCM3010 I/O ports in operating the data acquisition systems. PORT A2 is used for CHIP ENABLE for TLV5630 PORT A3 is used for CHIP ENABLE for ADS7870 PORT F0 is act as CLCK for both TLV5630 and ADS7870 PORT C0 used to fetch the instruction code for both TLV5630 and ADS7870 PORT C1 used to read the measured data from data acquisition. PORT D4 used to update all the DAC voltage on the output of TLV5630 The rest of the port will programmed as configurable digital I/O ports. 15 3.3.2 Software for Programming For RCM3010, it has its own programming software which named Dynamic C. It integrated development system used for writing programming. It also designed only for Rabbit base microprocessor. In single software, it able for editing, compiling, linking, loading and debugging. Dynamic C is easy to use since many are common with C language and additional feature for Dynamic C is it’s contain library made for Rabbit processor and also other useful source code. Dynamic C use PRINTF command for debugging and observe the result of programs. It also provides sufficient debugging tools to ease the process of programs debugging. Dynamic C use USB programming cable to connect to RCM3010 to burn the programs. 3.3.3 Programming on Digital to Analog Converter FIGURE 3.9 Clock Cycles for Fetching Instruction Code From the clock cycles, the chips receive the instruction code every failing edge of SCLK while FS is at low condition. TLV5630 will only able to receive the instruction code from the require clock mode. If I do not provide the correct clock mode from the RCM3010, the chips will not functioning. 16 FIGURE 3.10 Clock Modes for RCM3010 From the 4 types of clock mode that RCM3010 can provide. I have to set clock mode to 10 in order for TLV5630 can operate correctly. The pin connected to TLV5630 should be initializing or otherwise it will not be functioning. Since I using Port C0 and Port C1 for SPI connection, I have to initialize SPI serial port D. Port A2 which use as CLCK will program to toggle between 1 and 0 while same goes to Port D4 which will update all the output simultaneously at low condition. Since I am using internal reference voltage, I can program to get the reference voltage between 1.024 V and 2.048 V which are built in the chip. To set the internal reference voltage, I have to write bit 1 and bit 2 into register address 0x1001. The Instruction code is 16 bits which the most significant 4 bits are address and the rest are the instruction code. The address of output voltage is 0000 until 0111. The remaining 12 bits is the input digital signal for converting to analog signal. The input range for digital signal is from 0x000 until 0xFFF. The output voltage for each of the input can be obtained using the following formula. 17 3.3.4 Programming on Analog to Digital Converter FIGURE 3.11 Instruction Bytes There are two types of instruction mode for ADS7870, which are direct mode and register mode, both mode execute different kind of function. ADS7870 serial interfaces operate base on 8- bit instruction bytes. The mode of the instruction byte determines by the most significant bit which is D7. If bit D7 = 1, it is in direct mode and if bit D7 = 0, it is in register mode. In direct mode, it is the conversion command. D6 to D4 is for programmable gain amplifier while D3 to D0 is the address channel for conversion and also configure for single ended of differential mode. In register mode, D6 is selected for read or write operation, D5 choose whether the read or write data is in 16 bit word or 8 bit word. D4 to D0 is the address register required for read or write operation. Registers 0 and 1, the A/D Output Data registers, contain the least significant and most significant bits of the A/D conversion result (ADC0 through ADC13). Register 0 also has three fixed zeros (D3, D2, and D1), and a bit to indicate if the internal voltage limits of the PGA have been over ranged (OVR). This is a read only register. Write an 8-bit word to register 0 and the ADS7870 resets. Register 2, the PGA Valid register, contains information that describes the nature of the problem in the event that the allowable input voltage to the PGA has been exceeded. 18 Register 3, the A/D Control register, has two test bits (best left set to zero), a bit to convert the output format to straight binary (BIN), an unused bit set to zero, two bits to configure an automatic read back mode of the A/D results (RBM1, RBM0), and two bits that program the frequency divider for the CCLK (CDF1, CDF0). Register 4, the Gain/Mux register, contains the input channel selection information (M0 through M3) and the programmable gain amplifier gain set bits (G0 through G2). Register 5, the Digital I/O State register, contains the state of each of the digital I/O pins (I/O3 through I/O0). In addition, registers 4 and 5 contain a convert/busy bit (CNV/BSY) that can be used to start a conversion via a write instruction or sense when the converter is busy with a read instruction. Register 6, the Digital I/O Control register, contains the information that determines whether each of the four digital I/O pins is to be an input or an output function (OE3 through OE0). This sets the mode of each I/O pin. Register 7, the Ref/Oscillator Control register, controls whether the internal oscillator used for the conversion clock is on or off (OSCE), whether the internal voltage reference and buffer are on or off (REFE, BUFE), and whether the reference provides 2.5 V, 2.048 V, or 1.15 V. Register 24, the Serial Interface Control register, controls whether data is presented MSB or LSB first (LSB bit), whether the serial interface is configured for 2wire or 3-wire operation (2W/3W bit), and determines proper timing control for 8051type microprocessor interfaces (8051 bit). Register 31, the ID register, is read only. 19 FIGURE 3.12 Timing Diagram for an 8-Bit Read Operation The above diagram shows the example of 8 bit read operation. The instruction code receives by the ADC chip at rising edge. The instruction code can ether reach at rising edge or failing edge depend on the pin 10 (RISE/FAIL). If pin 10 set to 0 , the code will reach at failing edge while pin 10 set to 1, the code will read at rising edge. Upon completion of the read operation, the ADS7870 is ready to receive the next instruction byte. Read operations reflect the state of the ADS7870 on the first active edge of SCLK of the data byte transferred. The 12-bit A/D converter in the ADS7870 is a successive approximation type. The output of the converter is2s complement format and can be read through the serial interface MSB first or LSB first. Figure 3.13 Output Codes versus Input Voltage 20 3.3.5 Serial Peripheral Interfaces Figure 3.14 Serial Peripheral Interfaces As I have been mention before, the communication between microcontroller and the ADC and DAC chip is based on master and slave relationship. The microcontroller act as Master and the chip act as Slave. It is a synchronous communication at which sending and receive data is in the same time with the correct clock mode. To allow such communication, some initialization has to be called before it can be used. 3.3.6 Programs Implementation I used dynamic C software to burn the program code into the microcontroller. It is C++ language which very common and easy to understand. The program burned is used to control the whole system of DAQ device allowing the users to take control of the DAQ device. LAVIEW is used to build user interface for easy exploitation of the functionality of DAQ device without the need to understand the low level language. 3.3.7 Programs Algorithms Microcontroller is the function of computing and control for the whole DAQ device. It used to taking instruction from the User Interface from PC and interpret the command and pass it to the system to do the job. As an example, from the user interface, 21 users choose to read the signal from the Analog input. The instruction is sent to microcontroller via Ethernet cable. Microcontroller receive the instruction and sent required code to analog to digital chip which enable it to read the signal from the input and sent the data to PC for display. In order to for the flow of the system to be smooth, an algorithm has to been designed which enable the DAQ device act according and response faster. The algorithm explains how the systems allowing the microcontroller take control of all the functionality of data acquisition. There are lots of consideration to be made in the algorithm, different designs are made and improved to make sure there are not even a slightly mistake could be made. Moreover, the User Interface is also a part of the system but different category since it used LABVIEW to develop. So another algorithm will be build which is specialized for User Interface. It explains the flow of the User Interfaces, showing how it is works and how it is used to send the instruction to the DAQ device. 22 START INITIALIZATION Initialize SPI Initialize clock mode Initialize Port Initialize IP address Initialize calibration data Waiting For Instruction code from User Interface NO YES Checking if the instruction is valid NO YES Execute the instruction Figure 3.15 Main Program Algorithms 23 Figure 3.16 Execution Instruction Algorithms Part 1 24 ADC INPUT Check instruction type ADC CALIBRARION Execution instruction ADC input Execution instruction ADC calibration Set GAINCODE SET INPUT CHANNEL Load value 1 Load value2 Load Voltage 1 Load Voltage 2 Save calibration Check ADC MODE UNIPOLAR BIPOLAR Run on singe ended unipolar mode DIFF Run on singe ended bipolar mode Run on differential mode Check value type VOLT RAW Display rawdata Display voltage Return Figure 3.17 Execution Instruction Algorithms Part 2 25 START Established connection Waiting user input DAC OUTPUT ADC INPUT DIGITAL INPUT DIGITAL OUTPUT CALIBRATION Set type Set type Set PORT Set PORT Set RAW VALUE Set BIT Set BIT Set VOLTAGE VALUE Set port Set value Set mode Set port Set STATE Send instruction code Figure 3.18 LABVIEW User Interfaces Algorithms 26 Figure 3.19 Figure 3.20 Connection test using Hercules LABVIEW User Interfaces 27 3.3.8 Explanation of Main Programs The flow chart shown describes how the main program works. It basically waits for the user to send the instruction from the user interface. The initialization part is the most important part of program to make the whole thing works. Figure 3.21 SPI Initialization code The program above used to initialize serial peripheral interfaces allowing microcontroller to use the SPI connection to control the ADC and DAC chip for manipulating the functionality of data acquisition system. There are some SPI connections available in the microcontroller, since I initialize SPI serial D; I have to use PORT C BIT 0 and PORT C BIT 1 for the connection. Figure 3.22 TCP/IP Connection Initialization code 28 The above program code is used to initialize the TCP connection using Ethernet port from PC to DAQ device. Without the initialize part at above program code the connection would not be able to establish since the PC does not know the IP address of the DAQ device thus no connection is being setup. Figure 3.23 Digital I/O Initialization programming code In order set digital output or digital input for DAQ device, the initialization above is coded, and every time I turn on the DAQ device, it will automatically load the previous state of the digital I/O. As an example the saved memory loaded an output state from PORT A of the microcontroller, hence the programming code above will set PORT A to digital output. Figure 3.24 Clock Initialization programming code A SPI connection require a clock to send and receive data, the clock have to be in the correct form, or else the data will not be able to receive by the ADC and DAC chip since the clock between the Master and Slave is difference. So to set the correct clock for the microcontroller that is compatible to the DAC and ADC chip, I have to write PORT E BIT 5 and BIT 4 to STATE 1 and STATE 0 respectively. 29 Figure 3.25 EEPROM save Structure To able the DAQ device load the calibration data every time it is turn on, I have to create a way which can save the data along with other information and can be extract without any difficulty. The easiest way is construct a structure, with the above structure; I can load any data I want accordingly. As for the calibration data, I save it in the variable name “ calibdata”. Under the variable, it is a structure too, containing the calibration data both for ADC chip and DAC chip. Once the initialization part finish, the main programming is ready to receive instruction from user via the User Interface. The TCP connection is always listening, waiting for the user instruction. Figure 3.26 TCP listen programming code The code above used to call the connection program, and once the socket is establish, the connection will be complete and proceed to read bytes which allowing the device to read the instruction from PC via TCP connection. 30 Figure 3.27 TCP read programming code The DAQ device read the instruction from the buffer in the STATE_READ programs code shown above. The instruction is then will be processed and checked whether the instruction received is valid and executable. Once the instructions have been confirm, it will be proceed to execute instruction program. The main program will keep looping itself, letting user to take control all the time. 3.3.9 Explanation of Execution Programs According to the flow chart of execute instruction program algorithms, the function of the DAQ device consist of 6 parts which are : configure digital input, configure digital output , set DAC output, set DAC calibration data, set ADC input, set DAC calibration data. 31 3.3.9.1 DAC Output Figure 3.28 DAC main function programming code The above is showing how the programming code manipulates the DAC chip to output a desire voltage value. This is the main code for setting the voltage output from DAC chip, the main program will call the function to execute the instruction which involving DAC output. If the value type is voltage value, it will undergo calibration before send to the DAC chip, the calibration data is load from “gstFlashData” as shown as above programming code. If the value type is raw data, it will send directly to DAC chip. It is used to collect the calibration data from the DAC chip by comparing the raw data with the output voltage. “CHIPSELECT” is one of the elements for SPI connection. It allows the master to differentiate which slave is turn on at the moment. This helps the Master to control 32 more than one slave without sending the data to the wrong Slave. Since DAC and ADC chips used the same SPI connection with microcontroller, it is necessary for the Master to identify the correct chip for the correct data. “SPIWRITE” is used to send the command to the DAC chip. 3.3.9.2 ADC Input Figure 3.29 ADC calibration programming code The programs above is the function to be called when user ask to check the input signal from the channel input. According the input mode of the ADC, the program will call the calibration data from its respective address in EEPROM of microcontroller and used it to make the calibration before send to the ADC chips. Similar to DAC programs, ADC programs allows users to choose whether the output data is in raw data or voltage value, the raw data is an output of the ADC without calibration, it is used to collect data. 33 Figure 3.30 ADC output type programming code This is how the program differentiate the raw data type and voltage type from the instruction code, if the user choose raw data, result coming from the chips will not go through calibration and shown in hexadecimal format. If the users choose voltage value type, it will undergo calibration and display the voltage value. Figure 3.31 ADC fetch instruction programming code The difference between DAC and ADC chip are DAC programs only to send SPI Write as user sent it to output their desire voltage value, there is no digital signal can be read from the chips. Users can check if the DAC chip is doing its job by check the voltage coming out from the output pin. While ADC need to read back the data from ADC chip as users need to display the value of the analog signal measured. To the data display, I need to use SPI Read command to read back the contents from the register of the respective input signal. 34 3.3.9.3 ADC and DAC Calibration Figure 3.32 DAC and ADC calibration data structure The above code is use to construct a structure unit for both ADC and DAC calibration. With the help of structure, I can easily save the calibration data together with other information and extract the calibration data when it is need without disturbing other information which is saved in the EEPROM of the microcontroller Figure 3.33 DAC and ADC calibration equation Both calibration use same equation, in the for calibration data, I require the 2 voltage value and 2 raw data from the chips. From the result I have collected from the chips, the 35 calibration programs will generate 2 calibration data which are offset and gain. This 2 data will be used to calibrate the outcome from ADC and DAC chips to produce more accurate output. 3.3.9.4 Digital I/O Figure 3.34 Configure digital output programming code The DAQ device can provide digital input and output, the digital input and output is coming from the microcontroller. Since the digital input and output is from microcontroller, hence it is a straight away setup, no connection require for communication between chips to chip. “ioConfigureBit” use to setup the direction of the PORT BIT, for an example from above, it configure PORT A , BIT i into an output. As an output, it should has output bit 0 or bit 1, so do I used “ioSetBit” to set it output a digital output according to the default. Figure 3.35 Configure digital input programming code To set a digital input, I just have to change to input in the command of “ioConfigureBit” as above code. Since it take signal from outside the microcontroller, so I do not need to set the Bit value but to read from the PORT BIT to check the value of the input. 36 CHAPTER 4 RESULT AND DISCUSSION 4.1 Introduction The progress of the project has been able to achieve according to schedule. The component required has bought with the minimum budget. The schematic design for the ADC has been done. The design is based on combining the ADC chip, DAC chip and the microcontroller. In order to able the ADC chips to process negative voltage; experiment has been conducted using voltage divider with bipolar voltage at the end, I found that the negative voltage can be converted to positive first before it go into the ADC input channel. Then, the converted voltage will display in the monitor with calibrated value. Extra work has been done on programming part, the programming part supposed to done in the next semester but since there is some extra time, some part of the programming has been studied and discussed. The ADC and DAC simple program has been done to try out if the chip is functioning with the programming code. In addition, the TCP/IP connection programming has been done in half way for the DAQ device communication function. LABVIEW programming also been studied for the User Interface of DAQ device for fetching instruction code and displayed measured data. 37 4.2 Experiments on Analog Input Range This experiment is conducted to understand the signal conditioning signal using voltage divider and from the experiment, I will know the relationship between analog input range and resistor and reference voltage. The analog input scale of ADS7870 is between -0.5V to 6.0V, so in order to allow bipolar signals and signals which are out of scale able to act as an input for ADS7870, a voltage divider is used. The voltage divider use to scale down the input voltage to match the input range of ADS7870. Vadc Vdac Vin R1 Figure 4.1 R2 Circuitry Design of Signal Conditioning An experiment conducted to test the relation between the elements in the voltage divider. Through the experiment, resistor R1 and R2 and Bias Voltage can be determined correspond to the desired range of input voltage and ADS7870. 38 4.2.1 Procedure 1. Determine the desired range of input voltage and ADS7870.Sketch the linear graph. Vadc/V 5 -10 Figure 4.2 0 10 Vin/V Linear Graph with Vadc =0-5V and Vin =±10V 2. Determine the linear equation of the graph. Y= mX+C 3. Derive an equation from the voltage divider. 4. Compare the equation from step 2 and step 3. ( ) ( ……………………(1) ) ………………… (2) 5. From equation 1, Vdac can be determined while the ratio of the resistor can be obtained from equation 2 39 TABLE 4.1: Experimental Results for Vin Range -10V to 10V Calculation Result: Refer to linear graph, 5 = 0.25x + C ……………………(1) 0 = 0.25x + C ……………………(2) (1) + (2): 5 = 2C, C = 2.5 Y = 0.25x + 2.5 Compare to: : Then we can know, = 0.25 40 = 4R1 = R1 + R2 3R1 = R2 ( ) TABLE 4.2: Experimental Results for Vin Range -20V to 20V 41 Calculation Result: Refer to linear graph, 5 = 0.125x + C ……………………(1) 0 = 0.125x + C ……………………(2) (1) + (2): 5 = 2C, C = 2.5 Y = 0.125x + 2.5 Compare to: : Then we can know, = 0.125 = 6R1 = R1 + R2 7R1 = R2 ( ) Vdac = 2.5/0.875 From the result, I can divide into 2 parts: Vin Range -10V to 10V and Vin Range -20V to 20V. The optimum voltages for Vdac are 3.33V and 2.86V respectively. The ratio of resistor values are R1: R2 = 1: 3 and 1: 7. After the input voltage pass through the signal conditioning circuitry, the value of the voltage input is ratio down into the range of allowable for the ADC chips to work which is between 0V to 5V. As the result shown, I can manipulate the reference voltage and resistor according to the input range of analog signal but to design a DAQ device which able to change the mode of the converter in a single channel input, I have to fix on the value on the resistor and manipulate the value of reference voltage according to the mode of ADC channel input 42 4.3 Comparison of DAC Output Voltage This experiment is carried out to show the difference between the actual voltage value and the calculated voltage value. If the value from actual voltage and calculate voltage is the same, then it will not necessary to make calibration on DAC chips This experiment conducted by sending the instrument code to DAC chips to output the voltage value as the instrument code is in hexadecimal format. Code contains the value of voltage which I desired for the output. The table below shows the result on the experiment TABLE 4.3: Experimental Results of Output Voltage DAC comparison outpu t outA outB outC outD outE outF outG outH hex 0x0A0 0 0x150 0 0x220 A 0x390 0 0x4F0 A 0x5FF F 0x6B0 0 0x770 0 dec 256 0 128 0 522 230 4 385 0 409 5 281 6 179 2 internal Vref= 2.04V calculation result/ /V V internal Vref= 1.04V calculation result/ /V V external Vref=1.76V calculation result/ /V V 2.55 2.56 1.28 1.28 2.2 2.16 1.28 1.28 0.64 0.64 1.1 1.08 0.52 0.52 0.26 0.24 0.45 0.48 2.3 2.28 1.15 1.12 1.98 2.76 3.84 3.92 1.92 1.92 3.31 4.28 4.08 4.16 2.04 2.08 3.52 3.66 2.81 3.88 1.4 1.4 2.56 2.56 1.79 1.8 0.91 0.88 1.54 1.6 43 The experiment tested using different kind of reference voltage. There are huge difference between the actual value and calculated value when I using external voltage, the rest of result also shown some slightly difference. This kind of error will actually crucial in data acquisition system. The system require to be accurate, and this is not accurate enough to compete with other highly commercialize DAQ device. In order to solve the problem, I have written the calibration program to make the input voltage exactly the same with the output voltage. 4.4 Accuracy of ADC Input Signal The accuracy of the ADC input signal is basically base on the calibration data. So this experiment is used to show the accuracy of the results after calibration. The experiment conducted at robotic lab and used power supply generator to connect to the ADC input signal in order to test the range of the ADC input signal and its accuracy. The program has set the ADC to allow three kinds of mode for data acquisition: single ended unipolar mode, single ended bipolar mode, and differential input mode. Single ended unipolar mode has the input range of 0 to 20 volt after signal conditioning circuit has been added. While single ended bipolar mode has the input range from -10 volts to +10 volts. Finally for the differential mode has the input range from -20 volts to +20 volts. 44 TABLE 4.4: Accuracy of Single Ended Unipolar Mode Actual reading/V Measured reading/V 0.12 0.01 1.12 1 2.12 2 3.12 3 4.12 4 5.12 4.99 6.12 5.99 7.12 7 12.12 11.98 16.14 15.99 18.14 17.98 20.14 19.98 TABLE 4.5: Accuracy of Single Ended Bipolar Mode Actual reading/V Measured reading/V 10.12 9.97 9.12 8.97 8.12 7.98 7.12 6.99 6.12 5.99 5.12 5 4.12 4 3.12 2.99 0.12 0.01 -1.99 -2.09 -2.99 -3.08 -4.99 -5.08 -6.99 -7.09 -9.99 -10.08 45 TABLE 4.6: Accuracy of Differential Mode Actual reading/V Measured reading/V 20 19.47 19 18.49 18 17.53 17 16.55 15 14.61 10 9.73 8 7.78 6 5.83 4 3.87 2 1.94 0 0.01 -2 -1.95 -4 -3.91 -8 -7.81 -10 -9.75 -12 -11.71 -15 -15.04 SINGLE ENDED UNIPOLAR INPUT Voltage/V 30 20 Measured reading/V 10 Actual reading/V 0 1 2 3 4 5 6 7 8 9 10 11 12 FIGURE 4.3 Graphs on Single Ended Unipolar 46 SINGLE ENDED BIPOLAR INPUT VOLTAGE/V 15 10 5 Actual reading/V 0 -5 -10 -15 1 2 3 4 5 6 7 8 9 10 11 12 13 14 Measured reading/V FIGURE 4.4 Graphs on Single Ended Bipolar DIFFERENTIAL INPUT VOLTAGE/V 20 10 0 -10 Actual reading/V 1 3 5 7 9 11 13 15 Measured reading/V 17 -20 FIGURE 4.5 Graphs on Differential Input 47 From the data collected, I put in the tables shown above and convert to graph for a better analysis. As from the table, for single ended unipolar, there is a slightly different between the measured data and actual data and it is around measure voltage ±0.20 voltage. For single ended bipolar, the result is almost the same with single ended unipolar with the error of ±0.18 voltage. For differential mode, the difference is much steeper than the previous mode with error as high as ±0.40 voltage. This kind error can be reduced with a little bit effort on calibration data. I have to take more reading from the raw data of DAC and ADC chips to make a prefect calibration. From the graph, i can see that all the measured data and actual data line up in parallel which mean the actual data is directly proportional to the measured data and both data are approximately the same. 48 CHAPTER 5 CONCLUSION AND RECOMMENDATION 5.1 Conclusion According to recent development and technology, almost all the industry machine implemented with data acquisition system. Wide range of application of data acquisition system is available in industry work such as, research and development, digital control, analysis and monitoring and so on. With the great potential of data acquisition device over the market now a day, the customer has demand more from a data acquisition device instead of having the basic requirement of data acquisition system such the most critical part is the accuracy of analog input signal. Since the main function of data acquisition is used to measure analog input signal, hence the accuracy, repeatability and precision of a data acquisition system must be achieved. The goal of this project is to build data acquisition device with minimum budget hence producing a low cost data acquisition device. The demand from industry has pushed the recent data acquisition device on the market equipped with multiple functions which is extremely expensive for student to buy for their research. In this project, I will only code the main function of data acquisition system to reduce cost. The main elements in this data acquisition device is able perform analog to digital conversion with three different mode , configuring digital input and output for control system and finally interfaces with PC for fetching instruction and display measured data. 49 To enable the data acquisition device perform analog to digital conversion with different mode , digital to analog conversion have to implement along with voltage divider to convert the input signal into a suitable range of input for the ADC chips to process. For the first mode, single ended unipolar, the DAC will not output any voltage since the range of the mode is 0 volts to 20 volts, it only need to pass through the voltage divider to ratio down into an allowable value. For single ended unipolar and differential mode, the DAC will output a fixed voltage value to counter the bipolarity voltage signal from input. The accuracy of the data acquisition is depend on the calibration data as the noncalibrated output signal is not accurate, from the result shown, I have reduced the error until ±0.40 voltage and can be even become smaller as I have to do lot more effort on the calibration parts. The outcome of the project is achieved and the accuracy of the data acquisition device depends on the calibration data input from user. As the calibration data is more accurate, so as accuracy of the data acquisition system takes place. The schematic design has been design for ADC circuit, and some part of programming have been done for ADC and DAC chips and also communication part using TCP/IP connection. All the part from schedule has been carried out successfully. 5.2 Problems Although I have achieved the project goal but there has some problems have been encounter during the development of project. The First problems encounter is actually contrast to one of the project objective which is to build a data acquisition device in small structure , unfortunately a prototype has be built where the structure is 50 available for debugging. The prototype is built into 3 layers of PCB which widely open for debugging; hence the data acquisition device is bigger than the expected size. In additional, the other problems encounter is the wire and circuitry of data acquisition device. Debugging procedure going on , the wire and circuitry has been checked, removed, reattached, soldered again and again, hence the connection become fragile and sometimes making the whole system unable to work as the connection has been cut off. Moreover, an accurate DAC and ADC chips not supposed to write a calibration program for it since the output is already accurate, but I have try out both chips and as the result, both outputs are not accurate and it is slightly off the original signal. So a calibration program has to make for an accurate output. 5.3 Recommendations The data acquisition device developed in this project still has lots more improvement to implement before it can really go on market. There some recommendation for the product for future improvement for better performance. 1) Hardware improvement The device can be built in more compact and smaller structure for portability. This can be done by changing the entire component into surface mount component and redesign the circuitry for surface mount component. With the replacement of surface mount component, the device can be constructing into a smaller structure giving convenient to customer. Beside than that, the ADC and DAC chips should be replace with a more accurate replacement, since the current chips do not give an accurate output. This can be done by searching the 51 information from the net and conduct plenty of experiment for ADC and DAC chips 2) Software improvement The user interfaces of the device is not really convenient for some user because some of the users might need to configure digital input and output or measured data in the same times, as the current user interface only allow one instruction to be run at a times. 52 WORK SCHEDULE Semester 1, Section 2012/13 Semester 2, Section 2012/13 53 REFERENCES 1. Hai Feng Zhou, J. D. D., Yuan Qing Huang (February, 2012). "Design of Data Acquisition and LED Display System." Advanced Materials Research Automation Equipment and Systems: 863-866. 2. Ning, Y., Z. Guo, et al. (2012). "Design of Data Acquisition and Storage System Based on the FPGA." Procedia Engineering 29(0): 2927-2931. 3. Hai Feng Zhou(February, 2002). "Design of Data Acquisition and LED Display System." Advanced Materials Research Automation Equipment and Systems: 863-866. 4. Hemond, B. D., Wahab, A. A.(2001). MICA: an innovative approach to remote data acquisition. IEEE Instrumentation & Measurement Magazine, 15(5), 22-27. 5. Mohamad-Ali, B. S., & Maree, A. H. (1999). Low cost medical data acquisition system using AVR-MCU and PC. Journal Of Theoretical And Applied Information Technology, 42(2), 217-220. 6. Ning, Y., Z. Guo, et al. (2001). "Design of Data Acquisition and Storage System Based on the FPGA." Procedia Engineering 29(0): 2927-2931. 7. Wu, Z., Shan, J.F. 2002). “A new real time data acquisition system for low hybrid current drive system。” Advances in Intelligent Systems and Computing:Pages 299-303 8. http://www.vtiinstruments.com/Data-Acquisition-Signal-Conditioning.aspx 9. http://physweb.bgu.ac.il/COURSES/SignalNoise/data_aquisition_fundamental.pdf 54 Appendix A PARTS OF ADC PROGRAMMING CODE 55 56 57 Appendix B SCHEMATIC DESIGN OF ADC 58 Appendix C PCB DESIGN OF TINY DAQ 59 60 Appendix D CASING DESIGN OF TINY DAQ 61 Appendix E LAVIEW DESIGN OF TINY DAQ USER INTERFACE 62 Appendix F STRUCTURE OF TINY DAQ 63 REFERENCES 1. Hai Feng Zhou, J. D. D., Yuan Qing Huang (February, 2012). "Design of Data Acquisition and LED Display System." Advanced Materials Research Automation Equipment and Systems: 863-866. 2. Ning, Y., Z. Guo, et al. (2012). "Design of Data Acquisition and Storage System Based on the FPGA." Procedia Engineering 29(0): 2927-2931. 3. Hai Feng Zhou(February, 2002). "Design of Data Acquisition and LED Display System." Advanced Materials Research Automation Equipment and Systems: 863-866. 4. Hemond, B. D., Wahab, A. A.(2001). MICA: an innovative approach to remote data acquisition. IEEE Instrumentation & Measurement Magazine, 15(5), 22-27. 5. Mohamad-Ali, B. S., & Maree, A. H. (1999). Low cost medical data acquisition system using AVR-MCU and PC. Journal Of Theoretical And Applied Information Technology, 42(2), 217-220. 6. Ning, Y., Z. Guo, et al. (2001). "Design of Data Acquisition and Storage System Based on the FPGA." Procedia Engineering 29(0): 2927-2931. 7. Wu, Z., Shan, J.F. 2002). “A new real time data acquisition system for low hybrid current drive system。” Advances in Intelligent Systems and Computing:Pages 299-303 8. http://www.vtiinstruments.com/Data-Acquisition-Signal-Conditioning.aspx 9. http://physweb.bgu.ac.il/COURSES/SignalNoise/data_aquisition_fundamental.pdf