Design of a WAV audio player based on K20

. The designed player uses the Freescale Company's MK20DX128VLH7 as the core control ship, and its hardware platform is equipped with VS1003 audio decoder, OLED display interface, USB interface and SD card slot. The player uses the open source embedded real-time operating system μ C/OS-II, Freescale USB Stack V4.1.1 and FATFS, and a graphical user interface is developed to improve the user experience based on CGUI. In general, the designed WAV audio player has a strong applicability and a good practical value.


Introduction
With the continuous innovation and progress of digital electronic technology, network technology, embedded technology and communication technology, the human life is undergoing a dramatic changing. The embedded system has become the most advanced technology in the present society, equipment of embedded system has exceed the PC in the application, and the application of embedded technology in NC intelligent equipment, industrial robots and automotive consumer electronics is also increasing [1]. A cutting system of WAV audio player based on embedded technology is designed in this paper, its function is reliable, the cost is low, the volume is small and the power consumption is low. There are many kinds of solutions to design audio player, but it still has a lot of room to improve in the overall power consumption, performance and sound quality. Therefore, the designed player is combined with the characteristics of the existing audio player and takes its essence to enhance the overall performance, and it has a certain practical significance [2].

The general design of the system 2.1 Principle analysis
This paper designs a WAV audio player system which uses MK20DX128VLH7 as the core controller. The main work of audio player is to read the audio file, the file decoding and information display [3]. Therefore, the overall design of an audio player can be divided into the following three processing stages: a). accessing audio files, mainly including the transmission mode and the choice of storage media; b). decoding audio files, the main decoding scheme is the choice of soft or hard to decode; c). audio file information display, including the selection of the display, mainly to add more features and gorgeous interface to increase the user experience.
After a clear understanding of the different stages of the audio player design, we must complete the corresponding task at each stages, the next process mainly is the design of hardware circuit and software hierarchy.

Market demand analysis
The designed WAV audio player summarized the characteristics of the existing audio player and combined with the development trend of the audio player, it has the characteristics of compact and flexible, rich function, low overall design cost and so on. The specific functions are as follows: a). USB download, support USB2.0 full speed; b). SD card storage, support different types of SD card; c). human-computer interaction and OLED display; d). lyrics and audio information display; e). support a variety of audio format, such as WAV, MP3 etc.

Hardware design
The WAV audio player uses MK20DX128VLH7 as the core control unit, it receives the audio files from the PC and then to decode audio files and plays them. The system integrates the keyboard input, OLED display, SD card storage, USB communication, power management and JTAG download function unit. According to the composition and function of the whole system, the principle block diagram of the system is designed as shown in figure 1. The WAV audio player downloads WAV, MP3, WMA and other formats of digital audio files from the PC by USB interface, and then stores them on the SD card through the FATFS files system. The users can view and play the audio files on the SD card through the buttons and OLED display. When the player is playing the audio, the main control chip K20 reads the appropriate file content from the SD card and feds into the decoder VS1003 to decode and play through the SPI interface [4].

the Minimum system design
The peripheral circuit design of micro controller is shown in figure 2. S2 is a key switch for chip reset control; X1 is a crystal of 8 MHz which provides work clocks for MK20DX128VLH7; X2 is a crystal of 32.768 KHz which provides real-time clock for MK20DX128VLH7 (RTC); BT1 is a lithium ion battery of 3.7V to provide power for the system; J2 is output of serial port (UART) and is he output of debugging information of the system.

Voltage regulator circuit design
The WAV audio player uses 3.7V lithium ion as power source, and it can be charged through the USB interface. According to the desired voltage level, the whole system can be divided into three parts for 5V battery charging circuit, 3.3V power supply of system internal chip and 2.5V power supply of internal digital circuit VS1003.
The 5V battery power supply circuit uses power management integrated chip TP4056, it is a perfect function of a single lithium-ion battery constant current / constant voltage linear battery charger. The internal structure of the chip is designed with the PMOSFET structure, and the anti reverse charge circuit is designed, which needs no external isolation diode and simplifies the peripheral design. TP4056 charging voltage is limited to 4.2V, and the charging current can be adjusted by setting external resistors. If the charging current reaches the set float voltage value of 1 / 10, TP4056 will terminate charging automatically and it can be recovered when needed.
Because TP4056 has less number of external devices and it use the effective cooling package of SOP8, it is widely used in portable devices and variety of chargers. TP4056 charging circuit diagram is shown in figure 3, VCC is the 5V USB power input for internal circuit operation, BAT is connected to the positive side of the battery, which provides the current and 4.2V voltage to the lithium ion battery.  VIN is the voltage input which can choose the way of power supply mode for USB interface power supply or lithium ion batteries through the switch S1, VOUT is the stabilized voltage output which supplies for other IC in players system, and the ZTL431 is used to provide a 2.5V internal reference voltage source for MCU.
The 2.5V voltage regulator unit uses integrated chip SPX1117M3-2.5, it is a 800mA regulator of positive and ultra-low power consuming, and it has a very low static current. The chip of SPX1117M3-2.5 is very suitable for application in portable embedded devices and battery power supply equipment because its low differential pressure when full load is demand.

SD card interface circuit design
The WAV audio player's SD card storage circuit is shown as the figure.5. SD card module combines MCU through the SPI bus interface. CD/DATA3 is used as the selection line CS of SPI chip, CMD is used as the MOSI data output line in the SPI bus, DATA0 is used as the data input bus, CLK is the clock line, Card Detection is used to support hot plug of SD Card.

The man-machine interface circuit design
The man-machine interface part is mainly composed by key control input, JTAG download, and OLED LCD display and so on. The key circuit design uses five buttons, as shown in figure 6. One button has integrated signals of multiple directions for the controller to identify. Nowadays, the handheld devices is more and more adopted the multidirectional integrated button, because it can reduce the circuit board space of multiple keys and easy to integrate. The OLED12864 is adopted in liquid crystal display. Its distinguish ability is 128 x 64 and its visible angle can reach 170 °. Its power consumption of the normal display is just 0.06W that far lower than TFT display, and it can support the communication mode of SPI and IIC. The circuit design of the OLED12864 is shown in figure 7. GND is power cathode, VCC is the positive, D0 is used as the CLK of serial input clock, D1 is used as the serial input of data, RST is the reset signal, and the DC port controls the input data or command.

Audio playing circuit design
The data communication way of VS1003 and the core microcontroller MK20DX128VLH7 is SPI bus, circuit design is shown as figure 8. VS1003 receives audio file data and control commands of MK20DX128VLH7 through the serial data interface (SDI) and a serial command interface (SCI), and it confirms the interface whether is undering the state of transmission through the high or low level of XCS and XDCS. The main control function of VS1003 is the system initialization, play and pause, soft reset, volume control and the reading of audio playing time and so on, all of these functions are realized by write specific registers through the SCI. Between the two SCI instructions, the system need to judge whether the last data processing is completed through query the signal of DREQ [5].

Software design
The multi task operating system of μc/OS-II is adopted to manage all tasks of the player in this design, and the μCGUI graphics library is used to construct the graphical man-machine interface. The system's software is divided into four layers of driver layer, interlayer, application layer and system layer. The driver layer includes a bottom interface of the peripheral and board level peripheral devices. The intermediate layer is a transplanted code library of the file system, USB protocol stack and μ CGUI. The application layer is used to realize each function module of the system. The system layer uses μ c/OS-II to manage and schedule the task of the whole system. Since the player uses the operating system, the overall task management of the system becomes very easy. The software procedure is shown as figure 9. First of all, we need to initialize the system hardware platform, such as the basic peripheral registers and clock configuration. The next task is to initialize operating system and to write application task programs, and then starting the multi task operation and scheduling tasks after all the tasks are successfully created. Finally, the application layer drives programs indirectly in the management of the operating system through the middle layer, and the music playing and humancomputer interaction is achieved ultimately.

Music playing program design
Music playing is the core of this system, the design of music player program should be important part of the software design. The function of music playing needs two procedures of reading music file and decoding broadcast. Because the size of an audio file is at least 512 bytes and reads it needs 1-2ms, while the audio decoder VS1003 data cache is only 32 bytes, the playing length is less than 1ms, so the data writing frequency of decoder is more frequent than the reading speed of SD card. There will be a pause if the scheme of single task reading and writing is used. The two tasks to read and decode respectively is designed in this paper, the program flow chart is shown in Fig. 10.

Key Program Design
In order to achieve more key functions, the key scanning program should obtain information of key codes, names and time when a button is pressed. The key structure has been defined to manage events of the key conveniently, and its definition is shown in following program. The key scanning program checks the status of buttons every 50ms as a separate system task. The program will wait for the button to loosen if it finds a button is pressed. If the button is pressed for a long time, the signal of long press will be sent to the system, or it will be the short. The key signal is sent to the system in the form of a μ COS system mailbox, the mailbox carries the instance pointer of the movable key, and the key processing program can get all the information of the active key through the pointer.

Performance test
The performance test of WAV audio player includes storage media reading and writing speed, USB transmission speed, audio performance index, key response speed and so on. The way of storage media reading and writing speed test is to copy a fixed size files into memory, and measuring the time of the whole process. A 1.3M file is tested in this design, the writing time is about 18 seconds to 20 seconds and the reading speed is about 2 times of writing. The actual test file is written and read successfully, and the contents of the file are correct. The method of key test is to measure the IO port waveform of the button by an oscilloscope, and then to calculate the interval time between the two interrupts signals. The actual test of the key response time is 100ms. From the test, the overall design of the player has reached the expected design requirements, the extension mechanism and the decoding of different audio formats is realized, and the key input can be response correctly. After a long running test, the system runs stably and has good performance in the process of playing music.

Conclusions
A WAV audio player system based on K20 is designed in this paper. From the test results, the designed player meets the expected requirements. The designed audio playing system provides a complete solution to the design of an audio player. Due to the designed player has function of the modular expansion in the application software, the WAV audio player will have a high practical value in engineering applications.