Design of Data Acquisition System Based on C8051F340

Publisher:SereneMeadowLatest update time:2011-03-28 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1 Introduction

The stability of the operating state of electronic equipment directly affects the production of modern enterprises. The high maintenance costs after equipment failure and the losses caused to enterprise production after equipment downtime have led various enterprises to take measures to reduce the failure rate of equipment. Through the data acquisition system, the equipment operation characteristic data is accurately obtained, and the data is analyzed to determine whether the equipment is in good condition, so as to prevent failures in advance and reduce downtime for maintenance. In practical applications, the reliability, accuracy and portability of the data acquisition system are very high. Currently, the commonly used data transmission networks (such as RS232/RS485, CAN, etc.) can no longer meet the requirements of large-scale data collection and high-speed real-time data transmission. USB transmission has the advantages of high-speed and reliable transmission, low cost, high reliability and easy maintenance. This paper takes C8051F340 with on-chip USB and high-speed AD converter as the core control device, and uses the high-speed transmission characteristics of the USB bus to design a high-speed and low-cost data acquisition system. The acquisition signals include 14 parameters such as the temperature, pressure and flow rate of the output gas of the equipment, which is suitable for data acquisition of the operating state of specific equipment.

2 System Design

The system design diagram is shown in Figure 1. The system is mainly composed of the C8051F340 data acquisition module and the host PC. The data to be monitored is converted by the sensor at the front end of the system and sent to the preprocessing circuit. The data output from the preprocessing circuit is sent to the AD conversion port through the I/O port. After AD conversion, the data is saved to the C8051F340 microcontroller, and finally the data is sent to the host PC through USB for storage and processing.


Figure 1 System Design Block Diagram

3 Hardware Design

In the entire hardware design, the C8051F340 microcontroller is an important part of the system. The C8051F340 microcontroller is a fully integrated mixed-signal system-on-chip MCU launched by Silicon Laboratories. 8051 compatible microcontroller core with high speed and pipeline structure (up to 48M IPS); Universal Serial Bus (USB) function controller with 8 flexible endpoint pipelines, integrated transceiver and 1K FIFO RAM; true 10-bit 200ksps single-ended/differential ADC with analog multiplexer; on-chip voltage reference and temperature sensor; accurately calibrated 12MHz internal oscillator and 4 times clock multiplier; up to 64KB on-chip FLASH memory; up to 4352 bytes on-chip RAM (256+4KB); up to 40 port I/O (5V input allowed) circuit design of acquisition system.

Due to the characteristics of C8051F340 itself integrating many hardware circuits, the hardware interface design becomes very simple, and no additional electronic components are needed to realize USB data transmission and AD conversion, etc., making the system hardware structure simple, highly integrated and reliable. As shown in Figure 2, the MCU is connected to the host PC through the on-chip USB interface for data transmission. The P2.0~P2.6 pins on the C8051F340 are used as the input port for data acquisition, receiving data from the pre-processing circuit, and finally determining the channel for AD conversion through the analog multiplexer (AMUX) of the MCU.

Figure 2 Data acquisition hardware schematic.

4 Software Design

The software part of the system includes the MCU firmware and the host PC client program. The MCU firmware is mainly responsible for the MCU initialization and communication preparation with the host computer, while the client program is responsible for calling the corresponding control in the firmware to realize data transmission control, data storage and fault warning.

4.1 MCU firmware (firmware)

The MCU firmware is written using Keil uVision3 software and consists of three modules: main program, AD data conversion, and USB communication.

The main program is responsible for initializing each port and functional module of the MCU, setting the corresponding IO port as the data input port, and entering the USB interrupt service through the void USB_API_TEST_ISR (void) function after completing various initializations. In the interrupt service, the USB interrupt source is obtained by calling the Get_Interrupt_Source() function. Then, according to different entry conditions, corresponding processing is performed. For example, when receiving the initialization command, the various state parameters in the MCU are reset.

The AD data conversion module is mainly responsible for the conversion time interval and sampling accuracy setting during AD conversion. There are 6 triggering modes for the AD conversion start of the C8051F340 microcontroller. The state of the ADC0 conversion start mode bit (AD0CM2..0) in ADC0CN determines which mode is used. This system triggers the AD conversion by each timer overflow of timer 2 in the microcontroller. To ensure that the previous data conversion is completely completed when the timer triggers the AD conversion each time, the time interval (Tcont) from the overflow of timer 2 to the next timer overflow must be greater than the AD conversion time to ensure that each AD conversion is completed. The AD conversion time consists of the settling conversion time (Tsettle) and the sampling time (Tsample). Figure 3 shows the input circuit of the equivalent AD conversion in the differential mode. For a system with a given settling accuracy (SA), the required ADC settling time (Tsettle) can be determined by equation 1. The sampling time (Tsample) requires 10 SAR clocks by consulting the technical manual. Tcont must satisfy equations (2) and (3) to meet the design requirements.



Figure 3 AD conversion equivalent input circuit.



Where: SA is the settling accuracy, expressed as a fraction of an LSB (for example, the settling accuracy of 0.25 corresponds to 1/4LSB); t is the required settling time (Tsettle), in seconds; n is the resolution of the ADC, expressed in bits. Rtotal is the sum of the AMUX resistance and the external signal source resistance; Csample is the ADC sampling capacitor:



Where: K is the count value reloaded after timer 2 overflows; clk is the system clock frequency.



The USB communication module sets the data transmission mode between the microcontroller and the host. According to the requirements of the USB communication protocol, the corresponding registers are set to configure endpoints 0 and 2 in the USB to communicate data with the upper host, where endpoint 0 is responsible for receiving and responding to control commands from the host, and endpoint 2 is responsible for transmitting the collected data to the upper host. At the same time, the 256-byte space used by endpoint 2 in the FIFO allocation of USB SB0 is all for data output. Since C8051F340 integrates a 10-bit ADC controller, the collected data is filled with 16-bit data, and the data is saved in the system RAM with the lower 8 bits first and the higher 8 bits later. One AD conversion can get 2 bytes of data. Therefore, in order to make full use of the space of endpoint 2 each time data is uploaded, a variable i is added to the ADC interrupt response function to detect the number of conversions. After 128 AD conversions, the Block_Write() function is called to send data to the host. Part of the code is as follows:




4.2 Upper PC Client Program

The upper PC client program consists of two parts: the USB driver and the user application.

The USB driver is a software component that encapsulates the functional functions of the application to access the hardware device. Some devices have the same properties, and they are classified into a set of standard categories. The device class specification can be defined as the host driver framework of this type of device. The device class driver uses similar functions to handle the communication between different devices, so that the development of the device class driver can be independent of the device manufacturer. The driver of this system uses the USB Xpress development kit provided by Silicon Laboratories, developed in the Visual C++ 6.0 environment, and encapsulated in the form of a dynamic link library DLL for user application calls.

The user application is written in C++ and consists of four modules: customer interaction interface, USB data communication, data storage and display, and device fault warning. In the design of USB data communication module, the API functions such as SI_GetNumDevices, SI_GetProductString (), SI_Open (), SI_Close (), SI_Read (), SI_Write () provided by Silicon Laboratories are used to shield the complex USB communication protocol in the underlying hardware operation, simplify the USB communication development, and make it easier to develop USB communication programs. The

program flow chart is shown in Figure 4.


Figure 4 Client application flow chart.

There are many reasons for equipment failure. In order to ensure the normal operation of the equipment, it is necessary to detect multiple data. This system mainly detects the temperature and pressure data of the equipment. Once the data obtained exceeds a certain limit, it means that the equipment may fail. Therefore, in order to ensure the long-term stable operation of the equipment, it is necessary to compare the real-time data obtained with the pre-set critical value. Once the critical value is exceeded, the system will issue an alarm to remind the staff to troubleshoot the equipment, which has the effect of fault warning.

5 Conclusion

There are many options for USB data acquisition systems. This design considers portability and high-speed transmission, and writes firmware and client data transmission protocols, making the data acquisition system easy to carry, with high-speed and accurate data transmission, a good human-computer interaction interface, and the ability to warn of certain equipment failures, which has great use value. Moreover, the microcontroller port resources have not been used up, and there is still room for development and expansion.

Reference address:Design of Data Acquisition System Based on C8051F340

Previous article:Micr0 SD card reading and writing based on STM32F103XX microprocessor
Next article:Hardware Design of Brushless DC Motor Controller Based on DSP

Latest Industrial Control 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号