Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Hello ... Need Help With MMC And DAC to Play Wav Sound

Status
Not open for further replies.

mohammadjamal

Newbie level 6
Joined
Mar 24, 2012
Messages
11
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,351
Hi All

now i build a program to run a wave files
wave file type is Mono / Bits / 16 KHz
i do every things goood

reading from memory
and send a byte i have read to PORTB
but my problem

to play it in speaker
i know that's need DAC
but any body can help me on this ??????

this is my Code
Code:
#define LINE_LEN  43
#define CFILE_EXIST 1
#define CTMR0H 0xFE
#define CTMR0L 0xD4

sfr sbit Mmc_Chip_select at LATC0_bit;
sfr sbit Mmc_Chip_Select_Direction at TRISC0_bit;
sfr sbit Out_LED_Green at LATC1_bit;
sfr bit Out_LED_Red at LATC2_bit;
unsigned char AudioFile[7];
char iSample;
long int size;
char bTimerInt;

void Main_Init()
{
     TRISC6_bit = 0;
     TRISC7_bit = 0;
     TRISC1_bit = 0;
     TRISC2_bit = 0;
     TRISA = 0xFF;
     TRISB = 0x00;
     PORTB = 0x7F;
     TRISD = 0x00;
     INTCON = 0;
     INTCON2 = 0;
     INTCON3 = 0;
     T0CON = 0;
     T0CON.T08BIT = 0;
     T0CON.TMR0ON = 1;
     T0CON.T08BIT = 0;
     T0CON.T0CS = 0;
     T0CON.T0SE = 0;
     T0CON.PSA = 1;
     T0CON.T0PS2 = 0;
     T0CON.T0PS1 = 0;
     T0CON.T0PS0 = 0;
     TMR0H = CTMR0H;
     TMR0L = CTMR0L;
     
     ADCON1 |= 0x0F;
     CMCON |= 7;
     
     Out_LED_GREEN = 1;
     Out_LED_RED = 1;
     delay_ms(500);
     Out_LED_GREEN = 0;
     Out_LED_RED = 0;
}

void interrupt()
{
     if (INTCON.TMR0IF) {
     bTimerInt = 1;
     TMR0H = CTMR0H;
     TMR0L = CTMR0L;
     INTCON.TMR0IF = 0;
     }
}

void Timer_SetInterrupt(int bState)
{
     if (bState) {
     TMR0H = CTMR0H;
     TMR0L = CTMR0L;
     INTCON.TMR0IF = 0;
     INTCON.GIE = 1;
     INTCON.TMR0IE = 1;
     T0CON.TMR0ON =1;
     } else {
     T0CON.TMR0ON = 0;
     INTCON.TMR0IE = 0;
     INTCON.GIE = 0;
     }
}

void M_ReadAudioFile(int idx)
{
     char iStatus;
     bit bBadFile;
     switch (idx)
     {
            case 0 :
                 strcpy(AudioFile,"hi.wav");
                 break;
            default :
                 strcpy(AudioFile,"hi.wav");
                 break;
     }
     
     Out_LED_GREEN = 0;
     Out_LED_RED = 0;
     iStatus = Mmc_Fat_Exists(AudioFile);
     bBadFile = 0;
     if ((iStatus == CFILE_EXIST) && (!bBadFile)) {
     Out_LED_GREEN = 1;
     Mmc_Fat_Assign(AudioFile,0);
     Mmc_Fat_Reset(&size);
     Mmc_Fat_Seek(44);
     if (size > 44) size = size - 44;
     Timer_SetInterrupt(1);
     {
                           while (size > 1) {
                           if (bTimerInt) {
                           Mmc_Fat_Read(&iSample);
                           PORTB = iSample;
                           UART1_Write_Text(iSample);
                           size = size - 1;
                           bTimerInt = 0;
                           }}
     }
     Timer_SetInterrupt(0);
     {
                           while (size > 1){
                           Mmc_Fat_Read(&iSample);
                           PORTB = iSample;
                           size = size - 1;
                           delay_us(40);}
     }
     PORTB = 0x7F;
     Out_LED_GREEN = 0; }

     else
     {
         Out_LED_RED = 1;
         delay_ms(500);
         Out_LED_RED = 0;
     }
}
void main()
{
     UART1_Init(9600);
     Main_Init();
     SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV64,_SPI_DATA_SAMPLE_MIDDLE,_SPI_CLK_IDLE_LOW,_SPI_LOW_2_HIGH);
     if (Mmc_Fat_Init() == 0) {
     SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV4,_SPI_DATA_SAMPLE_MIDDLE,_SPI_CLK_IDLE_LOW,_SPI_LOW_2_HIGH);
     M_ReadAudioFile(0);
     }
     else {
     while (1) {
     Out_LED_RED = 1;
     delay_ms(250);
     Out_LED_RED = 0;
     delay_ms(250);
     }}
}



and the schemetic of my circuit in attachments
please help :sad:
 

Attachments

  • design.BMP
    117.1 KB · Views: 64

Thanks Arch

but it's actually consist in one pin to output

in my schematic , the problem is DAC , how can i do it ???????
and how could playing sound on the speaker using ampilfier ?????
 

the proteus is sooooo slow in simulation
one second in proteus actually 1 min

and my project need the real time Speed to get a better result
please any body can help me in this subject ??????
 

Test your DAC by sending data from 0x00 to 0xff (with delay about 50 ms) and watch the output voltage increases slowly. If it is okay, then you need add AC coupling a 1-10 uF capacitor, series with loudspeaker.
 
thanks
the output voltage was increasing

now what's the AC Capacitor ?????
 

So, the DAC has worked well.
That is for blocking DC signal to loudspeaker. The voltage will ripple at 0V.
You can add audio amplifier after DAC.
Good quality audio need high sample rate about 22 KHz, and you need high speed processing. You have to use high speed processor, two parts of RAM (1st = for playing, 2nd=buffering). But for speech audio signal 8 KHz is fine.
 
Thank you mr arch
now i am trying to install the program on the microcontroller
and i will alert you with my result
thanks very much
 

hello
i have a problem with DAC
i have used R-2R ladder to convert digital to analog
but it seems didnt work !

i dont know why
i send the bits to portD and pass it by digital analog converter then to amplifier
but no result good

only i have a good noise
any body have a schemetic for digital analog converter IC to sound amplifier
please help :)
 


Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top