1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

Audio recording/playback using PIC

Discussion in 'Microcontrollers' started by piper91765, Aug 20, 2008.

  1. piper91765

    piper91765 New Member

    Joined:
    Aug 12, 2008
    Messages:
    16
    Likes:
    0
    Hello all,

    I have a senior project that I need to get started on and I was looking for some guidance. My goal is to record a guitar solo for later playback using a µController. I need to create a circuit that has the following functionalities:

    1) Record mid to high quality audio using a µController, audio recording IC, or a combination of the two.
    2) IC/uC must be able to store 1-2 minutes with a sampling rate of 44.1k.
    3) Store this audio using either internal memory or on an external SD card.
    4) Have the ability to playback the audio on demand via control of a uC.

    If you have any ideas, please feel free to share them. Also, if you have seen similar projects, please let me know!
    Thanks
     
    • Disagree Disagree x 1
  2. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,328
    Likes:
    653
    Location:
    Derbyshire, UK
    ONLINE
    Assuming mono, and 16 bit (or 10 bit if using most common PIC's), you will require just over 5 megabytes per minute.

    PIC's have a few tens, or at most hundreds, of bytes of 'RAM', so that's not going to happen :D

    An SD card is a better possibility, but I'm not sure how fast you can write to them?.

    That's no problem at all, you should be able to read an SD card that fast easy enough and output via a D2A.

    Obviously you MUST have anti-aliasing filters on both input and output.
     
  3. piper91765

    piper91765 New Member

    Joined:
    Aug 12, 2008
    Messages:
    16
    Likes:
    0
    Thank you for your response. A quick google search revealed this:

    http://www.thetechzone.com/?m=show&id=190

    It basically says that a 32x SD card can be written to at a speed of 4.8MB/s, i'm not sure if a PIC can write to the card that fast, but the card seems to have the capability of accepting high speeds.

    I'm not very familiar with Anti-Aliasing, i'll have to look that up when I get the chance.

    Any design consideration advice?

    Also, i'm worried about programming. I am assuming that I should try and store this data in a relatively known format such as WAV, is anyone aware of a sample code that I could look at to help me program this pic to store the audio in WAV?
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. transistance

    transistance New Member

    Joined:
    Apr 3, 2008
    Messages:
    154
    Likes:
    1
    Location:
    Istanbul

    Here are some designs that might help you out:
    120 Second Voice Recorder
    Simple Voice Recorder

    Give more details on your project requirements and restrictions - such as type of microcontroller, budget, etc...
     
    Last edited: Aug 21, 2008
  6. piper91765

    piper91765 New Member

    Joined:
    Aug 12, 2008
    Messages:
    16
    Likes:
    0
    I couldn't check thoes links here at work because my firewall didn't deem them "work appropriate" so I'll check them when I get home tonight.

    Budget: $500 (but i know it shouldn't cost that much)
    Features: I would like a high quality recording, something that is a full 44.1k sample rate would be nice.
    Type of uController: Any that works, I don't have any preference to a single brand, but I may need one with a lot of ports, because I'm going to need to interface with an SD card and have controls for stop,play, etc.

    I was looking at this as an altertnative to an SD card.
    http://hem.passagen.se/communication/speach.html
    But I'm worried about sound quality. I don't want this to sound like an answering machine, so I don't know if this chip is appropriate.
     
  7. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,328
    Likes:
    653
    Location:
    Derbyshire, UK
    ONLINE
    It's similar to the links posted, a voice quality recorder chip - like I said above, you need around 5 megabytes to store 120 seconds of mono 16 bit audio at CD quality.
     
  8. Someone Electro

    Someone Electro New Member

    Joined:
    Sep 10, 2003
    Messages:
    2,579
    Likes:
    2
    Location:
    A boring village in Europe (slovene)
    i did such a project with a SD card and a dsPIC30F without any other ICs. It could do 48Khz without a problem. But i didn't make it record also.
     
  9. piper91765

    piper91765 New Member

    Joined:
    Aug 12, 2008
    Messages:
    16
    Likes:
    0

    I hear what you're saying Nigel, I'm leaning toward the SD card idea because the 120 sec chip has a max sample rate of 8.1 k samples/sec (that's telephone quality)

    I calculate 5.05 MB per min:
    44,100 (samples/sec) *60 (sec/min) *16 (Bits/sample) * 1/8 (byte/bit) * 1/1,048,576 (MB/ bytes)= 5.047 MB (using unit conversion)

    Let me know if any of that is incorrect. Are you dividing by two due to the mono? That is to say 22,050 samples per channel per second?
     
  10. piper91765

    piper91765 New Member

    Joined:
    Aug 12, 2008
    Messages:
    16
    Likes:
    0

    Any help with the programming? (that's what i'm worried about) Documentation? Website assistance?
     
  11. Someone Electro

    Someone Electro New Member

    Joined:
    Sep 10, 2003
    Messages:
    2,579
    Likes:
    2
    Location:
    A boring village in Europe (slovene)
    Yeah i have a little for you

    Code that interfaces a SD or CF memory card or a IDE harddrive and even handles a FAT12 FAT16 or FAT32 filesystem
    http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1824&appnote=en532040

    Information about the WAV file format
    http://ccrma.stanford.edu/courses/422/projects/WaveFormat/


    As for the DAC i just used a PWM at a very high frequency and used a resistor and capacitor filter on it, It seams to produce a excellent sound ( better than a cheap PC sound card ) Or one of the dsPIC33F chips has a built in audio DAC with its own buffer.
     
  12. piper91765

    piper91765 New Member

    Joined:
    Aug 12, 2008
    Messages:
    16
    Likes:
    0



    Thanks, I'll review these.
     
  13. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,328
    Likes:
    653
    Location:
    Derbyshire, UK
    ONLINE
    Sorry, refer to my earlier post, 5 megabytes per minute.

    No, the 44.1KHz is per channel, I incorrectly typed the time for one minute only.
     
  14. Eurisko

    Eurisko New Member

    Joined:
    Aug 19, 2008
    Messages:
    7
    Likes:
    1

    In SD 4-bit mode, that speed is probably doable. In SPI single-bit mode, you'd be lucky to hit 1 MB/sec. The 25 MHz max clock speed and the cards internal latency will reduce the transfer speed considerably.

    The good news is that you only need to transfer 88.2 KB/sec. The SD card could do that in stereo. Or quad.

    16 bit wave files (uncompressed) are incredibly easy to process. You just have to read the data from the SD card into a RAM buffer, read out two bytes 44100 times a second, popping the data into a 16 bit DAC. The output of the DAC goes into an audio amplifier, and Voila! CD quality sound.

    Use an interrupt service routine to keep the DAC busy. The ISR can flag the main program when the RAM buffer needs attention.

    The nice thing about the SD card's SPI mode is that the clock can be slowed down or shut down at any time. The ISR can interrupt the program at ANY point, and the SD card doesn't even care!
     
    Last edited: Aug 21, 2008
    • Like Like x 1
  15. Someone Electro

    Someone Electro New Member

    Joined:
    Sep 10, 2003
    Messages:
    2,579
    Likes:
    2
    Location:
    A boring village in Europe (slovene)
    SD cards are fast no drought even with 25Mbit SPI. But you are going to need a MCU with a lot of ram. I recommend you have an at lest 1KB of buffer between the card and the DAC. That is because the card is read in 512B chunks, reading one chunk is fast. But when it gets to the end of it it needs to go look back in the FAT16 table where the next chunk it then just to that chunk and read it.This takes some time you you need a big enough buffer so it dosent get drained completely when it dose that.

    Also take a look at the dsPIC33F micronctroler family. They have a 40MIPS 16bit CPU with a DSP endgine that helps it with math. Also it has a preperial inside that moves data between ram and other preperials without the CPU doing it.Also one other sweet thing is that some have a built in stereo audio DAC that has its small buffer in it.This means you only interupt when your buffer needs to be filled That means a LOT less interupts and saveing a lot of the CPU time so you have lots of room for other stuff. (These MCUs are esaly fast enough to do things like digital tone controll and such effects along playing it)
     
    • Like Like x 1
  16. piper91765

    piper91765 New Member

    Joined:
    Aug 12, 2008
    Messages:
    16
    Likes:
    0
    Ok, so I have a handle on the hardware I should use.

    My plans are:

    1) Impliment some type of bandlimiting filter on the input to A/D converter (400 Hz to 20kHz = guitar audio range)
    2) Use pic33f family uController (I looked over the specs and they look impressive).
    3) Use SD memory card to store data.
    4) Amplify signal after D/A converter to speaker (maybe another filter, I dont know if its necessary).

    Thoes are my hardware considerations.

    Someone earlier mentioned anti-ailising filters, can anyone explain what that is used for and where to impliment them?

    Also, I'm at a loss for how to program this thing. Maybe I should formulate a high level plan for the two modes (record/play) and see what you guys think. I'll work on it.

    Any comments?
     
  17. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,328
    Likes:
    653
    Location:
    Derbyshire, UK
    ONLINE
    Those are the filters before conversion to digital, and after conversion back to analogue - both are essential.
     
  18. Someone Electro

    Someone Electro New Member

    Joined:
    Sep 10, 2003
    Messages:
    2,579
    Likes:
    2
    Location:
    A boring village in Europe (slovene)
    That filter is basically a low pass filter that filter out whats above a certain frequency. It dose work without it but it will improve the audio quality. That filter on the DAC is not as inportant as the one on the ADC but it dose inprove the quality a little.(It will help a lot with very low sample rates)

    What this filter dose is filter out the frequencys too high for the sample rate to capture. If you leave them in they become noise. As for the output it smooths out the signal, because the signal is slightly chopy because of the sample rate and bit depth.

    With all this you should be able to produce crystal clear sound with only a dsPIC (And some kind of amp chip if you want to drive headphones or speakers directly from it)

    Also one important thing is a clean power supply. Noise on the power supply will cause noise in your analog input and output.

    Also note that an SD card is NOT a 5V part. It works on 3.3V , this is also why i recommended a dsPIC33F since they work on 3.3V also and you can get them in PDIP so you can put the stuff together on a breadboard.

    Oh and i hope you know how to program in C, since to use the FAT filesystem lib you will need to compile it with MPLAB C30 compiler, so that means you will also have to write your code in C.
     
  19. piper91765

    piper91765 New Member

    Joined:
    Aug 12, 2008
    Messages:
    16
    Likes:
    0

    Thank you for the advice on the power supply, I will be sure to use a regulated dc supply.

    I'll be using an LM386 chip to amplify the signal. I've had good experience in the past using it.

    I do know C++ but i've only made programs that work in the CMD prompt. I have used asembly to write to a uC before, but that was a long time ago, and it was with a Motorola 68HC11 board. I need to do some research on the MPLAB C30 program that you're talking about. I'll read up on it. My goal is to learn how to read/write to the sd card, then learn how to read from the A/D converter and write to the D/A converter.

    I guess I have a lot to learn.
     
  20. FredCDobbs

    FredCDobbs New Member

    Joined:
    Aug 22, 2008
    Messages:
    2
    Likes:
    0
    Use a Cirrus CS5330 for the A/D and the antialias filtering is included.

    Use a Cirrus CS4338 for the D/A.

    If non-volatility is not essential, some old 30pin SIMM's (Dynamic Rams) may be directly controlled by a PIC to meet your 2 minute storage requirement.

    The PIC will need to run at about 22 MHz or so (24.576 MHz is the magic number for 48KHz sampling) to service this arrangement. An 18F4221 is a good choice.
     
  21. Eurisko

    Eurisko New Member

    Joined:
    Aug 19, 2008
    Messages:
    7
    Likes:
    1

Share This Page