Wave player on LPC1768 with DAC

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Wave player on LPC1768 with DAC

455 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Badman on Mon Feb 17 00:48:06 MST 2014
Hello,

I'm trying to pursue the player based on the DAC. For convenience I use the wave file with a frequency of 11025 Hz, 8 bit mono. The only grumble I hear the speaker. What is wrong in the code ?
#define BUF_SIZE 512
uint16_t buf[2][512];
volatile uint8_t nr_buf = 0;// indeks aktywnego buforu
volatile uint8_t can_read = 1;

UINT play(char fn)
{
FIL fil;
char *wsk_buf = &buf[0][0];
DWORD eof, br;
UINT rb = 0 ;
char bufor[10];

if ( f_open(&fil, "11025mon8bit.wav", FA_READ) == FR_OK)
{
printf( "Otwarto plik\n\r" );
f_read( &fil, &buf[0][0], BUF_SIZE , &rb );
f_read( &fil, &buf[1][0], BUF_SIZE , &rb );

LPC_TIM0->TCR = 1;// start Timer0

while(1)
{
if( can_read ) {// jesli flaga ustawiona w obsludze przerwania

f_read( &fil, &buf[ nr_buf ^ 0x01 ][0], BUF_SIZE , &rb );// odczytaj kolejny bufor
//printf( "B%d\n\r", nr_buf ^ 1 );

if( rb < BUF_SIZE ) break;// jesli koniec pliku przerwij petle while(1)
}

can_read = 0;
}
LPC_TIM0->TCR = 0;// stop Timer0
}
else
printf( "Nie otwarto pliku\n\r" );

return 0;
}

void sound_init(void)
{
CLKPWR_ConfigPPWR( CLKPWR_PCONP_PCTIM0, ENABLE );// wlaczeczenie TIM0
//CLKPWR_SetPCLKDiv (CLKPWR_PCLKSEL_TIMER0, CLKPWR_PCLKSEL_CCLK_DIV_4);
LPC_PINCON->PINSEL1 = 0x00200000;// ustawienie P0.26 jako wyjscie DAC

LPC_TIM0->MR0 = ( 1000000000 / 11025 ) - 1;
LPC_TIM0->MCR = (1<<0) | (1<<1); // zerowanie MR0 i generacja przerwan
NVIC_EnableIRQ( TIMER0_IRQn );// Wlaczenie przerwan dla Timer0
NVIC_SetPriority( TIMER0_IRQn, 0 );
}

void TIMER0_IRQHandler(void)
{
// sprawdzamy czy przerwanie od rejestru porownujacego MR0
if ( LPC_TIM0->IR & 0x01 )
{
static uint16_t buf_idx;
static uint8_t probka ;
static uint16_t i;


LPC_TIM0->IR |= 1<<0;// skasowanie flagi przerwania od MR0

probka = buf[nr_buf][buf_idx++] ;

i =  ( probka << 2 );  // konwersja 8bit do 10bit

//LPC_DAC->DACR = ( (i&0x3FF) << 6 ) | DAC_BIAS;

DAC_UpdateValue( LPC_DAC, i );

if( buf_idx > BUF_SIZE-1 )
{
buf_idx = 0;// reset indeksu bufora
can_read = 1;// flaga = 1
nr_buf ^= 0x01;// zmiana bufora na kolejny
}
}
}
Labels (1)
0 Kudos
0 Replies