AVR-USB DATA ACQUISITION

2011 3rd International Conference on Electronics Computer Technology (ICECT 2011) AVR-USB DATA ACQUISITION 1 1 Nanda Kumar Lakkoju, 2Sateesh Gudla, ...
Author: Blanche Austin
8 downloads 1 Views 1MB Size
2011 3rd International Conference on Electronics Computer Technology (ICECT 2011)

AVR-USB DATA ACQUISITION 1 1

Nanda Kumar Lakkoju, 2Sateesh Gudla, 3Bhanu Sridhar Mantravadi

RAGHU’S CENTER OF EXCELLENCE IN EMBEDDED SYSTEMS DESIGN, 1 [email protected] 23 Department of Computer Science and Engineering, 2 [email protected] [email protected] 123 RAGHU ENGINEERING COLLEGE, Visakhapatnam, A.P. INDIA

Abstract – Several industrial operations in monitor control and command applications use data acquisition, where data from the external world is read, processed, used for decisions and, eventually, memorized by a digital system. Here data acquisition system with USB interface is considered. Using add-on serial to USB convertors, an existing system can be made USB interfaced or the complete system can be redesigned using new generation microcontroller with inbuilt USB hardware stack. This paper describes a low-cost data acquisition system that includes Software-defined open source USB stack over generic ATmega32 microcontroller, having analog channels and digital I/O lines and a temperature sensor. At PC side, GUI application is designed using .NET with Instrumentation Active-x Controls to acquire and monitor data and control all system I/O. The system hardware developed is a low-cost alternative to commercially available systems that use USB controllers. The work has been implemented for temperature sensing and controlling and the results shown currently support the h/w and s/w developed. It can be used for biomedical analysis, industrial temperature loggers, industrial process, instrumentation controls and the like.

Keywords— USB Data acquisition, AVR-USB, software defined USB, LibUsb-win32, instrumentation controls, temperature controller. I.

INTRODUCTION

The use of electronic equipment has been growing rapidly. Electronic systems controlled by software have marked great strides in today’s rapidly changing environment. New electronic equipment with lots of enhanced features can be easily embedded using software and can be made to work efficiently. However, this requires careful monitoring besides the presence of the user. Some examples are: systems for monitoring parameters such as temperature, pressure in closed spaces, systems for commanding different execution elements, data logging systems and the like. A wide-spread operation found in the above applications is data acquisition[l]. Data from the external world is read, processed, used for decisions and eventually, memorized. The digital systems may be PCs with dedicated interfaces through which a good user-friendly environment can be provided.

978-1-4244-8679-3/$26.00 C 2011 IEEE

There are different ways of connecting a microcontroller based system to a PC: the ISA or PCI connector, the serial port, the parallel port, or the USB port. USB based data acquisition systems can be developed using USB controllers like ISP1181 connected to P89c51RD2 microcontroller [1] , using PICI6F877 microcontroller [2] or using FT232/245BM USB interface chip to microcontroller [11,12]. Unlike the above mentioned systems our proposed system uses ATmega32 with software defined USB stack. This paper describes low-cost data acquisition hardware with USB interface basing on the ATmega32 microcontroller. First, a short review on USB has been discussed. Second, the developments of the system and a brief on hardware and software resources used have been discussed. This is followed by system integration and validation results. Finally conclusions and the development directions are given. II.

USB IN BRIEF

USB is a serial bus conceived for an easy and expandable way for connecting peripherals to PC. Its final purpose is to establish the unique interface for the PC peripherals. Similarly different peripherals are connected with the same cables and connectors. The specific features of each peripheral are assumed by the software. USB divides the serial compatible equipments into 2 classes: hubs and functions. A hub has connections, called ports, where the functions may be connected. A function is a peripheral equipment which achieves a certain type of operations.USB Speeds are High Speed - 480Mbits/s, Full Speed - 12Mbits/s and Low Speed - 1.5Mbits/s. USB specification defines four transfer/endpoint types, Control Transfers, Interrupt Transfers, Isochronous Transfers and Bulk Transfers. The Universal Serial Bus is host controlled. There can only be one host per bus. The USB host is responsible for undertaking all transactions and scheduling bandwidth. One of the original intentions of USB is to reduce the amount of cabling behind the PC. USB as its name suggests is a serial bus. It uses 4 shielded wires of which two are powered (+5v and GND).The remaining two is a twisted pair differential data signals. . It uses an NRZI (Non-Return to Zero Invert) encoding scheme to send data with a sync field to synchronize the host and receiver clocks. USB supports plug-n-plug with dynamically loadable and unloadable drivers. The user simply plugs the device into the bus. The

V1-35

2011 3rd International Conference on Electronics Computer Technology (ICECT 2011)

host detects this addition, interrogates the newly inserted device and loads the appropriate driver all in the time it takes for an hourglass to blink on your screen provided a driver is installed in the device. The end user need not worry about terminations, terms such as IRQs and port addresses, or rebooting the computer. Once the user is finished, they can simply plug the cable out; the host will detect its absence and automatically unload the driver. The loading of the appropriate driver is done using a PID/VID (Product ID/Vendor ID) combination. There are commonly two types of connectors, called type A and type B as shown in Figure 1. Type ‘A’ plugs always face upstream. Type B plugs are always connected downstream and consequently type B sockets are found on devices.

Figure 2(b): Low Speed USB wiring.

Enumeration is the process of determining what device has just been connected to the bus and what parameters it requires such as power consumption, number and type of endpoint(s), class of the product and the like. The host then assigns the device an address and enables a configuration allowing the device to transfer data on the bus. III.

Figure 1 .USB Connector Types.

A USB device indicates its speed by pulling either the D+ or D- line high to 3.3 volts [3, 4]. A full speed device, pictured in figure 2(a) uses a pull up resistor attached to D+ to specify itself as a full speed device. And in figure 2(b) a pull up resistor is attached to D- to specify itself as low speed device. These pull up resistors at the device end will also be used by the host or hub to detect the presence of a device connected to its port. Without a pull up resistor, USB assumes there is nothing connected to the bus. Some devices have this resistor built into its silicon, which can be turned on and off under firmware control. Others require an external resistor. All USB devices have a hierarchy of descriptors which describe to the host information such as what the device is, who makes it, what version of USB it supports, how many ways it can be configured, the number of endpoints and their types and the like. The more common USB descriptors are Device Descriptors, Configuration Descriptors, Interface Descriptors, Endpoint Descriptors and String Descriptors.

SYSTEMS DESIGN

Figure 3 shows the block diagram of AVR-USB Data Acquisition System developed. It uses familiar microcontroller from ATMEL AVR® series called ATmega32 [6] as the heart of the system. It has 32 general I/O lines from which 5 I/O lines are configured as output port for controlling AC loads via the relay driving stage and electromechanical relays, 4 I/O lines are configured as input lines for monitoring any open/close mechanical switches via use of magnetic REED switches. One–wire TM DS1820B [5] digital temperature sensor is connected to port B.1 (PB1) and finally an 8 channel ADC of ATmega32 is used to connect sensors (sensors that provide varying voltages with the change of physical quantity) like thermocouples, pressure , humidity and the like. A simple 5 volt regulated power is used to run the system. The developed system acquires physical phenomenon temperature from DS1820, voltage variations from different ADC channels and several other parameters can also be controlled and monitored using digital I/O sources.

Figure 2(a): Full Speed USB wiring.

Figure 3. The block diagram of AVR-USB Data Acquisition System.

V1-36

2011 3rd International Conference on Electronics Computer Technology (ICECT 2011)

USB interface is made by making use of port D i/o lines by which USB communication is established with desktop computer. For USB device drivers, the system makes use of an open source LibUsb-win32 generic drivers. PC side GUI applications written in C# .NET acquire parameters from data acquisition systems for monitoring and analysis. IV.

HARDWARE DESIGN

Figure 4 Shows the USB interface that has been adapted by making use of PD0, PD1, and PD2 of ATmega32 microcontroller. A 1.5 K ohm pull up resistor is attached to 5v data line from PD0. This line is used as D- and it results in low speed USB interface. The PD1 and PD2 are shorted and have a series resistor connected, which is configured as data line D+. The USB interface lines are connected to pins 2 and 3 (D- and D+ channels) of USB B Type connector, where the speed of the interface is 1.5Mbits/s max.

ADC =

Vin × 1024 Vref

where Vin is the voltage on the selected input pin and Vref the selected voltage reference on AREF pin. B. One-wire TM Digital thermometer DS1820 The DS18S20 [5] digital thermometer provides 9-bit Celsius temperature measurements and communicates over a 1-Wire bus that by definition requires only one data line (and ground) for communication with a central microprocessor. It has an operating temperature range of – 55°C to +125°C and is accurate to +/- 0.5°C over the range of –10°C to +85°C. In addition, the DS18S20 can derive power directly from the data line (“parasite power”), eliminating the need for an external power supply.

Figure 5. DS18s20 Digital Thermometer Connections to ATmega32.

Figure 4. Wiring diagram for low speed USB interface with ATmega32.

A. ATmega32 microcontroller The ATmega32 [6] is a low-power CMOS 8-bit microcontroller based on the AVR enhanced RISC architecture. By executing powerful instructions in a single clock cycle, the ATmega32 achieves 16MIPS throughput at 16MHZ .The AVR core combines a rich instruction set with 32 general purpose working registers. All the 32 registers are directly connected to the Arithmetic Logic Unit (ALU), allowing two independent registers to be accessed in one single instruction executed in one clock cycle. The ATmega32 provides the following salient features: 32K bytes of In-System Programmable Flash Memory, 1k bytes EEPROM, 2K byte SRAM, 32 general purpose I/O lines, On-chip Debugging support, three flexible Timer/Counters with compare modes, Internal and External Interrupts, a serial programmable USART, an 8-channel 10-bit successive approximation ADC, a programmable Watchdog Timer with Internal Oscillator, an SPI serial port, and six software selectable power saving modes. ATmega32 provides a highly-flexible and cost-effective solution to many embedded control applications. The ADC converts an analog input voltage to a 10-bit digital value through successive approximation. The minimum value represents GND and the maximum value represents the voltage on the AREF pin minus 1 LSB. The ADC generates a 10-bit result which is presented in the ADC Data Registers, ADCH and ADCL. With single ended conversion technique [1, 6] ADC resultant value is

AVR-USB data acquisition uses DS18s20 to measure temperature connected to PD4 of host microcontroller as shown in Figure 5. C. Other resources PB0 to PB4 pins are configured as digital outputs to connect Relays. Eight array Darlington transistor based driving IC ULN 2803 is used to energize these relays. PC0 to PC3 are configured as digital inputs to connect magnetic switches, REED switches and the like. 16 char by 2 lines LCD is also used in the proto model to display temperature and other measurement strings. The finished proto model hardware developed is pictured in the Figure 6.

V1-37

2011 3rd International Conference on Electronics Computer Technology (ICECT 2011)

and the like. Also the screenshot of .NET application for temperature controller is shown in Figure 7(b). All this graphical representation uses

Figure 6: Proto model of AVR-USB Data Acquisition System developed.

V.

SOFTWARE INTEGRATION

AVR-USB Data Acquisition System software is defined in three sections: A. Microcontroller firmware The firmware in the data acquisition system is responsible to carry out the USB communication (uses Virtual USB Protocol implementation), One–wire TM communication, reads temperature, analog channels and also responds to PC application requests. Virtual USB is a software defined implementation of a low-speed USB device for Atmel’s AVR® microcontrollers, making it possible to build USB hardware with almost any AVR® microcontroller, without using any additional chip. [7].The firmware is written using AVR GCC-C language and is compiled using WinAVR compiler. The resultant Object file in Hex format is used for microcontroller Flash programming.

Figure 7(a): GUI form of.NET application with IOCOMP instrumentation controls, showing analogue voltage variations, input status, and temperature.

Instrumentation pack Active-x controls IOCOMP [9] for .NET winforms and ZedGraph [10] plots. It is an added advantage that provides eye catching Graphical view. The .NET application developed makes use of ICsharpcodeLib, a wrapper (in C#.NET) around for LIbusbwin32 USB driver to access USB devices from C#.NET applications.

B. USB Drivers The open source Libusb-win32-device driver [8] is used as the device driver for windows XP operating system. It includes libusb0.sys and libusb0.dll.The driver information file (simple text file in .INF extension) is also required for the operating system to identify the device and install the above mentioned files during enumeration process [3]. The information file can be created with the help of Notepad or libusb-inf-wizard and the file can be saved the file with .INF extension. Vendor ID, Product ID and other device values that have been considered for creating INF file are: VID: “0c7d” PID: “0006” Device name: “USB-DAS”. Graphical User Interface Figure 7(a) show the screenshot of .NET winforms application developed having graphical representation with barometer like object to indicate temperature, configurable gauge meter controls to represent analogue voltage variations

Figure 7(b): GUI form of .NET application with ZedGraph , showing temperature versus time

VI.

RESULTS AND SYTEM VALIDATION

At PC side, the acquired temperature value is analyzed using the GUI application developed, for monitoring the temperature and controlling the heater, is connected to Relay2. Current temperature, relay status and switching threshold values with respective to time interval of one second are graphically represented in GUI application as shown in Figure 7(b). The results obtained are satisfactory.

V1-38

2011 3rd International Conference on Electronics Computer Technology (ICECT 2011)

REFERENCES

Figure 8: System validation report.

For validating the system performance, a software-based USB analysis tool “USBlyzer” is used to view USB device descriptors and it captures and analyzes USB devices activity in real time. It also enables to save captured data for later protocol analysis. USBlyzer not only shows a raw hex dump of the data that is sent to or received from a USB device, but also looks at that data and decodes it into human readable form. It analyzes the system and reports the results that include USB properties, device descriptors, configuration descriptors, data transfer status and the like. A sample screenshot of the validation report generated for the system is shown in Figure8. A satisfactory result has been reported with this tool.

[1]. Popal,M.; Marcu,M.; Popa,A. S. “A microcontroller based data acquisition system with USB interface”, Electrical, Electronic and Computer Engineering,2004. ICEEC [2]. Park, J., Mackay, S., “Practical Data Acquisition for Instrumentation and Control”, Elsevier.2003, ISBN0750657960 [3]. Axelson, J. , “USB Complete: Everything You Need to Develop Custom USB Peripherals”, Lakeview Research, 2001, ISBN 09655081958 [4]. Craig Peacock, USB in a nut shell - Technical document from http://www.beyondlogic.org [5]. DS18s20 High-Precision 1-Wire Digital Thermometer - Technical document - 19-5474; Rev 8/10 Dallas semiconductor maxim. [6]. ATMEL AVR ATMEGA32 datasheets – ref no: 2503O–AVR–07/09. From http://www.atmel.com [7]. V-USB is a software-only implementation of a low-speed USB device for ATMEL AVR® microcontrollers from http://www.obdev.at/products/vusb/index.html [8]. LIBUSB-win32 USB drivers from http://sourceforge.net/projects/libusb-win32 [9]. IOCOMP instrumentation activex controls for .NET winforms from http://www.iocomp.com [10]. .NET integrated charts and graphs provided from http://www.zedgraph.org [11]. Ziad Salem, Ismail Al Kamal, Alaa Al ,Bashar “A Novel Design of an Industrial Data Acquisition System” --0-7803-9521-2/06 IEEE 2006. [12]. S. Thanee S. Somkuarnpanit and K. Saetang -FPGA-Based Multi Protocol Data Acquisition System with High Speed USB Interface. ISSN: 2078-0958 IMECS2010. [13]. Arnold S. Berger, Embedded System Design: AnIntroduction to processes, tools and techniques, CMP books,2002. [14]. Dhananjay V. Gadre, Programming and Customizing the AVR Microcontroller, McGraw-Hill, 2001.

VII. CONCLUSION The system hardware developed is a low-cost alternative to commercially available systems that use USB controllers. Using a unique combination of hardware and software with optimum utilization of the resources, a low cost Data Acquisition System has been developed to monitor voltage variations from analog channels, for temperature controlling and the like. The results shown currently support the h/w and s/w developed. Further, this system can also be used to increase the USB transfer speed. There is a possibility of continuous development of the software which can be adapted to various transducers, to calculate and display various parameters. ACKNOWLEDGMENT We express our sincere and profound gratitude to Sri Raghu Kalidindi, Chairman of Raghu Educational Institutions and Sri S. Veerabhadraiah, Director, Raghu’s Centre of Excellence, for their encouragement in providing necessary lab and resources to carry out this research work. We also thank Dr. Edmund P. Samuel, Mrs. N. Dattasri and Mr. S. Satynarayana for their continuous support.

V1-39