PIC32MX SD-Card Wave File Player

Works done? Proud of it? Show off here! Let's see what you've built can help inspire others.

PIC32MX SD-Card Wave File Player

Postby Brian Griffin » Wed Apr 25, 2012 11:12 pm

Project Name: PIC32MX SD-Card Wave File Player

Author/Designer: Y H

Project description: Simple wave file mini jukebox. Continuously plays *.wav files and return to starting point and repeats. DAC is in the form of PWM to save pins. The system will not play the file if the wave file is invalid in format. The system is fitted into a Christmas decoration (not shown in video) as an external sound player. User improvisation of the fittings and the enclosures are welcome. Plays only one-channel, Mono 8-bit wave files, from 8kHz sample rate to 44.1kHz sample rate. FAT16 is only used because of space constraints in the microcontroller.

Video:

Software:
1.) MPLAB C32 v2.01, MPLAB IDE v8.80
2.) SD-Card Routines using MDDFS (Memory Disk Drive File System) from Microchip Application Libraries v2011-10-18.
3.) Double-buffering technique

Hardware:
-Microcontroller: PIC32MX120F032B. (SPDIP) [Future Projects will involve higher end PIC32MX1xx series]
-SD-Card Slot: DFrobot SD-Module. (obtainable from Cytron)
-UART-USB converter: Cytron UC00B.
-Cytron ICSP Universal Socket.
-Crystal: 10MHz.
-Power supply from the UART-USB converter.
-DAC using Pulse Width Modulation.
-RC First-order Low-Pass filter (still under testing, will improve this on future revisions)
-Carrefour Speakers. (Connections to a larger amplifier is untested - please use small speakers)

Schematic:
schematic.jpg
Schematic of the Project


Source Code: "test2-wav.zip". (It was in a test when I try to make that thing, hence the name.)

Remarks: The "HardwareProfile.h" in the "C:\Microchip Solutions v2011-10-18\MDD File System-SD Card" (or where you installed it) has a bit of a problem - it detects the "CD" pin on the SD-Card holder, which could be a problem if you need to save some wiring. I'm supplying the modified "HardwareProfile.h" inside to prevent the system from detecting the "CD" pin. You need to extract the provided "HardwareProfile.zip" into the "C:\Microchip Solutions v2011-10-18\MDD File System-SD Card" and overwrite it.

If you have problems compiling because of the missing "system.h", go to "Project->Build Options->Project", then click on the "Directories" tab, then the drop-down menu "Show Directories For", and select "Include Search Path". On the "C:\Program Files (x86)\Microchip\mplabc32\v2.01\pic32-libs\include\peripheral" in the box when it's selected, take out the space and the "(x86)" after the "Program Files". It should be this: "C:\Program Files\Microchip\mplabc32\v2.01\pic32-libs\include\peripheral".

The UART is optional. It is just for debugging purposes.

Note: LPF (Low Pass Filter) values suggested a 0.01uF capacitor and a 1K resistor. Connect the output to Pin 11 after the LPF. Use a small speaker.
Attachments
test2-wav.zip
Source Code
(67.69 KiB) Downloaded 533 times
HardwareProfile.zip
HardwareProfie.h (Modified)
(5.67 KiB) Downloaded 513 times
PIC - UIC00B from Cytron (replacement for my broken PICKit 2), Pickit 3, MikroC for PIC
dsPIC - MikroC for dsPIC, mikromedia board (dsPIC33)
AVR - AVR Dragon
Parallax - Prop tool
User avatar
Brian Griffin
Enthusiast
 
Posts: 403
Joined: Mon Jan 17, 2011 9:36 am

Re: PIC32MX SD-Card Wave File Player

Postby Brian Griffin » Thu Apr 26, 2012 1:24 am

Another post about the program flow:

The program starts by initializing everything, PWM, ports and activating selected ports.

1.) The SD-Card is checked, loaded and initialized. The system seeks for the first *.wav file inside. If it's invalid, it'll search for another one.

2.) Once it's found, the wave file header is checked. The first 1024 and another 1024 bytes of the file is dumped into memory (RAM). The first 44 bytes are checked. Here, the details like sample-rate, size, format and such are stored inside. If it's invalid, the system will drop the wave file and find another one. Read: https://ccrma.stanford.edu/courses/422/projects/WaveFormat/ for more details on the wave file.

3.) When the wave file is successfully detected, the PWM interrupt is initialized, and then the interrupt is feeding each wave file sample into the output from the first 1024 bytes dumped in RAM.

4.) Once all the samples in the first 1024 bytes is used, it'll go to another 1024 bytes for reading. The first 1024 bytes read previously is refilled.

5.) This process in (4) goes on and on, which the other is being played, other is being refilled. They take turns.

6.) When the file reaches the end, it stops, PWM interrupts shut off and then find another wave file. Process repeats and goes back to (1).
PIC - UIC00B from Cytron (replacement for my broken PICKit 2), Pickit 3, MikroC for PIC
dsPIC - MikroC for dsPIC, mikromedia board (dsPIC33)
AVR - AVR Dragon
Parallax - Prop tool
User avatar
Brian Griffin
Enthusiast
 
Posts: 403
Joined: Mon Jan 17, 2011 9:36 am

Re: PIC32MX SD-Card Wave File Player

Postby shahrul » Thu Apr 26, 2012 2:23 am

Wow, this really advanced project to me. I like to do it.
User avatar
shahrul
Professional
 
Posts: 812
Joined: Sat May 16, 2009 9:54 pm
Location: Selangor

Re: PIC32MX SD-Card Wave File Player

Postby ABSF » Thu Apr 26, 2012 7:16 am

How much memory is required to store a 3-minutes song on the SD card?
The 2G SD is dirt cheap nowadays. What's the biggest SD can it support?
Looks and sounds cool. Do keep up with the good work...... 8-)

Allen
The next war will determine NOT who is right BUT what is left.
User avatar
ABSF
Professional
 
Posts: 810
Joined: Wed Nov 10, 2010 9:32 am
Location: E Malaysia

Re: PIC32MX SD-Card Wave File Player

Postby robosang » Thu Apr 26, 2012 9:00 am

Brian, great project show case, like it a lot, but no time to explore yet!
robosang
Expert
 
Posts: 1239
Joined: Wed Jun 10, 2009 5:37 pm

Re: PIC32MX SD-Card Wave File Player

Postby Brian Griffin » Thu Apr 26, 2012 9:52 am

ABSF WROTE:How much memory is required to store a 3-minutes song on the SD card?
The 2G SD is dirt cheap nowadays. What's the biggest SD can it support?
Looks and sounds cool. Do keep up with the good work...... 8-)

Allen


Uh, I don't remember, but it's like 40MB if it's a CD-quality (44.1kHz). The biggest is only 2GB due to the FAT16 support.

For the newer PIC32MX1xx series they have much bigger flash memory space, up to 128KB. Then, I'll talk about using long file name support and FAT32. The SDHC is currently not supported as the MDDFS (Microchip Disk Drive File System) is an old version.

Due to the lite version of the compiler, it takes up a lot of space due to the lack of optimization. I'm going to save some money and invest on a professional version MPLAB XC32, but it's going to take years to do it. :lol:
PIC - UIC00B from Cytron (replacement for my broken PICKit 2), Pickit 3, MikroC for PIC
dsPIC - MikroC for dsPIC, mikromedia board (dsPIC33)
AVR - AVR Dragon
Parallax - Prop tool
User avatar
Brian Griffin
Enthusiast
 
Posts: 403
Joined: Mon Jan 17, 2011 9:36 am

Re: PIC32MX SD-Card Wave File Player

Postby Brian Griffin » Fri Dec 21, 2012 2:17 pm

As promised, I've upgraded the wave file player to support long file names and FAT32, so you can put more songs inside. The new chip is PIC32MX150F128B which is identical to the PIC32MX120F032B except the new one contains 128KB flash, so there will be more space for such support.

As again, this thing can be ported to Uno32, but with the bootloader wiped out.

This uses the MPLAB XC32 v1.0, with Microchip Applications Library v2012-08-22.
Attachments
test3-wav.zip
wave file player (updated)
(3.99 KiB) Downloaded 465 times
PIC - UIC00B from Cytron (replacement for my broken PICKit 2), Pickit 3, MikroC for PIC
dsPIC - MikroC for dsPIC, mikromedia board (dsPIC33)
AVR - AVR Dragon
Parallax - Prop tool
User avatar
Brian Griffin
Enthusiast
 
Posts: 403
Joined: Mon Jan 17, 2011 9:36 am

Re: PIC32MX SD-Card Wave File Player

Postby robosang » Sat Dec 22, 2012 4:23 pm

Nice work..... no time to explore this :(
robosang
Expert
 
Posts: 1239
Joined: Wed Jun 10, 2009 5:37 pm


Return to Project Showcase

Who is online

Users browsing this forum: No registered users and 4 guests