PIC-based Voice Recorder

[Vinod] just finished building a voice recorder and it turned out even better than he thought it would. The video after the break shows him recording what is surely one of your favorite songs from his cellphone and then playing it back. The audio quality does sound quite good for a project with very few components.

A PIC 16F877A makes up the majority of the build. Its ADC is used to capture the incoming line from an amplified microphone input (you’ll find that amp schematic half way through his post). He’s storing the data on an MMC card, which was a bit of a hack since the PIC has limited RAM to manage that overhead. The stored data is in a raw format, as the card is not accessed using a file system. This makes it easy to record at a high bit rate, leading to better audio quality. Playback consists of connecting a speaker via a low-pass filter and amplifier circuit to the hardware PWM output on the PIC.

[youtube=http://www.youtube.com/watch?v=Mn1VsM-i8QI&w=470]

34 thoughts on “PIC-based Voice Recorder

  1. I really like the documentation, specially the part about using the card, well done. I think an improvement can come from biasing the analog in to VCC/2 by adding another 220K resistor from the pin to VCC. The amplifier should have a dc blocking cap. This should improve the quality.

    I’ve designed some sort of music/info playing box that could play a file stored on an SPI flash memory(required high temp functionality that SD/MMC could not provide) and found that 8bit R2R resistor made DAC was much better than PWM in terms of quality, and a 10bit R2R DAC could improve on the 8bit, but further resolution increasing provided no gain. So, you might try an R2R DAC and see if improves.

    This post reminds me of when i was learning to use the ADC on an 16F876. A friend told me about an ATMEGA8. 4x RAM, faster, no external oscillator and 1/3 of the price of the PIC. Never used an 8bit pic since, but i do like the dsPIC thou…

    1. PIC vs AVR, wich is best… Well the price doesn’t matter much any more.
      16F876: 5,59E <dip28, pretty hard to get and pricy.
      16F877: 6,14E <dip40, popular hobby PIC.
      18F4455: 5,48E <dip40, my choice atm
      Atemega8: 4,14 <dip28,

      What I'm interested at, why is an AVR considered faster then a PIC, even when they run on the same clock freq.

      Not that I'm going to change microcontroller brand soon, just because I've still got 20-30 pics laying around!

      How is the supply of AVR atm? Last time i checked at my suplier in china most AVR where out of stock for the last 18 months.

      1. Your price and availability varies greatly depending on your available suppliers. The time i was talking about is quite somev years back and things are changed now. One thing today is that you can get many 16/32 bit microscwith more stuff for the money than 8 bit ones. Also there are superior 8 bit pics thaj the ones mentioned which are cheaper….

      2. I love the ATMega8. But to help you with your question, I know AVR instructions are almost always 1 cycle long. Maybe the PIC is slower because it needs more cycles per instruction?

        (Seeing how people use them I guess both AVR and PIC are awesome chips. I only have experience with AVR so I cannot judge on PIC)

      3. The reason why an AVR is faster than PIC is because an AVR runs one instruction each clockcycle, whereas a PIC only manages to do 1/4th instruction for each clockcycle. Or to put it in other words, a PIC needs 4 clockcycles for each instruction. (Argument holds for all non-branch instructions)

      4. The AVR runs at one clock cycle per instruction cycle, whereas an 8-bit PIC runs at four clock cycles per instruction cycle. This means that an AVR will execute approximately four times as many instructions per second as a PIC at the same clock frequency (I say “approximately” as a handful of instructions take more than one instruction cycle on both devices).
        This isn’t true for all PICs, however; the 16-bit dsPIC33F series has single clock cycle instructions (with a few exceptions), for example.

      5. @david etc.
        I already found that AVR do 1 instruction for each clock. But I’m interested in the technical stuff, Most chips use 4 stages and need 4 clock-pulses for each instruction. AVR is different, what makes it interesting because an AVR still needs the 4 stages: Instruction fetch, Instruction decode, Execute and save.

        Higher end chips use pipelining, but i never seen it in a 8bit chip. I guess it would be an overkill.

  2. I love the proclamation across the top of Vinod’s blog “ELECTRONICS THE KING OF HOBBIES ” far I out. While I’m unlikely to duplicate this project, but what was new information to me will be going into the current note book. Nice find Mike.

  3. My experience with playing 16bit 44khz wave on 10bit resistor r2r dac on good audio system showed better than expected quality.
    With a proper 16 bit dac you can get very good quality and maybe have sufficient time available on a card using wave format. I would recommend using a regular file system as you could just plug your card into the computer and download the file.

  4. Awesome, great to see this being done on a PIC. Back before PCs had sound cards, we used to use a similar trick to play ADPCM audio on the PC speaker by using one of the 3 timers to generate a periodic interrupt and another set to one-shot mode to generate each PWM pulse. If you set the frequency high enough (e.g. double each sample and play back at 88kHz) then the speaker itself forms the low-pass filter and you don’t need the RC components on the output (doesn’t work on piezos though).

    1. i have a device driver for DOS i think to do this. sounded like crap but i was still amazed at how much more detail was in the sound compared to standard 1-bit square-wave beeps!

      PS: thisone i have somehow works on a piezo but sounds wayyy much better on standard speaker like you say. ie u cant make out the words on piezo but u can tell what song is playing.

    1. If this is for a voice application, it would be nice to see voice being used for the example audio. It’s hard to compare the quality of music in/out to voice in/out since the frequency bandwidth required for music is much wider than that of the human voice. The output may actually sound better that way. If you don’t want to use your own voice, I don’t think it would be too hard to find a recording of someone reading a book or some other example text.

      Nice project though. Might play around with the idea on a maple I have here.

  5. Great project and awesome documentation, bravo! Thanks also to the author for sharing the code!

    The audio in the video could be distorted, 8 bit aside, because of input overload or clipping. The mic preamp capsule resistor seems too high to me and should be somewhere between 2.2k and 22k, usually 10k with 9-12 Vdc, much less with 5Vdc.
    Also, a true common emitter preamp like this one would be better.

  6. Hi,

    I have in my pocession a microphone, an amplifier and a pic18f452. I have already connected the microphone to the amplifier. I will connect the output of my microphone on the deck with an annalog port on the picdem Board and ground with ground on the picdem board. The channelA0 of the picdem board is reserved for the potentiometer so I have to use another port different from port A to connect the output of my Microphone.
    concerning programming I have to write a program that allows me to digitize this analog signal from the microphone and send it through the uart of my picdem board to a module blutooth HC05. the Picdem Board have an integrated ADC (10bit).

    i want your help for Programming please. i can send you what i already do.
    sorry for my english

Leave a Reply to Harvie.CZCancel reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.