Pages: [1]   Go Down
Author Topic: Problem while playing Wav files (SDcard & TLC7226 DAC)  (Read 1571 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 18
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi all,
I need to play .wav files from a SD Card. I chose to use 22050Hz 8bits mono files.

I connected a TLC7226 parallel DAC to my Arduino Duemilanove. The datasheet is here : http://www.ti.com/lit/ds/symlink/tlc7226.pdf
I use the first DAC (it's name DACA in the datasheet), that's why I connected A0 and A1 to ground. The D0-D7 pins go to the Arduino, as /WR one. Voltage reference is 5V.

A speaker is connected between OUTA and ground, through a 100 ohm resistor and a 10µF capacitor.

The DAC works well, I can hear a square wave for instance. I also read data from my SD card. The problem is when I read a byte from the file and I write it on the DAC, I can't recognize the music. There's just "cracking sounds".

Here is my code, sorry for the French :

Code:
#include <SD.h>

/*
  Connexion SD Card :
   ** MOSI (Violet) - pin 11
   ** MISO (Violet) - pin 12
   ** CLK (Gris) - pin 13
   ** SS (Blanc) - pin 4
*/


File fichier;
byte octet;
int i;



int pin_D[8] = {A0, A1, A2, A3, A4, A5, 2, 3}; // Here is connected my DAC
int pin_Enable = 7;





void Ecrire_DAC(byte val) // Write a byte to the DAC
{
    int i;
    
    for(i = 0; i < 8; i++) // I know that way to write the byte is slow. It's just for debug.
        digitalWrite(pin_D[i], bitRead(val, i));
    
    digitalWrite(pin_Enable, LOW);
    delayMicroseconds(5);
    digitalWrite(pin_Enable, HIGH);
    
    //Serial.print("Ecriture de ");
    //Serial.println(val, HEX);
}


void setup()
{
    int i;
    
    
    // Configuration du port série
    Serial.begin(115200);
    
    
    // Configuration du DAC
    pinMode(pin_Enable, OUTPUT);
    digitalWrite(pin_Enable, HIGH);
    for(i = 0; i < 8; i++)
        pinMode(pin_D[i], OUTPUT);
    Ecrire_DAC(0);
    
    pinMode(10, OUTPUT);
    if(SD.begin(10))
        Serial.println("Initialisation de la carte SD reussie.");
    else
        Serial.println("Echec de l'initialisation de la carte SD.");
    
    fichier = SD.open("22khz8b.wav");
    if(fichier)
        Serial.println("Ouverture du fichier reussie.");
    else
    {
        Serial.println("Echec de l'ouverture du fichier.");
        return;
    }
    
    fichier.seek(300); // make sure the pointer comes over the data
    
}




void loop()
{
    octet = fichier.read();
    Ecrire_DAC(octet);
    delayMicroseconds(45);
}
Even if the speed of the music will be very approximative, because I don't wait precisely 45µs between each byte, I thought I can hear something.

Can someone help ?
Thanks
« Last Edit: October 24, 2011, 02:07:25 pm by Sn4ke » Logged

Pages: [1]   Go Up
Jump to: