MAIN SITE HOME
Technical Tips

SD/SDHC CARD SOUND RECORDER
For SD with PETIT FAT File System see SD Bitmap project
For sound playback with EEPROM see Doorbell

Updated on 30.6.2015
The PIC16F876A's ADC
digitizes the sound and store it in the SD or SDHC card. The firmware works for SD or SDHC cards only, for old SD (before 2009) use ver1 firmware. Do not use SDXC cards with this project because some of them work on 1.8V drive. The code detects whether the card is SD or SDHC and selects the proper addressing system for the card.
The PIC's CCP is used as a DAC to convert the digital data back to audio. The sound is converted to 20KHz 8 bits mono in a format similar to .wav files. The quality of the audio is reasonable.
SD card interface the PIC in SPI mode. Reading and writing data is in multi-blocks. Memory is used at the rate of 20KB/s. The Error LED indicates error sent by the SD card. The software doesn't use any file system, it just uses absolute memory addresses (raw). Since the programme is less than 680 bytes there is much resources left for adding features.
Audio input is 1Vp-p , you can use the mic circuit or other source. The CCP in PWM mode gives 20KHz wave with duty cycle modulated to the audio amplitude. A low pass filter removes the 20KHz component. I added a simple 2 transistors amplifier to boost the power to drive 32 Ohm speaker or headphones.

SD/SDHC CARD SOUND RECORDER FOR ARDUINO

A sound recorder project for Arduino Uno with ATMEGA328P device.
The firmware works for SD or SDHC cards only. Do not use SDXC cards with this project because some of them work on 1.8V drive. The code detects whether the card is SD or SDHC and selects the proper addressing system for the card. The quality of the audio is reasonable.
The ADC converts the sound to 20KHz 8 bits mono in a format similar to .wav files. Timer0 in Fast PWM mode is used as a DAC to convert the digital data back to audio. During recording the ADC converts the audio to 10 bits, the low byte is streamed to the SD card. The 0.65V bias to the ADC input is for setting the signal to the low byte of the converter output.
SD card interfaces the microcontroller in SPI mode. Reading and writing data is in multi-blocks. Memory is used at the rate of 20KB/s. The Error LED indicates error of communication with the SD card. The software doesn't use any file system, it uses absolute memory addresses (raw).
Audio input is 1Vp-p , you can use the mic circuit or another source. The PWM gives 64KHz wave with duty cycle modulated to the audio amplitude. A low pass filter removes the 64KHz component. I added a simple 2 transistors amplifier to boost the power to drive 32 Ohm speaker or headphones.
Circuit diagram
You are free to use the circuit diagram and software with no limitations.

SD/SDHC CARD FAT32 WAV PLAYER PIC16F876A

This project is for .wav file type player (no recording). The software has the functions needed to read SD/SDHC card formatted in FAT32. The software can play only PCM 22.050KHz, 8 bits, mono. The bytes from the file are streamed to CCP1 (PWM mode) and with an external low pass filter you get the audio. The sound quality is OK for speech or medium quality music.
The software searches for files entries in the root directory only, it streams any file type without reading its name or type.
The circuit diagram is the same as the SD Sound Recorder minus the components for recording. Drawing is included with the software zip.
TO SET UP THE CARD:
Format the card with FAT32.
Create sound files type .wav
Name the files with short names, 8 low case characters max.
Save the files as 22.050KHz, 8 bits, mono.
Add the files to the root directory of the card (don't use a subdirectory).

SD/SDHC CARD SOUND RECORDER 3.3V PIC16F690

This sound recorder has the same characteristics as the sound recorder with PIC16F876A. The difference is the supply voltage is 3.3V. This makes the direct drive of the SD card simpler. It also makes it easier to power it from a battery.
8MHz internal oscillator is used, if the frequency drifts it causes the playback to change speed. I left pins 2 and 3 free in case I have to use crystal oscillator.
The programming of the pic can be with 3.3V, if you have a pic programmer for 5V only remove the SD card while 5V is connected to the circuit, 5V will damage the SD card.

SD/SDHC CARD FAT32 WAVE PLAYER 3.3V PIC16F690

This wave player has the same characteristics as the wave player with PIC16F876A. The difference is the supply voltage is 3.3V. This makes the direct drive of the SD card simpler. It also makes it easier to power it from a battery.
The playback speed can be changed by changing the time of TMR0 in the code.
The programming of the pic can be with 3.3V, if you have a pic programmer for 5V only remove the SD card while 5V is connected to the circuit, 5V will damage the SD card.

Troubleshooting:
If the Error LED is on immediately on power up it means that the card failed to initialize. This code works for SD card rev 2 or SDHC card, it doesn't work for SDXC (1.8V) or MMC or SD rev 1 cards. If your card is SD rev 1 you can use my firmware ver 1.
For a successful recording a sector (512 Bytes) has to be writen in 20ms, some old SD cards may be too slow writing data to the flash memory, in such case the error LED comes on. Try another make of card.

More about FAT32 in this document: https://staff.washington.edu/dittrich/misc/fatgen103.pdf
More about WAV in here: https://ccrma.stanford.edu/courses/422/projects/WaveFormat/
Good free specifications for SD can be found in SanDisk PDF: http://alumni.cs.ucr.edu/~amitra/sdcard/ProdManualSDCardv1.9.pdf
PIC C source code. You are free to use the circuit diagram and software with no limitations.

Circuit Description
See also Technical Tips

PIC supply is 3.3V. The SD Card supply must be 3-3.6V.
Audio input at pin 8 is 0.8Vp-p max. Voltage over 3.3Vp-p can damage the PIC input protection. 22K,47K and 10K bias input to 0.413V DC input which is the middle range of the ADC to give 8 bits.
One option is to boost the pic output by the Simple Headphones Amp. You can use a 32 Ohm speaker. For use with another amplifier connect via the lowpass filter.
Stop, Rec, Pause and Play are pushbuttons.

Circuit Description
See also Technical Tips

PIC supply is 5V. The SD Card supply is only 3.3V (3-3.6V) The 3.3V is generated by dropping the 5V with 2 diodes.
Audio input at pin 2 is 1Vp-p max. Voltage over 2Vp-p can damage the PIC input protection. 100K and 12K resistors give 0.6V DC input which is the middle of 1.25V range of the ADC.
One option is to boost the pic output by the Simple Headphones Amp. You can use a 32 Ohm speaker. For use with another amplifier connect via the lowpass filter.
Pin 1 is the PIC's reset.
22pF capacitors may need to be changed depending on the type of crystal used.
Digital outputs from the PIC to the SD card use 1K and 2K resistors to reduce the 5V signals to 3.3V. SD output at pin 7 is 3.3V but is enough to drive the PIC's input.
Stop, Rec, Pause and Play are pushbuttons.


Circuit Description
See also Technical Tips

The ground, 3.3V and 5V are sourced by the arduino board.
AREF pin on IOH connector is connected to 5V to supply the ADC Vref.
22K 47K and 10K give the audio input 0.62V DC bias to set the ADC to the low 8 bits.
1K and 2K resistors at the inputs to the SD are to reduce the 5V signals to 3.3V signals. MISO card output is only 3.3V but it is ok for the 5V input of the AMD.
The card's pins number are for standard size SD, for Micro SD the pins are different.
Audio output can use output filters as the drawing above. For microphone you can use the simple amp above.