VS1003 & atmega128

Writing software for systems that use VLSI Solution's devices as slave codecs to a host microcontroller.
karimi
User
Posts: 9
Joined: Wed 2013-06-26 9:24

VS1003 & atmega128

Post by karimi »

dear mr.panu

have nice day.i want to work with VS1003 that connect to ATmega128 & SD card.i attache my project (write withe code vision) .
mr.panu how do i set spi_clockf with crystal 16 MHZ(the crystal 16 MHZ use External oscllator for ATMEGA 128).
i attach pic of circuit .
-i run this program that i attach but i do not hear any voice from VS1003.
-i think problem between spi clock and clock of vs1003 .
-if you see my code and see problem please inform me.
-we use VS1003.c and vs1003.h

thanks
VS1003 projetc-MR.panu.zip
project & Pic of circuit
(770.32 KiB) Downloaded 2175 times
User avatar
Panu
VSDSP Expert
Posts: 2827
Joined: Tue 2010-06-22 13:43

Re: VS1003 & atmega128

Post by Panu »

Hi!

Sorry for the late reply, I'm in and out of holiday.

If you don't hear any sound from vs, then it's not a SCI_CLOCKF problem. With wrong SCI_CLOCKF value, you will hear sound but it's choppy and/or at the wrong frequency.

First you should read the MCU Howto link below. Start with 1 MHz SPI clock speed. And I suggest that your first project is to run the "Audible Hello" from this forum.

Hope this helps!
karimi
User
Posts: 9
Joined: Wed 2013-06-26 9:24

Re: VS1003 & atmega128

Post by karimi »

Panu wrote:Hi!

Sorry for the late reply, I'm in and out of holiday.

If you don't hear any sound from vs, then it's not a SCI_CLOCKF problem. With wrong SCI_CLOCKF value, you will hear sound but it's choppy and/or at the wrong frequency.

First you should read the MCU Howto link below. Start with 1 MHz SPI clock speed. And I suggest that your first project is to run the "Audible Hello" from this forum.

Hope this helps!
THANKS FOR REPLY

i DO project and right now i hear a voice from vs1003 and i test Audible hello project and i listen hello from vs like your sample

but my problem is about other bitrate

when i use bitrate 96kb i hear good music

but when i use bitrate 128 kb or more i hear choppy music

when i increase SCI_Clockf lower bitrate 128kb is choppy

right now what shall i do ?

I upload my project and upload 2 sound file that i record from output vs1003

one sound file is 128 kb and play very slowly

and other file is 64 kb and play choppy

-SCI_CLOCKF is 0XB3FE

-how do i set value of SCI_AUDATA ? , right now the value of SCI_AUDATA is 0XAC45 (44100 hz).

-spi clock of Atmega128 is 2*2 Mb .



thanks for helping me ..........
Attachments
128kb.mp3
(371.68 KiB) Downloaded 497 times
64kb.mp3
(396.17 KiB) Downloaded 510 times
spi_clock4.zip
(298.89 KiB) Downloaded 1136 times
User avatar
Panu
VSDSP Expert
Posts: 2827
Joined: Tue 2010-06-22 13:43

Re: VS1003 & atmega128

Post by Panu »

Ok, great that you hear sound.
- B3FE is the correct CLOCKF value for 12.288 MHz XTAL.
- You don't need to set SCI_AUDATA. VS1003 will set that one for you.

It seems a little like the microcontroller is not feeding data fast enough to the VS1003. What is your SPI bus speed? Where does the data come from? An SD card? How long time does it take to read the data from the SD card?

-Panu

PS. maybe you can browse my old source code documentation at http://www.vlsi.fi/player_vs1011_1002_1 ... larplayer/ to see if you do something similar or different than I at MP3SoftReset etc...
http://www.vlsi.fi/player_vs1011_1002_1 ... 8c.html#a3
karimi
User
Posts: 9
Joined: Wed 2013-06-26 9:24

Re: VS1003 & atmega128

Post by karimi »

Panu wrote:Ok, great that you hear sound.
- B3FE is the correct CLOCKF value for 12.288 MHz XTAL.
- You don't need to set SCI_AUDATA. VS1003 will set that one for you.

It seems a little like the microcontroller is not feeding data fast enough to the VS1003. What is your SPI bus speed? Where does the data come from? An SD card? How long time does it take to read the data from the SD card?

-Panu

PS. maybe you can browse my old source code documentation at http://www.vlsi.fi/player_vs1011_1002_1 ... larplayer/ to see if you do something similar or different than I at MP3SoftReset etc...
http://www.vlsi.fi/player_vs1011_1002_1 ... 8c.html#a3

thanks for reply

Mr Panu i use MicroSd in my Circuit and i use 4 SPi Mode (all of them ) and i use 2*1000 KHZ Spi Clock and 4*1000 Khz spi clock but both of them same sound like previous post
User avatar
Panu
VSDSP Expert
Posts: 2827
Joined: Tue 2010-06-22 13:43

Re: VS1003 & atmega128

Post by Panu »

Ok, can you find some location in your code where you read from the SD card? Then put some LED on (or IO pin high) when you start the read from SD card, and the LED off when the data is ready from the SD card. Then measure with oscilloscope how often you read from the SD card and how long it takes.

-Panu
karimi
User
Posts: 9
Joined: Wed 2013-06-26 9:24

Re: VS1003 & atmega128

Post by karimi »

Panu wrote:Ok, can you find some location in your code where you read from the SD card? Then put some LED on (or IO pin high) when you start the read from SD card, and the LED off when the data is ready from the SD card. Then measure with oscilloscope how often you read from the SD card and how long it takes.

-Panu
MR panu thanks for replying

My question is about all of bitrate ...

as you know i can play music with vs1003 but when i change bitrate

my song is slower or faster

i think when i play the song i read one register from vs

because when i play the song my Code must be Smart to decode all bitrate

and with one condition i must to tell the vs which bitrate is playing

Code: Select all

 for(k=0;k<10899;k++)
                  {    
                  VS1003B_SPI_Low();
                    res=f_read(&file,buffer,512,&br)  ;    
                  
                            if(res==FR_OK)
                                {   
                                
                                                                           
                                      for(count=0;count<16;count++) 
                                             {   
                                               
                                              if(VS1003B_NeedData() !=0)  
                                                       {
                                                      
                                                        VS1003B_Write32B(&buffer[32*count]);
                                                       VS1003_get_audio_info(&info)                                                                                              
                                                         }
                                                                      
                                                 }       
                                      }   
                        }   

Code: Select all

void VS1003B_Write32B(unsigned char * buf)
        {
	unsigned char n = 32; 
        VS1003B_SPI_High();
        VS1003B_XDCS_L();
	while(n--)
	        {
		VS1003B_WriteByte(*buf++);
	        }
	VS1003B_XDCS_H();
        }

Code: Select all

void VS1003B_SPI_Low(void)
{
	SPCR =   _BV(SPE)|_BV(MSTR)|_BV(SPR1)|_BV(SPR0);
	SPSR &= ~_BV(SPI2X);
}

// High speed, should not exceed 49.512MHz/6 
void VS1003B_SPI_High(void)
        {
	SPCR =  _BV(SPE)|_BV(MSTR);
	SPSR |= _BV(SPI2X);
        }

Code: Select all

unsigned char VS1003B_NeedData(void)
        {
        if(VS1003B_DREQ_PIN & (1<<VS1003B_DREQ_BIT))return 1;
        else return 0;
        }

Code: Select all


void VS1003_get_audio_info(struct VS1003_Mp3Info* Mp3Info)   
        {   
        unsigned int temp;
        unsigned char ID,SR,BR;
        VS1003B_SPI_Low();      
        ID = (unsigned char)((VS1003B_ReadCMD(VS1003_HEDATA1) & 0x0018) >> 3);      
        temp = VS1003B_ReadCMD(VS1003_HEDATA0);   
        SR = (char)((temp & 0x0C00) >> 10);   
        BR = (char)((temp & 0xF000) >> 12);
        Mp3Info->mode = (char)((temp & 0xC0) >> 6);   
        if (ID == 0 || ID == 1)
                {
                Mp3Info->sample_rate  =  sample_rate_values1[SR];
                }
        else if (ID == 2)
                {
                Mp3Info->sample_rate  =  sample_rate_values2[SR];
                }
        else if (ID == 3)
                {
                Mp3Info->sample_rate  =  sample_rate_values3[SR];
                Mp3Info->bit_rate = bit_rate_values1[BR];
                }
        else if (ID == 0 || ID == 1 || ID == 2)
                {
                Mp3Info->bit_rate = bit_rate_values2[BR];
                }
        }   
User avatar
Panu
VSDSP Expert
Posts: 2827
Joined: Tue 2010-06-22 13:43

Re: VS1003 & atmega128

Post by Panu »

Hi!

No need to tell VS the bitrate. Just feed MP3 data into VS, VS will detect bitrate, sample rate and number of channels and play correctly.

If you change to VS1053, you can feed MP3, WMA, OGG and AAC and there is not even need to tell which format the file is. The VS chip will detect automatically and play correctly.

You should set NEW_MODE to 1, SHARED_MODE to 0 (not shared mode), STREAM_MODE to 0 (not stream mode) and just check when DREQ is 1. When DREQ is 1, send more data. When DREQ is 0, don't send more data. You don't even need to know which format file is playing.

At a glance, your code seems OK to me, but perhaps you read the get_audio_info too often. Can you remove that and see how big bitrates you can play then. Can you check how long time the code is spending in the idle mode (DREQ=0). That will tell you roughly how much time you have left in your MCU.

-Panu
karimi
User
Posts: 9
Joined: Wed 2013-06-26 9:24

Re: VS1003 & atmega128

Post by karimi »

Panu wrote:Hi!

No need to tell VS the bitrate. Just feed MP3 data into VS, VS will detect bitrate, sample rate and number of channels and play correctly.

If you change to VS1053, you can feed MP3, WMA, OGG and AAC and there is not even need to tell which format the file is. The VS chip will detect automatically and play correctly.

You should set NEW_MODE to 1, SHARED_MODE to 0 (not shared mode), STREAM_MODE to 0 (not stream mode) and just check when DREQ is 1. When DREQ is 1, send more data. When DREQ is 0, don't send more data. You don't even need to know which format file is playing.

At a glance, your code seems OK to me, but perhaps you read the get_audio_info too often. Can you remove that and see how big bitrates you can play then. Can you check how long time the code is spending in the idle mode (DREQ=0). That will tell you roughly how much time you have left in your MCU.

-Panu
Hello mr panu

i can play music with 320 kb bitrate

but i have problem

when i play the song i have very little noise or maybe is gaps and this gaps very very little

but this gaps like noise and when i play the song this noise is background of song and song + noise playing together

Mr panu what s your idea about this problem
?
User avatar
Panu
VSDSP Expert
Posts: 2827
Joined: Tue 2010-06-22 13:43

Re: VS1003 & atmega128

Post by Panu »

Very difficult to say. Do you have D class amplifier in your system?

If you record some example sound, then I can listen.

-Panu
Post Reply