• AVR Freaks

dsPIC30F4011 + SD Card WAV Player.

Page: 12 > Showing page 1 of 2
Author
debrajdeb
Super Member
  • Total Posts : 575
  • Reward points : 0
  • Joined: 2006/03/13 01:28:29
  • Location: Bangalore, India.
  • Status: offline
2009/06/01 10:12:15 (permalink)
0

dsPIC30F4011 + SD Card WAV Player.

I created a WAV player using dsPIC30F4011 (5V device) + SD card: -

http://www.youtube.com/watch?v=EpCLC2j41as
http://www.youtube.com/watch?v=qbL6niInejw

And its working great.

For SD card interface, I had used resistor of 1.8K and 3.3K = (3.3/(1.8+3.3))*5V = 3.23V
I had to use the resistor for _SS, SCK and SDO pins (of dsPIC). For SDI pin the resistor is not required as the signal comes from SD card.
 
This project is NOT entirely done by me from scratch. But the WAV file reader is taken from the project -->
http://www.uchobby.com/index.php/2008/07/21/dspic-wav-player/
 
Thanks to the creator of the project.
 
Changes to my project are --> using dsPIC30F4011, using FRC to reduce cost further, using motor control PWM to generate stereo, an interface with LCD and the player plays 10 songs in round robin.
 
The project reads SD card, based on file system from Microchip. The Sound output is thro a 1-pole filter (0.1+0.1)uF and 1Kohms. The sound quality is good and amplitude is great to work on headphone directly without any power amplifier.
 
The demo on youtube is for a Hindi song. I am planning to put another demo for a group of (English) songs from "Bryan Adams" (Summer or '69) etc..
 
 
 
 
#1

28 Replies Related Threads

    Neiwiertz
    Super Member
    • Total Posts : 2094
    • Reward points : 0
    • Joined: 2004/09/01 02:58:52
    • Status: offline
    RE: dsPIC30F4011 + SD Card WAV Player. 2009/06/03 14:18:13 (permalink)
    0
    Hello debrajdeb

    I just added your project at the E16 gallery list at E16 Audio and Speech

    If you could shine a light on this that would be helpfull,
    For the wave file creation, could a "PCM unsigned 8 bit mono or stereo" test file at 44100 Hz (or lower)
    being used? I mean i should grab the data part of "data" subchunk and update one single channel by this repeated at 44100 Hz (or lower), in case mono wave file has been used.

    Flying With --|Explorer 16|HardWare|SoftWare|-- Fav(s) Gallery Lists
    #2
    debrajdeb
    Super Member
    • Total Posts : 575
    • Reward points : 0
    • Joined: 2006/03/13 01:28:29
    • Location: Bangalore, India.
    • Status: offline
    RE: dsPIC30F4011 + SD Card WAV Player. 2009/06/03 20:09:21 (permalink)
    0
    Hi Neiwiertz,

    Thanks for adding the project.

    Following are some more details, as you requested: -

    1. I have tested the player with WAV songs all the way from 8KHz voice files to 44KHz songs. All of them work fine.

    2. Only 8-bit can be played. 16-bit cannot be played. So for best  quality, I have tested the player with 44KHz, 8-bit, 2-channel (stereo) and it runs fine.

    3. The reason for not able to play 16-bit can be explained as (its my idea and if you think this is not correct, please let me know) -- dsPIC30F4011 max frequency is 30MHz (30MIPS). For playing a 44KHz sampled song, I am using a PWM which runs at (2 * 44KHz) = 100KHz. So the reload value of PWM for producing 100KHz = (30MHz/100KHz) = 300. Even if we run the PWM at 44KHz, we get reload value of PWM = 681. The reload value of PWM also means the max value of duty cycle (100%). These numbers (300 or 681) are no close to the max 16-bit sampled values (32767 or 65535). So there is a saturation of sound output and that results in a huge noise.

    4. I use Audacity http://audacity.sourceforge.net/ to convert mp3 songs to 8-bit WAV files and store into the player's SD card.

    5. The player works as below: -

                a. Detects SD card.
                b. Open song file (Track01.wav)
                c. Read WAV file header and detect the sampling frequency. Based on the value, initialize the Timer-1.
                d. While playing songs, the main loop reads the WAV file in chunks and store the values in a circular buffer. The timer interrupt reads each byte             from the circular buffer and loads into duty cycle.

    6. For playing stereo (2-channels) with 1-PWM (mono output), the code skips one byte of data. For playing mono (1-channel) on mono output, just get byte and place into PWM duty cycle.

    As you can see, the performance of the player (frequent interrupt) depends on the song that we are playing. I would have wished to have a DMA or sort of stuff where I could do without frequent interrupt.

    Since this project is for my own use (hobby purpose), I can share the code and schematic with any body interested.

    Regards,
    Debraj.
    #3
    Neiwiertz
    Super Member
    • Total Posts : 2094
    • Reward points : 0
    • Joined: 2004/09/01 02:58:52
    • Status: offline
    RE: dsPIC30F4011 + SD Card WAV Player. 2009/06/04 16:14:05 (permalink)
    0
    These numbers (300 or 681) are no close to the max 16-bit sampled values (32767 or 65535). So there is a saturation of sound output and that results in a huge noise.
    Very helpfull explain(s) and special this one i go check (over a while), at the E16 by using audio pictail plus, using 8-bit and re-check if the sampled values are well for sound output, maybe i should modify them to overcome any saturationSmile or first test the sound output by generate a sweep tone or single tone.

    I did have done testing using raw snd file i go try audacity, additional nice one too know about is goldwave

    Flying With --|Explorer 16|HardWare|SoftWare|-- Fav(s) Gallery Lists
    #4
    debrajdeb
    Super Member
    • Total Posts : 575
    • Reward points : 0
    • Joined: 2006/03/13 01:28:29
    • Location: Bangalore, India.
    • Status: offline
    RE: dsPIC30F4011 + SD Card WAV Player. 2009/06/04 19:43:26 (permalink)
    0
    The possible test would be to have a 16-bit sampled WAV file and the same file sampled in 8-bit. Then play both the files. The noise from 16-bit is so heavy, it will almost drown the music. But 8-bit will play fine.

    Let me know if you find any way to play 16-bit.

    Thanks.
    #5
    chris_1984
    New Member
    • Total Posts : 3
    • Reward points : 0
    • Joined: 2009/06/18 09:34:50
    • Location: 0
    • Status: offline
    RE: dsPIC30F4011 + SD Card WAV Player. 2009/06/18 15:19:06 (permalink)
    0
    Hello,

    I try to make the same project with the same source code but based on a dsPIC33F256GP710 on a explorer 16 demo board.
    I successfully detect and read the SD Card, and the output PWM works fine, but I still have a problem.
    In fact, the reading speed is very slow and I don't find the solution to solve this problem.

    Do you already have this kind of problem to help me?
    I measured the SCLK frequency and I have 125khz, that It's to slow to stream a song from a SD card. What is the frequency of your?

    This is my PLL config:

    _FOSCSEL(FNOSC_PRIPLL & IESO_OFF);
    _FOSC(FCKSM_CSDCMD & OSCIOFNC_OFF & POSCMD_XT);
    _FWDT(FWDTEN_OFF);


    and also:

    PLLFBD = 30;                //M factor from PLL M=32
    CLKDIVbits.PLLPOST = 0;     //Postscale factor N2=2
    CLKDIVbits.PLLPRE = 0;         //Prescale factor N1=2
    while(OSCCONbits.LOCK!=1) {};

    The result is : Fcpu = 64MHz   that is put in GetSystemClock
                        CPU = 32MIPS

    I ask you this question because I watched your videos and the results is surprising, and very good.
    So I think you can help me.

    I'm waiting your reponse and advices, please.

    Best reagrds

    Chris

    #6
    debrajdeb
    Super Member
    • Total Posts : 575
    • Reward points : 0
    • Joined: 2006/03/13 01:28:29
    • Location: Bangalore, India.
    • Status: offline
    RE: dsPIC30F4011 + SD Card WAV Player. 2009/06/18 18:57:48 (permalink)
    0
    Hi,

    In fact, the reading speed is very slow and I don't find the solution to solve this problem.

    -->Do you mean the song plays, but at a slow speed (like older gramophone)? Then the problem is simple and its basically related to the definitions of clock.

    I have used the dsPIC30F4011 which runs on internal fast RC (FRC) * 16/4 = 29.48MHz.
    Hence I have inserted the value of 29480000 as "GetSystemClock".

    For your case, you can define "GetSystemClock" as 32000000.

    All the best.
    #7
    asmallri
    Super Member
    • Total Posts : 1864
    • Reward points : 0
    • Joined: 2004/05/26 09:00:05
    • Location: Perth, Australia
    • Status: offline
    RE: dsPIC30F4011 + SD Card WAV Player. 2009/06/18 21:28:32 (permalink)
    0
    ORIGINAL: debrajdeb

    ... For SDI pin the resistor is not required as the signal comes from SD card.


    This could cause problems with different brands of sd cards. Before the card is put into SPI mode, the DO pin of the card is in open drain mode. Without a pull-up resistor the card may fail initialization.

    Regards, Andrew

    http://www.brushelectronics.com/index.php?page=software
    Home of Ethernet, SD Card, and Encrypted Serial and USB Bootloaders for PICs!!
    #8
    debrajdeb
    Super Member
    • Total Posts : 575
    • Reward points : 0
    • Joined: 2006/03/13 01:28:29
    • Location: Bangalore, India.
    • Status: offline
    RE: dsPIC30F4011 + SD Card WAV Player. 2009/06/19 10:41:37 (permalink)
    0
    This could cause problems with different brands of sd cards. Before the card is put into SPI mode, the DO pin of the card is in open drain mode. Without a pull-up resistor the card may fail initialization.

     
    Thanks asmallri
    I have 3 SD card with me and I was able to interface 1 and not able to interface other 2. I did not use any pull up and this might explain why.
     
    Thanks again.
    #9
    chris_1984
    New Member
    • Total Posts : 3
    • Reward points : 0
    • Joined: 2009/06/18 09:34:50
    • Location: 0
    • Status: offline
    RE: dsPIC30F4011 + SD Card WAV Player. 2009/06/24 03:13:17 (permalink)
    0
    Hello,

    Thanks for your answers that help me a lot, debrajdeb and asmallri.

    However, I have a little question about this project. In fact, I try to make a natural voice message with different sample of recorded voice.
    But I have a problem, in the transition between 2 samples. It's seems that the PWM was disconnected or stopped and the result is a "crack" sound between the two differents samples.

    Could you give me some informations?
    Is the PWM disconnected between the FSfclose() and the next FSfread() or before?
    Do you have a solution to let the PWM active when the transition happen, in order to have a an "unstopped" message?

    thanks again for your past answers.
    #10
    debrajdeb
    Super Member
    • Total Posts : 575
    • Reward points : 0
    • Joined: 2006/03/13 01:28:29
    • Location: Bangalore, India.
    • Status: offline
    RE: dsPIC30F4011 + SD Card WAV Player. 2009/06/24 03:24:19 (permalink)
    0
    Hi,

    In fact, I get some pop sound when shuffling between songs and I never bothered to look into its cause. I will have to check the code and let you know.

    Do you have a solution to let the PWM active when the transition happen, in order to have a an "unstopped" message?

    --> Since the WAV file feeds the duty cycle value for PWM, when the songs/ voice files are being changed, what will be placed in duty to keep the "PWM active"? Some fixed value of 50% duty will drive the speaker cone into a fixed position.
    #11
    hyperdyne
    New Member
    • Total Posts : 2
    • Reward points : 0
    • Joined: 2009/07/29 10:26:26
    • Location: 0
    • Status: offline
    RE: dsPIC30F4011 + SD Card WAV Player. 2009/07/29 10:33:27 (permalink)
    0
    I am trying to get this to work using the FRC also.  Do I just need to set the systemclock to 29.48MHz?  What about the peripheral clock?

    Also I am guessing the SD_CS line to the pic is RF1 (it looks like this in the hardware profile).  Is this correct?

    I have most of it wired up but the code is not getting past the FSInit() for the card.  I ended up using voltage dividers for the pic side CS, SDO, SCLK lines (1.1k and 2.2k resistors) going to the SD card.  For the pic SDI line I used 2 4401 transistors to level shift the 3.3v back to 5V (a 10k resistor from SD SDO to the 4401 base, a 10k resistor pulled up to 5V to the 1st collector, output taken at collector and run into 2nd 4401 base.  Another 10k pulled to 5V connected to 2nd collector.  Output to pic SDI is the 2nd collector.  Both emitters are grounded.) 

    So far I cant get the card recognized.  Any ideas?

    #12
    debrajdeb
    Super Member
    • Total Posts : 575
    • Reward points : 0
    • Joined: 2006/03/13 01:28:29
    • Location: Bangalore, India.
    • Status: offline
    RE: dsPIC30F4011 + SD Card WAV Player. 2009/07/30 02:47:57 (permalink)
    0
    My board is simpler with resistor divider for 5V to 3.3V. The signals which are out from SD card are already 3.3V and hence connected directly to dsPIC.

    I worked on this project quite sometime back. I can send you the code -- let me know your email ID.

    Regards,
    Debraj.
    #13
    hyperdyne
    New Member
    • Total Posts : 2
    • Reward points : 0
    • Joined: 2009/07/29 10:26:26
    • Location: 0
    • Status: offline
    RE: dsPIC30F4011 + SD Card WAV Player. 2009/07/30 09:26:42 (permalink)
    0
    Cool, I did get it to work by just running the SDO to SDI.  I would love to see how you did it, my email is jshima @ comcast.net

    Trying to get it to loop a sound right now, but am getting a pop when it loops.  Any ideas on fixing that?


    #14
    PsIOn
    New Member
    • Total Posts : 21
    • Reward points : 0
    • Joined: 2005/12/29 09:26:38
    • Status: offline
    RE: dsPIC30F4011 + SD Card WAV Player. 2009/07/31 13:35:38 (permalink)
    0
    Hi Debraj,

    If possible, I would also like to see your code for this pretty cool project.

    psi@ipac.ws

    Thanks

    -PsI

    Ps. I liked the Hindi song ;o)
    #15
    debrajdeb
    Super Member
    • Total Posts : 575
    • Reward points : 0
    • Joined: 2006/03/13 01:28:29
    • Location: Bangalore, India.
    • Status: offline
    RE: dsPIC30F4011 + SD Card WAV Player. 2009/07/31 21:44:27 (permalink)
    0
    I have sent the code to you -- PSIOn and hyperdyne.

    Also, this code, I had worked sometime back and will be looking into it after some days. So no real clue as such for solving the pop sound. But my idea would be to disable the PWM untill the file is searched and ready to play..
    #16
    PsIOn
    New Member
    • Total Posts : 21
    • Reward points : 0
    • Joined: 2005/12/29 09:26:38
    • Status: offline
    RE: dsPIC30F4011 + SD Card WAV Player. 2009/08/03 09:57:04 (permalink)
    0
    Thanks again, I'll try this out as soon as I get a Dspic ;o)

    Re: Pops and Clicks, how about trying this guys approach of "Soft Starting" audio play back...

    http://www.sfcompiler.co.uk/wiki/pmwiki.php?n=SwordfishUser.SDMMCWavPlayer

    It looks like a sound approach, no pun intended ;P
    #17
    remobj
    New Member
    • Total Posts : 9
    • Reward points : 0
    • Joined: 2009/03/06 00:50:01
    • Location: 0
    • Status: offline
    RE: dsPIC30F4011 + SD Card WAV Player. 2009/11/22 07:32:09 (permalink)
    0
    Hi. debrajdeb,
      Well, I am new to this idea of processing audio files. I have read through your detailed explanation and I have some queries.

    1) Does this mean that a cpu working at less than 30 MIPS is not sufficient for this application? I was looking at the pic24f /pic24H family. But they are all running at 16 mips max.  Please advise.
    2) Have you made use of any of speech decoding libraries available with microchip?
    3) I would really appreciate if you could send me the schematic and code. My email id is remobj@gmail.com.
      
    #18
    Guest
    Super Member
    • Total Posts : 80500
    • Reward points : 0
    • Joined: 2003/01/01 00:00:00
    • Location: 0
    • Status: online
    RE: dsPIC30F4011 + SD Card WAV Player. 2009/11/22 07:38:57 (permalink)
    0
    BTW this brilliant masterpiece from Elm Chan beats this dsPIC project with a single 8-pin TinyAVR.

    aspforum.mchp.guest
    #19
    debrajdeb
    Super Member
    • Total Posts : 575
    • Reward points : 0
    • Joined: 2006/03/13 01:28:29
    • Location: Bangalore, India.
    • Status: offline
    RE: dsPIC30F4011 + SD Card WAV Player. 2009/11/23 08:32:46 (permalink)
    0
    Thanks for the link. The project looks amazing. Speciality of the project is FAT system, which can fit into small memory size.
    #20
    Page: 12 > Showing page 1 of 2
    Jump to:
    © 2019 APG vNext Commercial Version 4.5