Design of a data acquisition system based on USB bus and Aduc831 microcontroller
2026-04-06 04:12:31··#1
Due to the development of information networking, it is often necessary to connect various devices to the host. The traditional communication interface between peripherals and the host is generally based on PCI bus, ISA bus or RS-232C serial bus. Although the PCI bus has a high transmission speed (132Mbps) and plug-and-play functionality, its disadvantages are cumbersome plugging and unplugging, and limited expansion slots (generally 5-6). The ISA bus obviously has the same problem. Although the RS-232C serial bus is simple to connect, its disadvantage is slow transmission speed (56kbps). The emergence of the Universal Serial Bus (USB) can solve these conflicts well. We designed a data acquisition system based on the USB bus using the new high-performance microcontroller Aduc831. 1. Introduction to USB 1.1 USB Features USB stands for Universal Serial Bus. It is a fast, bidirectional, synchronous, inexpensive serial interface that can be hot-swapped. Its main features are: 1) High speed. USB has two modes: high speed and low speed. The main mode is high speed mode with a rate of 12Mbps. In addition, in order to accommodate some devices that do not require high throughput and high real-time performance, such as mice, USB also provides a low speed mode with a rate of 1.5Mb/s. 2) Device installation and configuration are easy. Installing USB devices no longer requires opening the computer case, and adding or removing already installed devices does not require shutting down the computer. All USB devices support hot-swapping and are easily expandable. 3) Flexible use. USB has four transmission modes: control, synchronization, interrupt, and bulk, to adapt to the needs of different devices. 1.2 USB Bus Protocol The USB bus is a polling-based bus, where the host control port initializes all data transmissions. Each bus operation transmits a maximum of three data packets. According to pre-defined principles, at the start of each transmission, the host controller sends a USB data packet describing the type and direction of the transmission operation, the USB device address, and the terminal number. This data packet is usually called a token. (packet). USB devices extract their own data from the appropriate position in the decoded data packet. Data transfer direction is either from host to device or from device to host. At the start of a transfer, a flag packet indicates the direction of data transfer, and then the sending end begins sending data packets containing information or indicating that no data is being transferred. The receiving end also sends a handshake data packet to indicate whether the transfer was successful. USB data transfer between the sending and receiving ends, between the ports of the host and the device, can be considered as a channel. There are two types of channels: streams and messages. Stream data is unlike message data; it does not have the structure defined by USB, and the channel is related to data bandwidth, transfer service type, and port characteristics (such as direction and buffer size). Most channels exist after the USB device is set up. USB has a special channel—the default control channel, which belongs to the message channel and exists when the device is started, thus providing an entry point for device setup, status queries, and input control information. 2. Hardware Design 2.1 Introduction to Aduc831 The ADuC831 is a fully integrated 247 k sample-and-hold data acquisition system that combines a high-performance self-calibrating 12-bit ADC on the same chip. The ADuC831 features multiple channels, dual 12-bit DAC channels, and a programmable 8-bit MCU. The microprocessor core is the 8052, providing 62 kB of on-chip non-volatile flash/Electrically erasable program memory. It also provides 4 kB of on-chip non-volatile flash/Electrically erasable data memory, 256 bits of RAM, and 2 kB of extended RAM. The ADuC831 also provides an additional power monitor and a high-precision reference source. On-chip digital peripherals include two 16-bit Σ-Δ DACs, dual-output 16-bit PWM, a watchdog timer, a timer interval counter, three timers/counters, with Timer 3 for baud rate generation and serial interface I/O (I2C, SPI, and UART). On-chip serial download and debug modes (via UART) are provided, along with a single-pin contention mode via the EA pin. The ADuC831 supports QuickStart and QuickStart Plus system upgrades and low-cost software and hardware tools. 2.2 USBN9603 Overview: The USBN9603 is an integrated USB endpoint controller with enhanced DMA capabilities. It integrates a transceiver with a 3.3V regulator, one SIE (Serial Interface Engine), one 8-bit parallel interface, one clock generator, and one MICROWIRE/PLUS interface. The USBN9603 can perform data transfer across seven endpoints. Except for one endpoint, which must be a control endpoint, the other six endpoints can be configured as interrupt endpoints, bulk endpoints, or isochronous endpoints. Each endpoint has a dedicated FIFO; the control endpoint's FIFO is 8 bits long, and the others are 64 bits long. The parallel interface supports both multiplexed and non-multiplexed interface modes with the CPU. The USBN9603's key features include: low EMI (electromagnetic interference), low wait current, a 24MHz crystal oscillator, enhanced DMA functionality; it can use either 5V or 3.3V power supplies; bus operation features a full-speed static HALT mode with asynchronous wake-up; an improved 3.3V input voltage regulator; and 64B FIFOs on all non-bidirectional endpoints. The external controller interface is simple and easy to program. 2.3 Schematic Design The USB data acquisition system hardware module mainly consists of the Aduc831 chip and the USB interface chip USBN9603. The hardware structure is simple, and the overall hardware block diagram is shown in Figure 1. An analog input signal A/D converter stores the conversion result in a FIFO memory. Once the FIFO is full, the SIE immediately processes the data, and then the Aduc831 system reads the data from the FIFO memory, which is then sent to the host by the transceiver via data lines (D+, D-). When the USB controller detects a transfer request initiated by the host from the USB bus, it notifies the Aduc831 system of this request via an interrupt. The Aduc831 system obtains various parameters related to this transfer by accessing the status register and data register of the USB controller, and performs corresponding operations on the control register and data register of the USB controller according to the specific transfer parameters to complete the host's transfer request. The interface circuit between Aduc831 and USBN9603 is shown in Figure 2. 3. System Software Design The system software mainly includes: the control program and the USB device driver. 3.1 Control Program The control program refers to the program running in the Aduc831, and its operation on the USB controller strictly follows the USB protocol 1.1. In actual development, two transfer methods were used: control transfer and block transfer. Control transfer is mainly used to complete various control operations of the host on the device, that is, to implement the various control operations of the device by the USB bus driver (USBD.SYS) located on the host and the written function driver. Block transfer is mainly used to complete large-volume data transfer between the host and the device and to detect errors in the transmitted data (if an error occurs, it supports a "retransmission" function). The main functions of the control program include controlling A/D sampling, controlling the USBN9603 to accept and process requests from the USB driver and control commands from the application. Because the Aduc831 has a serial port download function, programs can be easily downloaded to the Aduc831 via serial port, without the need for an emulator or traditional methods of burning programs to the EEPROM, making debugging very convenient. The control program flow and interrupt handling program are shown in Figures 3 and 4. 3.2 USB Device Driver Design The USB device driver is based on WDM. WDM drivers are kernel programs, unlike standard Win32 user-mode programs. A layered approach is adopted, with 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 Module (USBD) and a lower-level Host Controller Driver Module (HCD). The USB device driver does not need to be specifically programmed into the hardware; all USB commands and read/write operations are transferred to the USB device through the bus driver. However, the USB device driver must define the communication interface and data format with external devices, and also define the interface with the application. Windows USB 98/2000 provides a series of system drivers that have all the basic functions needed to service many standard types of devices. Users can define the device configuration and functions by following the prompts, and then modify the functions. The functionality of a USB device driver can be divided into four different modules: initialization module, plug-and-play management module, power management module, and I/O function implementation module. The initialization module provides one entry function, DriverEntry(). In DriverEntry, an AddDevice routine needs to be provided to add the driver to the driver stack. In addition, all routines for handling various IRPs (I/O request packets) are defined in this entry function. DriverEntry(IN PDRIVER_OBJECT DriverObject,…) //Driver entry point { DriverObject->DriverExtension->AddDevice=USBAddDevice; DriverObject->DriverUnload=USBUnload; DriverObject->MajorFunction[IRP_MJ_READ]=USBRead; DriverObject->MajorFunction[IRP_MJ_WRITE]=USBWrite; DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = USBDeviceControl; RegisterForPnpNotification(DriverObject); return status; } 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. If the application wants to perform I/O operations on the device, it uses Windows API functions perform WIN32 calls to the WIN32 subsystem. This call is received by the I/O system service and notified to the I/O manager. The I/O manager constructs an appropriate I/O request packet (IRP) and passes it to the USB device driver. Upon receiving the IRP, the USB device driver constructs the corresponding USB request block (URB) based on the specific operation code contained in the IRP and places this URB into a new IRP. Then, this IRP is passed to the USB bus driver. The USB bus driver performs the corresponding operation (such as reading data from the USB device) according to the URB contained in the IRP and returns the operation structure to the USB device driver via the IRP. The USB device driver, upon receiving this IRP, returns the operation result to the I/O manager via the IRP. Finally, the I/O manager returns the operation result in this IRP to the application, thus completing one I/O operation of the application on the USB device. In conclusion, USB provides a new interface standard for computer peripheral input/output. It enables devices to be hot-plugged, plug-and-play, and automatically configured, standardizes device connections, and can also be used with MAX... The system combines RS-485 with remote data acquisition. It boasts advantages such as high reliability, cost-effectiveness, and multi-point acquisition. Furthermore, the USB 2.0 standard offers even higher transmission rates and has a promising future. References: 1. Aduc831 datasheet. Analog device. 2. USB 1.1. Universal Serial Bus Specification S. 3. Zhang Nianhuai and Jiang Hao. *USB Bus Interface Development Guide*, National Defense Industry Press.