APP下载

U disk recorder based on CH376 and ATmega 128

2013-12-20RANZibo冉自博MAYouchun马游春LIUHongyu刘红雨

关键词:游春

RAN Zi-bo (冉自博), MA You-chun (马游春), LIU Hong-yu (刘红雨)

(Department of Electronic Science and Technology, North University of China, Taiyuan 030051 , China)

U disk recorder based on CH376 and ATmega 128

RAN Zi-bo (冉自博), MA You-chun (马游春), LIU Hong-yu (刘红雨)

(Department of Electronic Science and Technology, North University of China, Taiyuan 030051 , China)

By using enhanced reduced instruction set computing(RISC) architecture and carrying out powerful instructions in a single clock cycle, the ATmega128 achieves the data transmission speed of about one MIPS per MHz. With this advantage, the designer can eliminate the contradiction between power consumption and processing speed in data acquisition system based on U disk. In this paper, a U disk recorder for mass data storage is designed. It consists of a microcontroller ATmega128 and a U disk management chip CH376. ATmega128 with 4 KB SRAM provides enough buffer memory and CH376 enables U disk files to be written or read in sector size. Based on analysis of the system, the hardware and software designs are given. With the designed data acquisition system, data transmission speed can reach 460 KB per second. The experimental results show that the designed system has higher efficiency and reliability than the traditional ones when writing or reading U disk files.

ATmega128; U disk; CH376

CLD number: TP274 Document code: A

0 Introduction

To evaluate system performance, many parameters need to be collected for a long period of time, so the amount of data is very large. In addition, there may be a mass of interrelated data need only post analysis and processing but feedback to the control system and reak-time analysis by computer[1], such as real-time data, engineering vehicle test parameters and aeronautical navigation data, etc. in some process control systems on the occasion that bulk data need to be acquired are from the moving object or the workplace of data acquisition system is not fixed.

U disk has been widely used with the development of the universal serial bus(USB) device driver, and it can be a good solution to the problem of an amount of data acquisition. In the data acquisition process, U disk controlled by microcontrotter unit (MCU) can be used as the portable mobile device for bulk data storage in data acquisition system, which needs to exchange data with computer. Thus it effectively reduces the wasted time and resources when reading the mass-storage data of the traditional data acquisition system and achieves data storage in real time[2]. In this paper, a U disk recorder for mass data storage is designed.

1 Analysis of the system

1.1 Feasibility analysis and system structure

USB interface is a new serial communication standard specified by some large computer manufacturers in order to eliminate the contradiction between the growing PC peripherals with limited motherboard slots. USB bus has some advantages such as plug-and-play, high-speed, etc[3].

U disk as one of the typical USB devices has occupied an important position in our daily life. Its advantages of portability, mass storage and real-time have laid the foundation for high-speed data acquisition system.

The ATmega128 is a 8-bit low-power CMOS microcontroller based on AVR RISC architecture[4], which can execute powerful instructions in a single clock cycle and achieve data throughput approaching 1 MIPS per MHz.

The AVR core combines a rich instruction set with 32 general purpose working registers. All the 32 registers are directly connected to the arithmetic logic unit (ALU), allowing two independent registers to be accessed in one single instruction executed in one clock cycle. Thus not only code efficiency increases but also data throughput can reach ten times faster than that of the conventional complex instrument set computer (CISC). Furthermore, the contradiction between power consumption and processing speed can be eliminated to prepare for storing real-time high speed data[5]. ATmega128 MCU also has a wealth of on-chip resources: 128 KB in-system programmable Flash with read-while-write capabilities, 4 KB EEPROM, 4 KB SRAM, 53 general-purpose I/O lines, ISP download interface and JTAG emulation.

The ATmega128 AVR is supported by a full suite of program and system development tools, including: C compilers, macro assemblers, program debugger or simulators, in-circuit emulators and evaluation kits, which offer a better development condition for designers.

With the development of USB technology gradually, more and more USB interface chips have been applied in engineering. CH376 is a U disk file management chip provided by Nanjing Qinheng company. It is used for SCM system to read and write files in U disk or SD card. It supports USB device mode and USB host mode, and it includes built-in USB communication protocol firmware, communication protocol firmware customized for mass-storage, FAT16, FAT32 and FAT12 file system management firmware[6].

CH376 supports three communication interfaces: 8-bit parallel communication, SPI communication and UART communication. USB host mode and 8-bit parallel communication of CH376 are applied in this design to manage files in U disk.

The whole system consists of a controller unit ATmegs128, a U disk management chip CH376, two 422 bus interfaces and some necessary peripheral circuits. The serial data with speed approaching 460 KB per second from device terminals is transferred to the system via 422 bus interface, and sequentially MCU receives and processes the data to control CH376 to write or read the received data into U disk. Finally, data storage is completed. The block diagram of the whole design is shown in Fig.1. RS232 is a serial interface used to connect MCU system with computer. Serial debugging assistant, a software is used to track the running of program timely to debug the program.

Fig.1 Block diagram of system structure

1.2 High-speed serial data storage

The serial data transmission speed of traditional MCU system that manages U disk files is limited because of little buffer with small memory. This will lead to loss of data, so the reliability of data storage can not be guaranteed.

In order to achieve high-speed data acquisition and ensure the reliability of data storage, rich memory resources of the ATmega128 MCU are fully taken advantage of as system cache. On one hand, it is necessary to test the availability of U disk when writing or reading U disk data, so the data can not be inputted continuously, which needs a large memory buffer to avoid a bad phenomenon of the loss of data during the waiting period whether U disk has been ready. On the other hand, due to non- uniform and non-continuity of serial data from device terminals, it will take a longer time to produce a half flag if memory buffer is too large. Thus the efficiency of data storage reduces. For mass data storage, it may also produce loss and overflow of data because of longer waiting time even though there is a large memory buffer.

It is necessary to design a special circuit, consisting of a micro controller FPGA and a Flash memory, to act as a cache in the whole system. The Flash with a large capacity of 4 GB can guarantee the high-speed serial data not to be lost and enhance the reliability of data storage. The functions of the part include two aspects: one of them is to separate the two 422 bus serial data and pack them as packages by frame with a special flag of frame; another function is to connect MCU to transfer the high-speed serial data from Flash to MCU. The data will be stored into U disk perfectly owing to the large Flash memory.

1.3 U disk file management

CH376 is a chip to manage U disk files, and it can write data into U disk or read data from it.CH376 supports FAT32, FAT16 and FAT12 in accordance with Windows file system format. It is convenient to exchange data between MCU of electronic products with that of personal computer with Windows operation system. Nanjing Qinheng Company offers C language library with many functions about write/read U disk, which simplifies the process of programming. For example, the function CH376FileCreatePath() is used to create multi-level directory file and open it, and the function CH376SecWrite() is used to write data into U disk in sector-write way. CH376 has the biggest capacity of U disk which is 32 GB, and the biggest capacity of single file which is 1 GB.

Fig.2 Flow chart of U disk file management

A U disk can store a number of files, and each file is a collection of data, which is identified by file name. Actually, the storage of the file is not be continuous, whereas it uses “pointer” to link multiple data blocks (that is, the allocation unit or cluster). Therefore, file length can increase in order to store more data. In order to guarantee the integrity and continuity of data storage, and taking into account the non-continuity of actual process, it is necessary to manage U disk files in writing-after-reading mode, that is, a log file is created to record index of the current file, at the same time, the follow-up file is named and data is written into it. The flow diagram of U disk file management is shown in Fig.2.

Capacity of U disk depends on the number of files. The system will give a warning by a LED if the length of file exceeds the capacity of U disk.

2 Design of hardware and software

ATmega128 has working voltage in the range of -4.5 V to 5.5 V. And CH376 supports power supply of 3.3 V and 5 V[7]. An appropriate voltage can be obtained by designing related peripheral circuits for V3 pin of CH376. A power module is used to supply 3.3 V for the system in this design. The design adopts the 8-bit parallel interface for communication. The signal lines of parallel interface include 8 dual-port lines D7-D0, input pin RD# for enabling read, input pin WR# for enabling write, input pin PCS# for chip selection and address input pin A0. The pin PCS# of CH376 is driven by address decoder circuits. It is used to select a needed device when there are a lot of peripheral devices. A 12 MHz oscillator is selected to enhance frequency accuracy of the system. CH376 can be connected to MCU system bus conveniently like other periphesal circuits via the parallel interface.

CH376 needs two address bits. The command port is selected by setting pin A0 high to write a new command or read the state of interface; the data port is selected by setting pin A0 low to write or read data.

The output pin ACT# of CH376 is used to indicate status of the system. In the case of working in host mode, the pin ACT# is set at 1 when after USB devices are not set or settings are cancelled; And the pin ACT# is set at 0 when USB devices are connected. The pin ACT# of CH376 connects a LED which is combined with a resistor to indicate whether U disk has been connected or not. ATmega128 supports real-time simulation, and a JTAG interface is designed to track the program conveniently in debugging process. Schematic diagram of peripheral circuit is shown in Fig.3.

Fig.3 Schematic diatram of CH376 peripheral circuit

3 Experimental results

To debug the system, a high-speed digital signal source is generated by imitating to send serial data to the system at the speed of about 460 KB per second. The system receives data via 422 bus interface, and then transfers it to inner memory for processing. At last, the data is stored into U disk under the controlling of MCU.

Fig.4 Experimental result at the first time

At the first time, data is written into U disk and a file named “file .log” is created with content as follows: “The file's index is x”, where x stands for the number of current files. Once the length of the first file is over 512 MB, the file is closed. Subsequently, the value of x is increased up to x+1, and then the new value is written into “file.log” to avoid the phenomenon that the existed gile is covered by new files when new data is written into U disk again. At the same time, the system will create a new file to store new data. At the second time, the system will check U disk firstly, if there are not the file named “file.log” yet, it will repeat the operation like the fist time; if the file exists, the system will read the content of the file, and then change the value of x from current value x to x+1 as well as write the refreshed content into “file.log”. At the same time, a new file is created to record the new data. For example, we can find the files that has been written into U disk by the system, as shown in Fig.4. The content of “file.log” is shown as follows:“The file's index is 3”, which means the name of current file is “file_3.NAV”. We also can see that the lengths of the other files such as “file_0.NAV”,“file_1.NAV” and “file_2.NAV” are all 512 MB. Repeating the operation again, the system will show “The file's index is 3”. After updating “file.log” with “The file's index is 4”, the file named “file_4.NAV” is created to store the received data. The file named “file_5.NAV” is created after “file_4.NAV” is closed when the received data is over 512 MB. Finally, the file “file.log” is renewed with the content as “The file's index is 5”. The result is shown in Fig.5.

Fig.5 Experimental result at the second time

4 Conclusion

The recorder based on U disk microcontroller system is constituted by AVR core microcontroller ATmega128 and U disk file management chip CH376. It can realize real-time high-speed serial data storage without a computer to operate U disk. It not only provides a new design method for the data acquisition system, but also simplifies system structure as well as improves the efficiency of data storage. Therefore, it plays an important role and has practical value in the design of mass data storage system.

[1] JIANG Yi-jun. Design of multi-line data acquisition process recorder based on U disk. Master thesis. Nanjing: Nanjing University of Science ang Technology, 2008.

[2] Thukaram D, Lomi A. Selection of static VAR compensator location and size for system voltage stability improvement. Electric Power Systems Research, 2000, 54(2): 139-150.

[3] SONG Nan. The test-equipment with U disk storage function for mechanical parameters acquisition system. Taiyuan: North University of China, 2012.

[4] Atmel Corporation. AVR core MCU ATmega128 Data-sheet. 2008.

[5] Lee E. AVR basic direction for C programming. Beijing: Tsinghua University press, 2003.

[6] Nanjing Qinheng Company. U disk and AD card file management chip CH376 reference. 2010.

[7] Barnett R H, Cox S, O'Cull L. Embedded C programming and the Atmel AVR. [2013-01-11]. http:∥www.filecrop.com/Embedded-C-Programming-and-the-ATM-EL-AVR-2nd-Edition.html.

date: 2013-06-27

RAN Zi-bo (13753485975@139.com)

1674-8042(2013)04-0330-05

10.3969/j.issn.1674-8042.2013.04.006

猜你喜欢

游春
Graphene-based heterojunction for enhanced photodetectors
少年游·游春
风鸢图诗
爱他莽苍苍青天碧海,熙攘攘赤县神州——顾随《游春记》杂剧主题意蕴新探
风莺图诗
诗二首
老乞丐
孔子游春与课堂动态生成
无心恋良夜
游春