Pages: 1 [2] 3   Go Down
Author Topic: EEPROM better than SD card for audio ?  (Read 2135 times)
0 Members and 1 Guest are viewing this topic.
Cape Town South Africa
Offline Offline
Edison Member
*
Karma: 19
Posts: 1189
A newbie with loads of posts, and still so much to learn !
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I have had one last try at using the SD card.

I modified the Adafruit wave library to take my bcd inputs, but its exactly the same, it reads the 256Mb cards, but not most of the 2Gb cards.

Heres the code  below, I dont know if there is something stupid, otherwise I will carry on with the eeprom try, which I am rather out of my depth on I must confess...

Code:
#include <FatReader.h>
#include <SdReader.h>
#include <avr/pgmspace.h>
#include "WaveUtil.h"
#include "WaveHC.h"

SdReader card;    // This object holds the information for the card
FatVolume vol;    // This holds the information for the partition on the card
FatReader root;   // This holds the information for the filesystem on the card
FatReader f; // This holds the information for the file we're play

WaveHC wave; // This is the only wave (audio) object, since we will only play one at a time

int talkingPin = 19;  // high while audio playing to video chip to keep number on.
int aPin =18; //define pin numbers for bcd inputs from HT12D
int bPin =17;
int cPin =15;
int dPin =16;
int vtPin = 14; // define pin numbers for valid transmission input from HT12D
int track ; // define audio track number
int bcda ; // define bcd digitalreads for BCD/dec conversion
int bcdb;
int bcdc;
int bcdd;
int valid ;  // to be set high if vt in

// this handy function will return the number of bytes currently free in RAM, great for debugging!
int freeRam(void)
{
  extern int  __bss_end;
  extern int  *__brkval;
  int free_memory;
  if((int)__brkval == 0) {
    free_memory = ((int)&free_memory) - ((int)&__bss_end);
  }
  else {
    free_memory = ((int)&free_memory) - ((int)__brkval);
  }
  return free_memory;
}

void sdErrorCheck(void)
{
  if (!card.errorCode()) return;
  putstring("\n\rSD I/O error: ");
  Serial.print(card.errorCode(), HEX);
  putstring(", ");
  Serial.println(card.errorData(), HEX);
  while(1);

}

void setup() {
  // set up serial port
  Serial.begin(9600);

  pinMode (aPin,INPUT);  //bcd inputs from HT12
  pinMode (bPin,INPUT);
  pinMode (cPin,INPUT);
  pinMode (dPin,INPUT);
  pinMode (vtPin,INPUT);  // valid trasnmission input
  pinMode (talkingPin,OUTPUT); // display enable to vga chip

  putstring_nl("WaveHC with 9 inputs");

  putstring("Free RAM: "); // This can help with debugging, running out of RAM is bad
  Serial.println(freeRam()); // if this is under 150 bytes it may spell trouble!

  // Set the output pins for the DAC control. This pins are defined in the library
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);

  // pin13 LED
  pinMode(13, OUTPUT);

   if (!card.init(true)) { //play with 4 MHz spi if 8MHz isn't working for you  *****  TRIED BOTH
 // if (!card.init()) {    //play with 8 MHz spi (default faster!)
    putstring_nl("Card init. failed!");  // Something went wrong, lets print out why
    sdErrorCheck();
    while(1);     // then 'halt' - do nothing!
  }
  // enable optimize read - some cards may timeout. Disable if you're having problems *** TRIED WITH AND WITHOUT AND true
 // card.partialBlockRead(false);
  // Now we will look for a FAT partition!
  uint8_t part;
  for (part = 0; part < 5; part++) {     // we have up to 5 slots to look in
    if (vol.init(card, part))
      break;      // we found one, lets bail
  }
  if (part == 5) {      // if we ended up not finding one  :(
    putstring_nl("No valid FAT partition!");
    sdErrorCheck(); // Something went wrong, lets print out why
    while(1);     // then 'halt' - do nothing!
  }

  // Lets tell the user about what we found
  putstring("Using partition ");
  Serial.print(part, DEC);
  putstring(", type is FAT");
  Serial.println(vol.fatType(),DEC);     // FAT16 or FAT32?

  // Try to open the root directory
  if (!root.openRoot(vol)) {
    putstring_nl("Can't open root dir!"); // Something went wrong,
    while(1);      // then 'halt' - do nothing!
  }

  // Whew! We got past the tough parts.
  putstring_nl("Ready!");
}

void loop() {

  bcda = digitalRead ( aPin );  // read the state of the video micro "decode" data outputs 
  bcdb = digitalRead ( bPin );
  bcdc = digitalRead ( cPin );
  bcdd = digitalRead ( dPin );
  valid = digitalRead ( vtPin );  // check if signal received, set valid high

  if (bcda==1 && bcdb==0 && bcdc == 0 && bcdd == 0 ) { //longwinded bcd / dec decoding to give track number to be read
    track = 1;
  }
  if (bcda==0 && bcdb==1 && bcdc == 0 && bcdd == 0 ) {
    track = 2;
  }
  if (bcda==1 && bcdb==1 && bcdc == 0 && bcdd == 0 ) {
    track = 3;
  }
  if (bcda==0 && bcdb==0 && bcdc == 1 && bcdd == 0 ) {
    track = 4;
  }
  if (bcda==1 && bcdb==0 && bcdc == 1 && bcdd == 0 ) {
    track = 5;
  }
  if (bcda==0 && bcdb==1 && bcdc == 1 && bcdd == 0 ) {
    track = 6;
  }
  if (bcda==1 && bcdb==1 && bcdc == 1 && bcdd == 0 ) {
    track = 7;
  }
  if (bcda==0 && bcdb==0 && bcdc == 0 && bcdd == 1 ) {
    track = 8;
  }
  if (bcda==1 && bcdb==0 && bcdc == 0 && bcdd == 1 ) {
    track = 9;
  } 

// if ( valid == HIGH ){
 
  if (track==1 ) {
    playcomplete("doornum1.wav");
  }
  else;
  if (track==2) {
    playcomplete("doornum2.wav");
  }
  else;
  if (track==3) {
    playcomplete("doornum3.wav");
  }
  else;
  if (track==4) {
    playcomplete("doornum4.wav");
  }
  else;
  if (track==5) {
    playcomplete("doornum5.wav");
  }
  else;
  if (track==6) {
    playcomplete("doornum6.wav");
  }
  else;
  if (track==7) {
    playcomplete("doornum7.wav");
  }
  else;
  if (track==8) {
    playcomplete("doornum8.wav");
  }
  else;
  if (track==9) {
    playcomplete("doornum9.wav");
  }
 //}
}
// Plays a full file from beginning to end with no pause.
void playcomplete(char *name) {
  // call our helper to find and play this name
  playfile(name);
  if (wave.isplaying) {//   set display enable high to vga chip
    digitalWrite(talkingPin, LOW);
  }
  else
  { 
    digitalWrite(talkingPin, HIGH);
  }
  while (wave.isplaying) {

  }
  // now its done playing
}

void playfile(char *name) {
  // see if the wave object is currently doing something
 //if (wave.isplaying) {// already playing something, so stop it!  cant happen with talkinpin
 //  wave.stop(); // stop it
//}
  // look in the root directory and open the file
  if (!f.open(root, name)) {
    putstring("Couldn't open file ");
    Serial.print(name);
    return;
  }
  // OK read the file and turn it into a wave object
  if (!wave.create(f)) {
    putstring_nl("Not a valid WAV");
    return;
  }
 if (valid == 1){  //  wont run without this here
    // ok time to play! start playback
    wave.play();

  }

}




Logged

With my mobile phone I can call people and talk to them -  how smart can you get ?

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 444
Posts: 23861
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

John,
What is your hardware connection to the SD card?
Are you using an IC to buffer the signals from the Arduino to get them down to 3.3V levels?
How are you powering the SD card? They can be power hungry and need more than the 50mA an FTDI chip can put out, if that is your source for example.

I followed the design of this shield when I added parts for my Bobuino, and it works great with 2 GB cards.
http://www.ladyada.net/make/logshield/design.html
I used a 74AC125D for the data buffer and IXF25001MEV33 for a 3.3V regulator.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Cape Town South Africa
Offline Offline
Edison Member
*
Karma: 19
Posts: 1189
A newbie with loads of posts, and still so much to learn !
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

This is really frustrating, I used the same circuit as you Bob, I made 4 of these units and they all have the same problem,  I have a separate 3.3v 150mA regulator, I scoped the output and its steady.  I tried a couple of different voltage buffer chips, I have decoupled everything.

Tomorrow I think I will make a separate part on perf/vero board, and try it with all the recommended part numbers if I can get them.

Have you tried yours playing back audio clips?   I can't see it making any difference, I dont think mine is even getting that far.

With it fitted to the board I have no serial to see whats happening.

I would like to go the DS cvard route, the eeprom is fiddly recording to.



« Last Edit: September 25, 2011, 02:36:54 pm by Boffin1 » Logged

With my mobile phone I can call people and talk to them -  how smart can you get ?

Yorkshire England
Offline Offline
Sr. Member
****
Karma: 2
Posts: 267
Arduino good init
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I don't know enough about this to offer advice. But what i can say it that i bought a adafruit wave shield a few months ago and have been using a 2gig card with only a minor problem.  when i first got the card i put some files on it all was ok. I changed the files using a diffident computer and lynux instead of my windows. I then spent a whole day trying to get to the bottom of a intermittent sound output. For the first half of the day i put it down to another part of the project that i had just been working on, not the audio which i thought was working fine. i did do a quick check on the audio and it read the first file fine, so i put it down to some other change in the code. Anyway after lots of swearing and head scratching and taking the code back to a version from a week earlier i eventually found the sd card was doing all sorts of strange things. Sometimes recognized files sometimes didn't , sometimes player weird clicks instead of the audio. Took the card home reformatted put the original files on again using windows and it all worked again. It still worked fine now it's installed in a interactive display for kids and plays nature noises, had no problems since. Still don't know why it did it. I was planning on using a 32gb card for a new project so i hope it they do go above 250mb smiley
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 444
Posts: 23861
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

John,
I haven't done more than the SdFat provided tests.
I get Write & Read results of ~160K & 280K with a Sandisk Ultra 15 MB/s SDHC 16GB card on the Benchmark test.

"With it fitted to the board I have no serial to see whats happening."
Huh? What does the SPI to the SD card have to do with Serial out to a monitor?
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Cape Town South Africa
Offline Offline
Edison Member
*
Karma: 19
Posts: 1189
A newbie with loads of posts, and still so much to learn !
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I meant that I cant see all the error reports that the sketch has when initiating the card.

Perhaps I will make up a test jig using the arduino board tomorrow so I can monitor everything

« Last Edit: September 25, 2011, 03:01:19 pm by Boffin1 » Logged

With my mobile phone I can call people and talk to them -  how smart can you get ?

Cape Town South Africa
Offline Offline
Edison Member
*
Karma: 19
Posts: 1189
A newbie with loads of posts, and still so much to learn !
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

@ AVP

Thats the sort of problems I have been having with the SD cards,( in my project)  its only the smaller capacity cards that work consistantly, and there is a chance that I will have to make a load of these devices, so I have to get the sound stable , and if I use SD cards they must be current ones that I can buy.

That why I was thinking of using an eeprom, but its just a bit too confusing for my experience at the moment, so if I can get the card working it would be the best...........................
Logged

With my mobile phone I can call people and talk to them -  how smart can you get ?

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 444
Posts: 23861
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

This is where GrayNomad's "perfect debugging tool"would come in handy!
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Cape Town South Africa
Offline Offline
Edison Member
*
Karma: 19
Posts: 1189
A newbie with loads of posts, and still so much to learn !
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I hav'nt heard of that, I will do a search...
Logged

With my mobile phone I can call people and talk to them -  how smart can you get ?

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 444
Posts: 23861
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

There's a whole thread on it, a work in progress still.

http://arduino.cc/forum/index.php?topic=72014.new;topicseen#new
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Cape Town South Africa
Offline Offline
Edison Member
*
Karma: 19
Posts: 1189
A newbie with loads of posts, and still so much to learn !
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

very interesting, but way over my head at the moment  :-)
Logged

With my mobile phone I can call people and talk to them -  how smart can you get ?

Cape Town South Africa
Offline Offline
Edison Member
*
Karma: 19
Posts: 1189
A newbie with loads of posts, and still so much to learn !
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Before changing anything on my problem board, I checked the specs of my 3.3 v low drop out regulator, and it was rated at 100mA output.
I had 'scoped the 3v3 output and could not see any glitches ( but my junk usb scope has poor sync )

At that time, two of my  SD cards worked ( one 256Mb and one of the 2Gb microSD with adaptor )  , the other 2 ( 2 Gb ) could be read on the PC but wouldn't boot on the project.
In case the problem was a dip in the 3v3 when initialising the cards, I just tried putting a 1000mFd cap on the 3v3 line.

Then all 4 cards worked !   I thought I had it cracked, but when I removed the 1000mFd cap, all 4 still booted up OK !

I have since fitted the right type of buffer chip ( 74HC4050 ), and an 800 Ma low dropout regulator and all is still working.

I have since thought that the problem might be something to do with the fact that the audio control micro is triggered from the video control micro,  it might be that the one is trying to trigger the other as soon as it comes on, so I am going to try a delay in the setup function of the video control micro to give the other one a chance to initiate the SD card.

Meanwhile I will still experiment with the mysterious eeprom route  just in case  !

Another mystery is that I have another 4 faulty SD micro cards that had failed in these projects, and they wont even format or be read on a PC ??
Logged

With my mobile phone I can call people and talk to them -  how smart can you get ?

Chile
Offline Offline
Sr. Member
****
Karma: 0
Posts: 260
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Have you seen the APR9600 IC? Sounds like it is a full solution for your requirements in just one IC.
Logged

Cape Town South Africa
Offline Offline
Edison Member
*
Karma: 19
Posts: 1189
A newbie with loads of posts, and still so much to learn !
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

That chip is the same as the ISD chips that I used several years back, the quality is not too good when played through a decent amp .

If I dont come right by the end of the week I might have to go back to that :-)
Logged

With my mobile phone I can call people and talk to them -  how smart can you get ?

0
Offline Offline
Edison Member
*
Karma: 7
Posts: 1411
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I used a 74AC125D for the data buffer and IXF25001MEV33 for a 3.3V regulator.
Do you have the datasheet for IXF25001MEV33? (google returns only one reference to this part, your spreadsheet).
Thanks.
FlorinC
Logged

Pages: 1 [2] 3   Go Up
Jump to: