MP3 player powered by microchip pic18f

10 May 2010

Ok, so my second year in university is coming to an end, and it is that time of the year where i have to spend half of my time in the library trying to catch up on all the lectures i missed during the semester, I am unfortunate enough this year to also have a pending second year design project which is supposed to account for quite alot( so i hear). The good part is that its based on a topic I LOVE!! that is micro-controllers.

Being the innovative guy that i have always been, i decided to undertake a project that no one else in the past had attempted ( within our departments at least) mainly due to lack of what my Spanish mates would call “mucho grande cajones”. Despite the fact that I am lazy(ok,not really) and that research is the last thing i would do in my free time, I decided to undertake this hugely but time consuming and brain degenerating task of making a PIC powered MP3 player intuitively called “MPic3 Player”. Don’t get me wrong, I appreciate all work as long as it involves a bit(preferably a lot) of computing, as this is my speciality.

Here on this part of the blog, I will divert from the usual banter on the latest technology and try to update my dear readers on the progress of this awesome project.

All I know at this moment about what I am about to attempt is that, I am going to use a PIC18f46k20 from microchip, a VS1011E-s mp3 decoder from vlsi solutions, an SD/MMC card connector + card. The rest of the component like the capacitors, transistors, resistors, 2 x oscillators (how do i know i need them now? well I am an engineer after all) a voltage regulator, and maybe, just maybe, an LCD screen. All this coupled with LOADS and LOADS of programming and possibly prayers will results in a beautiful  home made MP3 player.

I will keep all you punters posted on my progress…stay tuned!

PS: this post is not consistent with my work, it might contain some information that is way overdue, I intend to finish this project by the first week of may, if you are reading this post after this date, and the project is not complete, please send me an e-mail reminder to update my blog which I shall loyally oblige.  I will most likely upload my entire report in the mid of may

                                                Summary

This report describes the design and testing of a portable media player, powered by a Micro-chip PIC18F46k20 micro-contoller. The report contains detailed information on all the software that has been developed in C and also all the components used. Due to the complexity of this project, some proven methodologies have been borrowed, examples being the FAT32 system employed by the SD card. Due credit is given where materials produced by a third party have been used.

                                                    HARDWARE DESCRIPTION

The MP3 player used quite a number of components. This part of the report will contain the detailed description of all the working parts.

There are three bits of hardware of utter importance, they are

  1. Microchip PIC18F46k20
  2. VLSI VS1011E-S MP3 decoder
  3. SD/MMC Card connector from Kyocera.

 

1.0 Microchip PIC18F46k20

The PIC18f46k20 is a high performance RISC CPU with an optimized architecture for C compiler. The general design of this chip makes it an ideal choice for many high performance but power sensitive applications. It packs high performance computational performance at an economical price with the addition of an enhanced flash program memory. This micro controller has loads of features, those of importance to this project include:-

  • 1MB Data EEPROM
  • 16 MIPS (Million Instructions per Second)
  • 16 bit wide instructions, 8-wide data path
  • Priority  levels for interrupts
  • A 16 MHZ internal clock scaling up to 64Mhz using software and available PLL( Phase Locked Loop)
  • Secondary oscillator using Timer1 at 32 Khz
  • Has an operating voltage range of 1.8V to 3.6V
  • A 3v3 ICSP (In Circuit Serial Programmer) via two pins
  • Analogue to digital convertor module with 10 bit resolution, 13 External Channels.

1.1Peripheral Highlights

  • Up to 35 I/O pins with 1 exclusive input only pin
  • Master Synchronous Serial Port (MSSP) module 
  • 3 wire SPI (using ports RC3, RC4 & RC5 for clock, input and output respectively) an additional port can be used while in slave mode(slave select RA5) 

1.2PICkit 2 Programmer/Debugger

For this particular chip, the PICkit 2 Development Programmer /Debugger will be used. It is a low cost development tool with an easy to use interface for programming and debugging the PIC18f46k20 flash. It also enables in-circuit debugging, this allows the engineer to see the state of the executed by analysing the state of variables and memory registers, it also allows file registers to be examined and modified at break points

1.3 Master Synchronous Serial Port (MSSP)

The Master Synchronous Serial Port module is the serial interface of the microcontroller. Its main use is to communicate with other peripherals or other micro-controllers (if in a network). These peripheral devices might be display drivers, SD/MMC cards, Audio Decoders, MIDI players or other memory locations.

The MSSP operates in two modes, this project makes heavy use of the Serial Peripheral Interface(SPI)

1.4 Serial Peripheral Interface (SPI) mode

This mode allows 8 bits of data to be synchronously transmitted and received simultaneously. It allows a fast and easy method for communication between two or more devices.

SPI is a synchronous protocol that allows a master device to initiate communication with a slave device. Data is exchanged between these devices. In almost all cases, the micro controller is the master device as it is easily programmable.

Since SPI is synchronous, there has to be a clock pulse along side the data. The clock signal is provided by the micro controller (master) to provide synchronization. The clock signal controls when data can change and when it is valid for reading/writing operations.

Since SPI has a clock signal, the clock can vary without disrupting the data. The data rate will simply change along with the changes in the clock rate. This makes SPI deal when the microcontroller is being clocked imprecisely, this project uses a 24.57Mhz crystal oscillator.

Most importantly, SPI is a data exchange protocol, as data is being clocked out, new data must be clocked in. In this case, data is clocked in from the SD card, then read into new variables/buffers, then clocked out onto the audio decoder.

Whenever more than one slave device exist, chip select(CS) or Slave Select (SS/RA5) ports must be used. This project utilizes the CS and XCS ports of the SD card and the audio decoder respectively. It indicates to a slave that the master wishes to start an SPI data exchange between that slave device and itself. The signal is most often active low, so a low on this line will indicate the SPI is active, while a high will signal inactivity.

In SPI, data typically changes during the rising or falling edge of SCK. This is how the data is synchronized with the clock signal.

Note, data only changes on the falling edge of the clock, and is only read on the rising edge of SCK. Sampling is also done on the opposite clock of when data changes.

An illustration of the MP3 serial connection is shown below.

 

2.0 VLSI VS1011E-S MP3 decoder

The choice for the decoder was brought about by its simplicity and low power requirements. It also has good audio quality. The other biggest factor was that it incorporates a DAC as well as a direct interface to the earphones, thus simplifying the design tremendously.  For this project, the VS1011e MPEG Audio Codec from VLSI Solution will be used. This device contains all the necessary components for successfully decoding and playing the mp3 files.

Some of its useful features include:

  • High quality stereo DAC
  • Stereo earphone driver capable.
  • High performance, low power DSP core
  • Decodes MPEG1.0 and 2.0 Audio layer III and WAV
  • Up to 320 Kbit/s MP3
  • Separate serial control and data interfaces
  • Volume, bass and treble controls
  • Separate 2.5…3.6 V operating voltages for analog and digital
  • New functions may be added with software and 4 GPIO pins

 

 

                                                    

The following is the description of the signals used:

  • SO – SPI serial output
  • SI – SPI serial input
  • SCLK – SPI serial clock
  • XCS – SPI chip select commands
  • XRESET – chip Reset
  • XDCS – SPI chip select for data
  • DREQ – Data request

Once the chip is configured, it only needs a steady stream of data to be fed via XDCS, the occasional requests to change volume, bass or treble comes from the XCS and thus does not interfere with data transfer.

The microcontroller monitors the DREQ port of the VS1011e, when it is high, data is fed to the device. When DREQ is asserted to high, it means that the VS1011e is capable of accepting at least 32bytes of data, once it goes low, the micro-controller stops sending data.

The audio decoder has the capabilities of accepting commands for bass, treble and volume, at this point, there are going to be some crucial tradeoffs. The project does not include any of these controls manually, rather they can be set in software. A later revision of the system might include these fancy buttons.

For the software control, the volume is controlled by the SCI_VOL register in the vs1001e. This is a 16 bit register, with the upper 8 bits for the left channel and the lower 8 bits for the right channel. This allows the system to have full stereo. A value of 0 represents the highest volume and surprisingly a value of 255 represents mute. Each 256 step is a 0.5dB increment, so the system has an overall of 128dB of sound, which is as loud as a chainsaw! On power-up, the volume of both channels will be set to 31 that is roughly 112dB. The SetVolume(BYTE vRight, BYTE vLeft) function is used to modify the volume

The bass is controlled in an almost similar manner. The SCI_BASS register in the VS1011 contains controls for both the bass and treble. Bass control has two settings, bass boost and frequency limit. The boost control value ranges from 0 to 15, with 0 being off and each step being equivalent to 1dB of bass enhancement.

The frequency limit also has a 0 to 15 range with each step being equal to 10Hz.

Another important feature of this decoder is that it can be operated without a microcontroller, this sort of operation can be found in devices where the sound to be played is mostly repetitive and control being restricted to on/off, example being toys.

                                                                3.0 SD/MMC CARD

This project utilizes an SD/MMC card connector together with an SD card. This is to allow the storage of more files and to give the system more storage that the micro controller greatly lacks.

Secure Digital is a flash memory card format that is very popular amongst hand held and other portable devices. They are based on the older Multi Media Card(MMC) format, but most are physically slightly thicker than MMC cards, they also boast higher data transfer rates. Digital Rights Management (DRM) features are available but none is going to be used on this occasion. SD cards measure 32mm x 24mm x 2.1 mm.

3.1 Transfer modes

At physical level, SD supports at least three transfer modes:

  1. One-bit SD mode – separate command and data channels and a proprietary transfer format.
  2. Four-bit SD mode – uses extra pins plus some reassigned pis
  3. SPI mode – a simpler subset of the SD protocol for use with micro-controller. SPI discussed in depth in section 2.5

As there is a wide range of SD cards out there in the markets, there has arisen the need to classify them in terms of speed. These classes are 2,4,6, and 10 with transfer speeds of 2,4,6 and 10 MB/s respectively.

3.2 SPI bus concept

The SPI bus allows one bit data line by 2-channel (Data IN and Data Out). The SPI compatible mode allows the MMC host systems to use SD cards with little change. SPI mode is byte transfers.

Pin Number Name
1 Chip Select(CS)
2 DataIN (SI)
3 VSS1
4 VDD
5 CLK
6 VSS2
7 DataOut(SO)
8 &9 DAT1 & 2

 

The SPI mode is compliant with the Serial Peripheral Interface (SPI) specification. Its bus architecture includes the following signals:

  • CS: Host to card Chip Select signal
  • CLK: Host to card clock signal
  • MOSI: (Master Out Slave In) Host to card single bit data signal
  • MISO: (Master In Slave Out) Card to host single bit data signal

Both SD/MMC and SPI modes use the single master/multiple slave bus architecture to communicate with the end devices and/or media cards.

For the micro controller to be able to access the SD card, it has to connect via Chip Select (CS) port, this is particularly important if there was more than one card on the system. A card is selected by asserting(active low) CS. CS must be continuously active for the duration of the SPI transaction.

3.3 SD Card Registers

There is a set of seven registers within the card interface. The Operating Condition Register (OCR),Card Identification Register(CID), card specific data(CSD) and SD Card Configuration Register (SCR) carry the card configuration information. The RCA register holds the card relative communication address for the current session.

The card status and SD status registers hold the communication protocol related status of the card.

 for those who are always in a hurry and cannot remember the website, you can download the PDF version of this page from here

this is a much better link

3 Responses »

  1. use the second link to download the file, the first one is full of ads

  2. ok, very interesting write up, i am an IT professional and i also a micro-controller hobbyist. I have been thinking of integrating an MMC card on one of my projects, and ur good example here has shown me how easy it is to do it, do u mind posting the code as soon as possible?

  3. all in good time, i have not submitted this work for moderation, but as soon as i do it, i will post everything online. what exactly are u working on?

Leave a Reply

;?>