Share this

Design and Implementation of a USB Data Acquisition System Based on CH372

2026-04-06 06:47:09 · · #1
Abstract: This paper proposes a design method for a data acquisition system based on the USB bus transmission protocol. The system uses a CH372 USB controller and an SPCE061A microcontroller to complete communication between the device and the host. The paper introduces the overall design concept and hierarchical structure of the data acquisition system, and describes the design methods for firmware, device function drivers, and application programs. The system uses the CH372's built-in firmware mode to shield related USB protocols and uses the SPCE061A's built-in analog-to-digital converter for data conversion control, making the hardware circuit very simple and widely applicable for acquiring various types of data. Keywords: USB bus; data acquisition; CH372 0. Introduction: In modern scientific research, data acquisition and analysis are frequently required. Currently, the most common method is to install data acquisition cards (such as A/D cards and 422/485 cards) in a PC. However, these data acquisition devices suffer from cumbersome installation, high cost, limitations imposed by the number of computer slots, addresses, and interrupt resources, poor scalability, and data distortion due to the inability to perform electromagnetic shielding. With the increasing demands for higher system data acquisition speeds, USB is increasingly being used in data acquisition systems due to its ease of use, expandability, and high speed. USB (Universal Serial Bus), as a new peripheral connection technology, simplifies the connection process between computers and peripherals, improves compatibility between low and high speeds, and provides users with a shareable, expandable, and convenient serial bus. 1. Composition and Working Principle of a USB Data Acquisition System A practical USB data acquisition system includes an A/D converter, a DIO (Digital I/O) chip, a microcontroller, a USB control chip, and a PC-side application program. The external measured signal is converted into an analog voltage signal by a sensor and transmitted via a shielded cable to the A/D conversion module for conversion into a digital signal. On the host side, when a peripheral USB device is connected to the system, after being detected and configured as available through bus enumeration, the host application program can control the data acquisition system to acquire data. The microcontroller acquires data according to the required sampling rate and stores the acquired data in a data memory. Then, through the USB interface control chip, the data packaged according to the USB bus transmission protocol is placed on the USB bus and transmitted to the host. The host application program then displays, analyzes, and processes the data. 2. System Hardware Design The USB bus interface controller is an important component for communication between USB devices and the host. Currently, there are many types of USB controllers on the market, which can be roughly divided into two types: one is a microcontroller with a USB interface, such as the Cypress CY series; the other is a pure USB controller that only handles USB communication and requires an external microcontroller for protocol processing. According to the classification of USB controllers, there are two methods to realize communication between USB devices and the host: (1) USB controller with a microprocessor (2) Independent USB controller plus microprocessor. Based on the function of the data acquisition card, this system uses the SPCE061A microcontroller with a 7-channel 10-bit precision A/D converter and the CH372 USB control chip to form an external data acquisition device to realize communication with the host. 2.1 Main features of the CH372 controller: (1) Supports full-speed device interface, compatible with USB 2.0 specification, plug and play, and only requires crystal and capacitor for peripheral components. (2) Provides a pair of master endpoints and a pair of auxiliary endpoints, supporting control transmission, batch transmission and interrupt transmission. (3) It has an 8-bit data bus and read, write, chip select control lines and interrupt output, which can be easily connected to the system bus of controllers such as microcontrollers/DSPs/MPUs. (4) It has built-in the underlying protocol of USB communication, and has a convenient built-in firmware mode and a flexible external firmware mode. In the built-in firmware mode, CH372 automatically handles all transactions of the default endpoint 0 and automatically completes the standard USB enumeration configuration process. The local microcontroller only needs to be responsible for data exchange, so the microcontroller program is very simple [1]. 2.2 Main performance characteristics of SPCE061A SPCE061A has a 16-bit microprocessor core, a CPU working clock frequency of 0.32-49.152MHz, two 10-bit digital-to-analog converter output channels, and seven 10-bit analog-to-digital converter input channels. It has a high processing speed and can process complex digital signals more easily and faster. [2] Based on the integration of functional modules and the characteristics of CH372 built-in firmware mode, the hardware circuit of this system is very simple. [align=center] Figure 1 System hardware connection diagram[/align] The analog signal is amplified externally and input through IOA[6:0]. The read strobe output RD# and write strobe output WR# of the CH372 chip are connected to the microcontroller. CS# is driven by the address decoding circuit and can be used to select devices when the microcontroller has multiple peripheral devices. In this system, CS# is required to be low level, so it is directly grounded. The interrupt request output by INT# is active low level. The microcontroller can use interrupt mode or polling mode to know the interrupt request. When WR# is high level and CS#, RD# and A0 are all low level, the data in CH372 is output through D7~D0; when RD# is high level and CS#, WR# and A0 are all low level, the data on D7~D0 is written into the CH372 chip; when RD# is high level and CS# and WR# are both low level and A1 is high level, the data on D7~D0 is written into the CH372 chip as a command code[1]. 3. Software Design The software part of the USB data acquisition system includes three aspects: the firmware program in the microcontroller, the device driver, and the application program on the host. 3.1 The firmware program is the code executed by the microcontroller connected to the USB controller, which is mainly responsible for two tasks. (1) Responding to the host's enumeration of devices to configure the devices, that is, enabling the host to detect and identify the devices, and preparing for data transmission between the host and the devices. (2) Transmitting data according to the requirements of the application program on the PC. Since the CH372USB controller used in this system has a built-in firmware mode that shields the relevant USB protocols and automatically completes the host's USB enumeration configuration process, it does not require any processing from the local controller. Therefore, the firmware program only needs to implement the requirements related to the transmission of acquired data and the setting of acquisition parameters. The SPCE061A has 7 A/D conversion channels, but only one ADC. Before use, the RDY value of the P_ADC_MUX_Ctrl unit/P_ADC_Ctrl unit must be checked to determine that the ADC is in an idle state. Channel switching is achieved by setting the 2nd and 3rd bits of P_ADC_MUX_Ctrl. Moreover, the A/D conversion of the SPCE061A can only be triggered by reading the data of the P_ADC_LINEIN_Data unit [2]. Data acquisition relies on reading the data of the P_ADC_LINEIN_Data unit for continuous data acquisition. Since the transmission speed of USB is much greater than the data acquisition speed, a dual data buffer is defined in the internal RAM of the SPCE061A. The buffer buf[0] is used as the buffer full flag and the read pointer p to determine the reading data order, so as to read data from the two buffers in turn. When buf_i[0]==1&&p==buf_i, it means that the i buffer is full and the reading data order is correct, so data is read from this buffer. After the data is sent, the buffer full flag is changed and the read pointer is set to continue reading the next buffer. To ensure continuity between data transfers, the time interval between host queries must be less than the time required for the buffer to be filled once. Endpoint 0 of the CH372 is the default endpoint, automatically handling various standard USB transactions in built-in firmware mode. Endpoint 1, the downlink endpoint, serves as an auxiliary endpoint for transmitting control commands for data acquisition, such as starting, stopping, and setting various parameters. Endpoint 2 acts as a batch data transfer endpoint for transmitting acquired data. The CH372 provides an end-to-end connection between the computer application layer and the local microcontroller. This system uses a request-response communication method. The computer application layer sends data requests to the CH372 chip according to a pre-agreed command code and data transmission format. The CH372 chip then notifies the microcontroller via an interrupt, entering the interrupt service routine. Interrupt service routines obtain and analyze interrupt status by executing the GET_STUTAS command. If the data is successfully sent, the RD_USB_DATA command is executed to read the received data from CH372; if the data is successfully uploaded, the WR_USB_DATA command is executed to write the next set of data to be sent to CH372; if the interrupt data is interrupted, the control command type is analyzed and the corresponding data acquisition control is executed. 3.2 Device Driver The design of the client driver for USB bus devices is the key to the development of USB bus peripherals. USB bus devices adopt a layered WDM driver model. Through it, users do not need to interact directly with the hardware, but only need to access the hardware through the interface provided by the lower-level driver. The core of driver operation is the I/O request packet (IRP). Each layer of driver must communicate through IRP. When the application needs to perform I/O operations on the device, it calls the Windows API function. The WIN32 subsystem notifies the I/O manager to construct a suitable IRP according to the request and pass the request to the next layer. The dispatch routine often only performs the initial processing of the IRP, such as checking whether all parameters are valid, and then dispatches the IRP to the lower-level driver for processing [4]. The USB function driver accesses the USB bus through the USB bus driver interface. All low-level I/O is handled by the USB bus driver, so the function driver only cares about data transfer type, timing, pipeline, and how to process data. This system directly uses the device driver provided by the CH372 chip developer, which includes operations such as device creation, device shutdown, device control, and device PnP. 3.3 Application The client application is written in Visual C++, providing users with control functions such as opening and closing the device, adjusting data acquisition parameters, and displaying acquired data. Once the device is connected and configured, the application needs to communicate with the device to initiate a transfer. [align=center] Figure 2 Application Flowchart[/align] To the application, the USB device is simply a file with a device name, so file functions in the Win32 API can be used to control the device. The application utilizes multi-threaded programming to achieve real-time performance. The main thread completes system parameter settings and data display, while auxiliary threads independently complete data acquisition. 4. Conclusion With the increase in USB data transfer speed and the enhancement of real-time performance, more and more USB devices will emerge. This paper addresses the current situation where data acquisition systems are cumbersome to install, expensive, and have poor scalability by designing a data acquisition system based on a USB bus interface. This system not only features a very simple hardware circuit but also convenient installation (plug and play), excellent reliability and stability, and can be widely applied to the acquisition of various types of data. The author's innovation lies in the fact that this system uses the CH372USB control chip's built-in firmware mode to shield related USB protocols for USB transmission. The default endpoint 0 automatically handles the host's USB enumeration configuration process, requiring no processing from the local controller. The microcontroller program is very concise, and the data acquisition hardware utilizes a microcontroller with built-in analog-to-digital conversion capabilities, making the entire system's control and hardware circuitry extremely simple. References [1] Nanjing Qinheng Electronics Co., Ltd. CH372S User Manual [M] 2005 [2] Luo Yafei Lingyang 16-bit Microcontroller Application Basics [M]. Beijing: Beijing University of Aeronautics and Astronautics Press 2005 [3] Jan Axelson. USB Encyclopedia [M]. Beijing: China Electric Power Press 2001 [4] Chris Cant. Windows WDM Device Driver Development Guide [M]. Beijing: Machinery Industry Press 2003 [5] Cao Ligang Development and Application of USB Bus Data Acquisition Control System [D]. Nanchang: Nanchang University Master's Thesis 2005 [6] Bian Hailong. Jia Shaohua USB 2.0 Device Design and Development [M]. Beijing: People's Posts and Telecommunications Press 2004 [7] Shi Xiaoying Xu Zhibang Data Acquisition System Based on AT90S8515 and USB Interface [J]. Microcomputer Information 2005 [8] Zhang Hong. USB Interface Design [M]. Xi'an: Xi'an University of Electronic Science and Technology Press 2002
Read next

CATDOLL 123CM LuisaTPE

Height: 123cm Weight: 23kg Shoulder Width: 32cm Bust/Waist/Hip: 61/54/70cm Oral Depth: 3-5cm Vaginal Depth: 3-15cm Anal...

Articles 2026-02-22