Implementation of USB Real-time Data Acquisition and Processing System Based on LabVIEW

Publisher:幸福时光Latest update time:2013-11-08 Source: dzscKeywords:LabVIEW Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

  Universal Serial Bus (USB) is a new type of data communication interface that is being used in more and more fields. Compared with traditional PCI cards and ISA cards , data acquisition cards based on USB interfaces have the advantages of plug-and-play, hot-swap, fast transmission speed, strong versatility, easy expansion and high cost performance.

  USB applications are generally written in Visual C++ and are relatively complex. LabVIEW is a programming language based on graphical programs, which contains a wealth of subroutines such as data acquisition, data signal analysis, and control. Users use the method of creating and calling subroutines to write programs, making the created programs modular, easy to debug, understand, and maintain, and the program programming is simple and intuitive. Therefore, it is particularly suitable for data acquisition and processing systems. Using it to compile USB applications, the data acquisition system that closely combines LabVIEW language and USB bus will integrate the advantages of both. The USB bus can realize real-time and high-speed acquisition of external data, and after the acquired data is transmitted to the host, the data display, analysis, and storage can be smoothly realized through the functional modules of LabVIEW.

  1. USB and its application in data acquisition equipment

  Since its debut at Comdex in 1995, USB has been widely supported by various PC manufacturers. Almost all PCs produced now are equipped with USB interfaces, and popular operating systems such as Microsoft's Windows 98, NT, Mac OS, and Linux have added support for USB. USB has the main advantages of fast speed, easy device installation and configuration, easy expansion, bus power supply, and flexible use, and its application is becoming more and more widespread.

  A practical USB data acquisition system hardware generally includes 微控制器\'); companyAdEventShow(this,\'companyAdDiv\',[5,18])">a microcontroller , a USB communication interface, and A/D converters, EPROMs, SRAMs, etc. added according to system needs. In order to expand its use, multi-way analog switches and digital I/O ports can also be added. The design of the system's A/D and digital I/O can follow the traditional design method, and select appropriate chips based on the acquisition accuracy, rate, number of channels and other factors. When designing, full attention should be paid to anti-interference, especially for A/D acquisition. There are two ways to choose a microcontroller and USB interface: one is to use an ordinary single-chip microcomputer plus a dedicated USB communication chip; the other is to use a single-chip microcomputer with USB communication function. Another major advantage of USB is that it can be bus-powered. In data acquisition equipment, the power consumption channel is not large, so it can be designed to be bus-powered.

  The software of a USB device generally includes the host driver, application program and firmware written into ROM. Windows 98 provides a variety of USB device drivers, but there is no one specifically for data acquisition systems, so drivers must be compiled for specific devices. Although the system has provided many standard interface functions, compiling drivers is still the most difficult thing in USB development. Usually, Windows DDK is used for implementation, but now many third-party software manufacturers provide a variety of generation tools, such as Compuware's Driver Works, Blue Waters' Driver Wizard and other software that can easily generate high-quality USB drivers. The compilation of microcontroller programs is also difficult, and no manufacturer provides automatic generation tools. Compiling a stable and complete microcontroller program is directly related to the performance of the device and must be given full attention. The above two programs are of concern to developers, but users are not very concerned. Users are concerned about how to efficiently operate the device through the mouse and how to process and analyze the large amount of data collected. Therefore, there must also be high-quality user software. User software must have a friendly interface, powerful data analysis and processing capabilities, and an interface for users to redevelop.

  2. Calling LabVIEW and its external dynamic link library

  LabVIEW is a virtual instrument programming language based on graphical programs developed by National Instruments (NI) of the United States. It has been widely used in test and measurement, data acquisition, instrument control, digital signal analysis, factory automation and other fields. LabVIEW programs are called virtual instrument programs (VI for short), which mainly include two parts: the front panel (i.e., human-machine interface) and the block diagram program. The front panel is used to simulate the panel operation of a real instrument, and can set input values, observe output values, and realize the display of charts, texts, etc. The block diagram program is written in a graphical programming language, which is equivalent to the source code of a traditional program. It is used to transmit the command parameters input by the front panel to the instrument to perform the corresponding operation. The powerful function of LabVIEW lies in its hierarchical structure. Users can call the created VI program as a subroutine to create a more complex program, and the calling order can be arbitrary. LabVIEW's method of creating and calling subroutines makes the created program modular, easy to debug, understand and maintain. The LabVIEW programming method is different from the traditional programming method. It has the characteristics of a flowchart programming language and is free from the constraints of the linear structure of traditional programming languages. The execution order of LabVIEW is determined by the flow of data between block diagrams, instead of executing line by line like general programming languages. When writing a block diagram program, you only need to select different function icons from the functional modules, and then connect them with lines to achieve data transmission.

  Although LabVIEW has interface card drivers and management programs, they are mainly for cards produced by NI itself. For ordinary I/O cards, they cannot be directly applied by LabVIEW, and other methods must be adopted. Among them, the PortIn and PortOut functions of LabVIEW can be used, but this method is simple to apply and cannot implement more complex interface functions. With the dynamic link library, appropriate programs can be written according to specific needs, and the various functions of LabVIEW can be flexibly utilized. Users can write DLLs by themselves to realize the link between LabVIEW and hardware. When compiling a dynamic link library with VC++6.0, the DLL framework is generated first. AppWizard will automatically generate project files, but no code is generated. All codes need to be typed by the user. The files required by DLL are: ①h function declaration file; ②c source file; ③def definition file. The function of the H file is to declare the function prototype to be implemented by the DLL for use in DLL compilation, and also for application compilation. The C file is the source file that implements the specific file. It has an entry point function. When the DLL is called for the first time, some initialization work is done. In general, users do not need to do any initialization work, just keep the entry point function framework. The def file is a special file in the DLL project. It is used to define which functions the DLL project will export. Only the functions listed in this file can be called by the application function. The function names to be exported are listed under the EXPORTS keyword in this file.

  3. Single photon acquisition system based on AN2131Q

  The acquisition system was developed by the author and used in the single photon counting seed activity rapid detector. It mainly consists of a photomultiplier tube (PMT) that converts photon signals into electrical signals and its auxiliary circuits and a USB acquisition card based on AN2131Q. PMT and its auxiliary circuits such as preamplifier , amplifier, and discriminator can convert weak photon signals into 15ns standard TTL pulse signals. The pulse signals are processed by frequency division and then collected by USB, which transmits the collected results to the host for processing in real time.

  3.1 USB capture card hardware components

  The acquisition card consists of 控制器\'); companyAdEventShow(this,\'companyAdDiv\',[5,18])">a microcontroller , a USB communication interface, a host, and a digital I/O port, as shown in Figure 1.

Hardware composition of USB capture card

  The author has designed a single-chip solution for synchronous transmission, using the USB design with built-in microprocessor - EZ-USB AN2131Q. It is an 80-pin USB chip with an embedded microcontroller from Cypress, which contains three 8-bit multi-function ports, an 8-bit data port, a 16-bit address port, two USB data ports, two 16-bit timer/counters and other input and output ports. It uses a solution based on internal RAM, allowing customers to continuously set and upgrade at any time without being restricted by the number of ports, buffer size, transmission speed and transmission mode. An enhanced 8051 microcontroller is embedded in the chip, and its 4-clock cycle makes it 3 times faster than the standard 8051. The count value of the microcontroller is transmitted to the host in real time using synchronous transmission, while the host's control signal for the counter is transmitted using block transmission. EZ-USB is a USB development system launched by Cypress, which provides a good integrated solution for USB peripherals. EZ-USB has done a lot of tedious and repetitive work in its core, which simplifies the development code and shortens the development cycle. In addition, the developer also provides supporting development software (including compilation software uVision 51, debugging software dScope 51, control software EZUSB Controll Panel) and driver GPD (General Purpose Driver) interface to facilitate user development and use. [page]

  3.2 Software composition of USB acquisition card

  In the USB firmware, two transmission modes are adopted: isochronous transactions and bulk transactions. The isochronous mode is used to transmit the collected data in real time, and the bulk transaction is mainly used to transmit the host command signal and USB status information. Endpoint 2 is used in the bulk transaction. The core interrupt programs of the two transmission modes are as follows:

  void ISR_Sutok(void)interrupt 0 //Block transfer mode

  {

  //initialize the couters in the 8051

  TMOD=0x05;

  TCON=0x10;

  TH0=0;

  TL0=0;

  Thb=0,

  TH0=0;

  TL0=0;

  thb=0;

  EZUSB_IRQ_CLEAR();

  USBIRQ=bmSUTOK; //Clear SUTOK IRQ

  }

  void ISR_Sof(void)interrupt 0 //Synchronous transmission mode

  {

  if(TCON&0x21){ //Deal with the counter overflow

  TH0=0;

  Tl0=0;

  THB++;

  TCON&=0xdf;}

  IN8DATA=TH0; //3 Bytes counter result

  IN8DATA=TL0;

  IN8DATA=THB;

  EZUSB_IRQ_CLEAR();

  USBIRQ=bmSOF; //Clear SOF IRQ

  }

  In the LabVIEW application, a Usb.dll file is designed as the driver for LabVIEW and USB. Since the EZ-USB development system has provided the underlying driver (GPD) interface functions, users only need to call these functions to connect to the USB device. Therefore, in the compilation of the DLL, only the functions provided by it need to be called, which greatly saves development time and improves development speed. The created Usb.dll file contains the following five output functions, and the functional descriptions are shown in Table 1.

  Table 1 Function description of functions included in Usb.dll

Control The host controls the USB device.
ReadResult Gets the data sent from the USB to the host.
StartIsoStream Starts the isochronous transfer stream of the device.
StartThread Gets the device descriptor of the standard device.
StopThread Closes the isochronous transfer stream of the device.

  Its definition is as follows:

  LPSTR_declspec(dllexport)_stdcall Control(int input);

  int_declspec(dllexport)_stdcall ReadResult(void);

  int_declspec(dllexport)_stdcall StartIsoStream(void);

  int_declspec(dllexport)_stdcall StartThread(void);

  int_declspec(dllexport)_stdcall StopThread(void);

  The process of turning on the device and acquiring collected data is shown in Figure 2. Its main functions include: turning on or off USB devices, detecting USB devices, setting USB data transmission pipes and endpoints, collecting data from the USB interface in real time, and displaying and analyzing data. [page]

Flowchart for starting the device and obtaining collected data

  Figure 2 Flowchart of starting the device and acquiring collected data

  After the program is successfully compiled in the VC++6.0 environment, the DLL file is automatically generated. When calling, open the FunctionPalette (function template) in the block diagram program window. The Advanced module contains the call module for the library function, namely CallLibraryFunction. Put the compiled DLLs in the current directory or a specific directory. Place the function call module in the function template, then select Configure, and a dialog box will appear. According to the parameter correspondence between LabVIEW and DLLs, fill in the path of the DLL file (the DLL file is not in the current directory), the name of the called function, the type of the parameter and the return type. It should be noted that when calling multiple functions, the number of parameters and the corresponding type must be filled in separately, and the data bits should be kept consistent during the calling process. After filling in and selecting the OK button, LabVIEW will automatically generate the entry and exit status of each parameter, thus realizing the call between LabVIEW and DLLs.

  The above method successfully realizes the data exchange between LabVIEW and USB driver, thus realizing the USB real-time acquisition processing system with LabVIEW as the application program. After adding A/D or D/A to the USB acquisition card and making corresponding changes to the circuit, all the functions of the traditional acquisition card can be realized. Obviously, this acquisition processing system that integrates the advantages of USB interface and LabVIEW graphical programming language has incomparable advantages compared with traditional acquisition cards. It is not only cost-effective, highly versatile, easy to develop, simple data processing, but also can greatly shorten the development time.

Keywords:LabVIEW Reference address:Implementation of USB Real-time Data Acquisition and Processing System Based on LabVIEW

Previous article:Implementation of USB Real-time Data Acquisition and Processing System Based on LabVIEW
Next article:A brief analysis of the application and development of virtual instruments in medicine

Recommended ReadingLatest update time:2024-11-16 15:35

Research on Virtual Spectrum Analyzer Based on LabVIEW
In experimental teaching in colleges and universities, traditional spectrum analyzers are commonly used to perform frequency domain analysis and measurement of signals. Traditional spectrum analyzers are generally composed of three functional modules: signal acquisition and control, analysis and processing, and result
[Test Measurement]
Research on Virtual Spectrum Analyzer Based on LabVIEW
My understanding of virtual instrument technology
I have been engaged in virtual instrument technology for many years. Although I have been engaged in other work in the past two years, I have always been paying attention to the changes in this field. I have been engaged in virtual instrument work since I was a graduate student. I mainly work on hardware, bu
[Test Measurement]
Simple USB to LVDS Interface Converter
1 Introduction The Universal Serial Bus (USB) interface is widely used for its fast communication speed, USB2.0 protocol speed up to 480 Mb/s, and hot-swap support, which alleviates the contradiction between the increasing number of PC peripherals and the limited motherboard slots and ports; and the Low-Voltage
[Power Management]
Simple USB to LVDS Interface Converter
Digital Filter Design in LabVIEW 8.2
  LabVIEW provides a variety of filters and function nodes and VIs for designing filters. The filter node is located in the "Signal Processing - Filter" of the function palette, as shown in the figure.   The digital filter node can directly process the input signal through the filter, or calculate the filter coeffic
[Test Measurement]
Digital Filter Design in LabVIEW 8.2
Do you know the USB cable and DuPont cable in your hand?
For those who are involved in low-voltage electrical work, we must have more than one USB cable and more than one DuPont cable around us, but do you understand them? When I was lighting up the 7-inch touch screen, I used a USB cable to connect to the external power supply, but it was unstable and the screen was alwa
[Microcontroller]
Do you know the USB cable and DuPont cable in your hand?
Understanding all aspects of the car USB interface
There is no such thing as free charging convenience. Engineers have come up with many solutions behind the scenes. Looking to the future, don't buy a car that does not support the USB Type-C interface. With the widespread popularity of portable electronic devices, users are increasingly charging their devices while
[Embedded]
Understanding all aspects of the car USB interface
STM32 USB IAP steps
1. Download STM32_USB-FS-Device_Lib_V3.2.1.rar 2. Install DfuSe_Demo_V3.0_Setup.exe. 3.打开...\STM32_USB-FS-Device_Lib_V3.2.1\Project\Device_Firmware_Upgrade\MDK-ARM\DFU.uvproj Modify: //#define ApplicationAddress 0x08003000 to #define ApplicationAddress 0x08004000 (because the program needs to be modified to increase t
[Microcontroller]
Design of data acquisition system based on single chip microcomputer and USB interface
In industrial production and scientific and technological research, PCs or industrial computers are often used to collect various data to obtain the required control information and experimental data. Traditional data acquisition systems mostly complete data transmission in the form of ISA, EISA or PCI cards. This meth
[Microcontroller]
Latest Test Measurement Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号