Audio Player Design Example

Introduction The Audio Player design example is an embedded hardware/software solution for 16-bit digital audio. The project has three major functional blocks: 1) LPC2138 microcontroller 2) SD card interface 3) Audio DAC interface This prototype has been built around an LPC2138 evaluation board and two extra prototype boards: one for the audio DAC and one for the SD card. System timing analysis: To achieve the audio CD quality of sound (16 bit stereo with 44.1 kHz sampling frequency) the required bit rate is: 16 bit (resolution) x 2 channels (stereo) x 44.1 kHz (Fs) = 1411200 Hz This is the clock to be generated by the SSP interface, supplying data continuously to an audio DAC. The data has to be read from the file on an SD card. The file is in a PC compatible format. The data has to be read and processed in real time. The processing required is very simple for uncompressed audio and more complex for compressed audio, like MP3, which requires complex decoding. As the above numbers plus the microcontroller specifications show, it is definitely possible to implement a 16 bit audio replay from an SD card on an LPC2138 microcontroller running at CLK=60MHz, for uncompressed audio (such as in WAV format). There are commercial libraries for MP3 decoding on ARM7TDMI, but the author chose to check the performance of an open source code implementation.

Hardware Microcontroller The LPC2138 microcontroller needs only a single +3.3V supply, a reset circuit, the crystal or oscillator circuit and a JTAG connector and/or a serial port level converter for In-System Programming (ISP) via the PC. For the design example the circuitry on a Keil MCB2130 board has been used without modifications. The following on-board peripherals have been used: • • • • • •

Timer0 – in timer mode, to generate 10ms tick for task scheduling Timer1 – in counter mode, with external input and output to provide LRCK for DAC SPI0 – 8-bit master mode to read/write the SD card data SSP (SPI1) – 16 bit master mode to send data to audio DAC PWM – to generate MCLK for audio DAC UART0 – to communicate with a PC

There are other remaining peripherals, which can be used, for example to implement a user interface, such as an LCD, a keypad, or others as required.

Two extra prototype board have been attached to the MCB2130 evaluation board including: •

SD card interface The SD card operates in a standard SPI mode. The SPI0 has been used operating at its maximum clock of 7.5MHz. The SPI mode is an 8-bit slave with another port line used as CS.



Audio DAC interface 2 An I S standard interface was selected for an audio interface, due to its popularity (a number of chips available from different manufacturers) and simplicity of interface to the microcontroller.

An SSP is used in a 16-bit TI SSI mode. Some modification is required to convert to I2S. An LRCK signal has to be divided by 2, which is achieved through the on-board counter (external input and output pins) and the bit clock has to be inverted, which is done by a single gate inverter. See SSP_2_I2S.jpg and waveforms for timing diagrams.

2

An external DAC CS4330-KS has been used; however any audio DAC with I S interface will work just as well. A programmable low-power DAC like TI TLV320DAC26 has the benefit of built-in PLL, making it easy to use with different clocks, built-in audio amplifiers and other features.

Software The software has been written using an evaluation version of CrossStudio for ARM (Release 1.5 Build 1) from RA. The sources and project files are attached. The software consists of two parts. Part one is written by the author and part two is an open source MP3 decoder from https://datatype.helixcommunity.org/ The open source code is within the “\ fixpt” subdirectory. All of the open source files have been left as is (unmodified). The resources required by the open source code are listed in memory.xls and the cpu usage in the cpuusage.xls file, both in the “\ fixpt\docs” subdirectory. The memory required is 13446 bytes of ROM and 23816 + 4608 (output buffer) = 28424 bytes RAM. The cpu usage for the code compiled with ARM ADS1.2 on ARM7TDMI is listed as 26MHz. As the measurements shows, the software is able to perform MP3 decoding in real time.

The time taken by software for decoding of one MP3 frame (418 bytes) is ~13 ms. One frame lasts for 26 ms and has 1152 samples. An extra RAM (>4kB more) is needed for a real time MP3 software decoder. The next microcontroller in the hierarchy (LPC2148) has 8kB more RAM more and will fulfil the requirements.

Sample Code An interrupt for TX FIFO half empty is used. As *.wav data comes in little endian, the byte order is reversed here to feed 16 bit into SSP FIFO. Four 16-bit frames are loaded into FIFO (being 2 left and 2 right audio samples).

unsigned char bb[BIG_SIZE];

// big buffer – data written here from // SD card and data are read from // here for SSP (DAC)

typedef union { unsigned char b8[4]; unsigned short b16[2]; unsigned int b32; } wave_data;

// used to change byte order

wave_data wave_data wave_data wave_data

left; right; left1; right1;

// left audio sample // right audio sample

void sspISR(void) __attribute__ ((interrupt ("IRQ"))); void sspISR(void) { unsigned char c; c = SSPMIS; SSPICR = 0x03; // reset INT errors if any left.b8[0]=bb[play_index++]; left.b8[1]=bb[play_index++]; right.b8[0]=bb[play_index++]; right.b8[1]=bb[play_index++]; left1.b8[0]=bb[play_index++]; left1.b8[1]=bb[play_index++]; right1.b8[0]=bb[play_index++]; right1.b8[1]=bb[play_index++]; SSPDR SSPDR SSPDR SSPDR

= = = =

left.b16[0]; right.b16[0]; left1.b16[0]; right1.b16[0];

if(play_index >= BIG_SIZE) play_index = 0; VICVectAddr = 0; /* Update VIC priorities */ } /*--------------------------------------------------------*/ /* End of Function: sspISR */

Summary The project shows that it is easy to implement the replay of uncompressed audio data of good quality on an LPC2138 microcontroller. The processing power of ARM7TDMI core allows for real time digital signal processing like MP3 decoding. With some extra RAM (available on LPC2148) a very good quality audio player can be built for little cost. The open source code, plus free GNU, or low cost compilers are very beneficial in terms of saving time and money.