Design of a real-time data acquisition system based on USB bus
2026-04-06 05:13:17··#1
The design of this real-time data acquisition system based on Universal Serial Bus (USB) strictly adheres to the USB 1.1 protocol, fully embodying the convenience, expandability, low cost, and low interference characteristics of USB. It details the specific design of the system's USB device driver, device cores, and application programs. Modern industrial production and scientific research place increasingly higher demands on data acquisition. Currently, the most common approach is to install data acquisition cards, such as A/D cards and 422/485 cards, within PCs or industrial control computers. These data acquisition devices suffer from the following drawbacks: cumbersome installation; high cost; limited scalability due to constraints in the number of computer slots, addresses, and interrupt resources; and the inability to provide dedicated electromagnetic shielding in some high-electromagnetic-interference testing environments, leading to data distortion. Universal Serial Bus (USB) is a new serial communication standard promoted in 1995 by companies such as Compaq, Microsoft, IBM, and DEC to address the shortcomings of traditional buses. This bus interface offers advantages such as easy installation, high bandwidth, and easy expansion, and has gradually become the trend in modern data transmission. The USB-based data acquisition system fully utilizes these advantages of the USB bus, effectively solving the shortcomings of traditional data acquisition systems. 1 System Hardware Design 1.1 Overall Hardware Structure The USB real-time data acquisition system hardware module includes an A/D converter, a microcontroller, a USB communication interface, and a multiplexer. The overall hardware structure is shown in Figure 1. 1.2 USBN9602 Chip The USB interface chip uses a dedicated chip from National Semiconductor, the USBN9602. This chip integrates a microprocessor interface, FIFO memory, clock generator, serial interface engine (SIE), transceiver, and 3.3V voltage converter, supporting DMA and microwave interfaces. Its internal structure is shown in Figure 2. The microcontroller transmits the A/D acquired data through an 8-bit parallel interface, storing it in the FIFO memory. Once the FIFO is full, the SIE immediately processes the data, including: synchronization mode recognition, parallel/serial conversion, bit stuffing/destuffing, CRC generation and verification, address recognition, handshake response and generation, and USB special event (Reset, Suspend, Resume) detection. Finally, the transceiver transmits the data to the PC via data lines (D+, D-). The above process strictly adheres to the USB 1.1 protocol. The specific implementation circuits of USBN9602 and 89C52 are shown in Figure 3. 2. System Software Design System software includes USB device drivers, device firmware, and application programs. 2.1 USB Device Driver Development The USB system driver adopts a layered structure model: a higher-level USB device driver and a lower-level USB function layer. The USB function layer consists of two parts: a higher-level Universal Serial Bus Driver Module (USBD) and a lower-level Host Controller Driver Module (HCD). Their hierarchical relationship is shown in Figure 4. In the above USB layered modules, the USB function layer (USBD and HCD) is provided by Windows 98 and is responsible for managing the communication between the USB device driver and the USB controller; loading and unloading the USB driver; and communicating with the USB device universal endpoint to perform bidirectional conversion tasks for device configuration, data, and USB protocol framework and packet format. Currently, Windows 98 provides various USB device drivers, but not specifically for real-time data acquisition devices. Therefore, a dedicated USB device driver needs to be designed using the DDK development tool. This can be implemented by four modules: an initialization module, a plug-and-play management module, a power management module, and an I/O function implementation module. The initialization module provides a DriverEntry entry point to execute numerous initialization functions. The Plug and Play (PnP) management module implements hot-plugging and dynamic configuration of USB devices. When the hardware detects a USB device connection, Windows 98 locates the corresponding driver and calls its DriverEntry routine. The PnP manager calls the driver's AddDevice routine to inform it that a device has been added. Then, the driver creates an FDO (Functional Device Object) for the USB device. During this process, the driver receives an IRP (IRP) of IRP_MN_START_DEVICE, including the resource information allocated to the device. At this point, the device is correctly configured, and the driver begins communicating with the hardware. Of course, if the device's state changes during operation (unplugged, paused, etc.), the PnP manager also issues a corresponding IRP, which the driver handles accordingly. The power management module is responsible for suspending and waking up the device. The I/O function implementation module handles most of the I/O request work. When an application makes an I/O request, it calls the Win32 API function DeviceIoControl to issue commands to the device. Then, the I/O manager constructs an IRP and sets its MajorFunction field to IRP_MJ_DEVICE_CONTROL. Upon receiving the IRP, the USB device driver extracts the control code and uses a switch statement to find the corresponding routine entry point. 2.2 Device Firmware Design The device firmware is the core of device operation and is designed using assembly language. Its main functions are: controlling the USB9602 chip to accept and process requests from the USB driver (such as requests for device descriptors, requests or settings for device status, requests for device settings, requests or settings for device interfaces, etc., providing 10 types of USB 1.1 standard requests); the USB962 chip accepts control instructions from the application program; controls the data acquisition of the A/D module; and stores data through the USB9602 and uploads it to the PC in real time. Its main program block diagram is shown in Figure 5. In Figure 5, the ALT event indicates that the hardware detects that the USBN96902 is in the following states: Reset, Resume, Suspend, reported by the ALTEV register and generating an interrupt. 2.3 Application Design The PC or industrial control computer application is the center of the real-time data acquisition system and is programmed using Visual C++ 5.0. Its main functions are: to turn on or off the USB device, detect the USB device, set the USB data transmission pipe, set the A/D status and data acquisition port, collect data from the USB interface in real time, and display and analyze the data. The main block diagram of the USB program is shown in Figure 6. Since the FIFO provided by USB9602 does not exceed 64 bytes, when the FIFO is full, USB9602 automatically packages the data and immediately requests to read the data, and the SIE automatically sends the data packet. After the program obtains the data, it needs to delay until the next group of data packets is ready, so as to ensure that the program and the device acquisition frequency are synchronized. In addition, when the system starts the A/D module, the program continues to execute and uses multi-threaded programming to issue commands to stop acquisition and turn off the USB device. 3 Features of the real-time data acquisition system based on USB bus The design of the real-time data acquisition system based on USB bus strictly follows the USB1.1 protocol, and its performance characteristics are as follows: (1) Easy to install and supports plug and play. During installation, the device can be inserted into the USB slot without shutting down the computer or opening the chassis, and the driver can be run. After that, the device can be hot-swapped directly. (2) Easy to expand. The maximum transmission distance is 5m, and it can reach 30m with a Hub or repeater; up to 127 devices can be connected to the outside. (3) Convenient power supply. The USB bus directly uses the host power supply to provide a maximum current of 5V 500mA to the peripherals, and the system does not need a backup power supply. (4) Minimal power interference. Since this product is placed outside the computer chassis, it is not affected by the power supply between boards inside the chassis. In environments with severe electromagnetic interference, a shielding scheme can be specially designed for this product. (5) High cost performance. Far superior to traditional real-time data acquisition systems. (6) Real-time acquisition and real-time display. Editor: He Shiping