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.
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]
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.
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
- Popular Resources
- Popular amplifiers
- Virtualization Technology Practice Guide - High-efficiency and low-cost solutions for small and medium-sized enterprises (Wang Chunhai)
- usb_host_device_code
- 100 Examples of Microcontroller C Language Applications (with CD-ROM, 3rd Edition) (Wang Huiliang, Wang Dongfeng, Dong Guanqiang)
- Arduino Nano collects temperature and humidity data through LabVIEW and DHT11
- Keysight Technologies Helps Samsung Electronics Successfully Validate FiRa® 2.0 Safe Distance Measurement Test Case
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Seizing the Opportunities in the Chinese Application Market: NI's Challenges and Answers
- Tektronix Launches Breakthrough Power Measurement Tools to Accelerate Innovation as Global Electrification Accelerates
- Not all oscilloscopes are created equal: Why ADCs and low noise floor matter
- Enable TekHSI high-speed interface function to accelerate the remote transmission of waveform data
- How to measure the quality of soft start thyristor
- How to use a multimeter to judge whether a soft starter is good or bad
- What are the advantages and disadvantages of non-contact temperature sensors?
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Which one has faster sampling speed, ADS1220 or AD7799?
- 2005 National Undergraduate Electronic Design Competition Topic
- EEWORLD University----[High Precision Laboratory] Interface: HDMI
- How to Make DSP Digital Oscillator Generate Phase-Shifted Sine Wave
- WIFI 6 is coming, do you know about it?
- Discuss one of the STM32H750
- Book an appointment to win a gift: Book an appointment for the live broadcast of power integrity design of ideal power distribution network, gain knowledge and win a Keysight gift
- The first article GD32VF103C START development board unboxing running lights
- How to eliminate the influence of gravity acceleration on accelerometer
- MSP430 programmer and emulator