DSPRelated.com
Forums

follow-up to sample_input/output question

Started by m_st...@hotmail.com March 11, 2010
Thanks for the reply, Jeff. I believe that this is a CSS problem, as somebody has posted about the same problem before (can't find the link now) and fixed it by changing some linker settings in CCS. Here's an example of the code that doesn't work:

//sine8_intr.c Sine generation using 8 points, f=Fs/(# of points)
//Comm routines and support files included in C6xdskinit.c

short loop = 0;
short sin_table[8] = {0,707,1000,707,0,-707,-1000,-707}; //sine values
short amplitude = 10; //gain factor

interrupt void c_int11() //interrupt service routine
{
output_sample(sin_table[loop]*amplitude); //output each sine value
if (loop < 7) ++loop; //increment index loop
else loop = 0; //reinit index @ end of buffer
return; //return from interrupt
}

void main()
{
comm_intr(); //init DSK, codec, McBSP
while(1); //infinite loop
}

This is taken straight from the book and should work. However, using CCS's "tone" example does work. The only difference between these two examples appears to be the use of output_sample instead of DSK6713_AIC23_write. Here's the fft256 code that also doesn't work. Both examples use the intterupt routine that you described.

//FFT256c.c FFT implementation calling a C-coded FFT function

#include
#define PTS 256 //# of points for FFT
#define PI 3.14159265358979
typedef struct {float real,imag;} COMPLEX;
void FFT(COMPLEX *Y, int n); //FFT prototype
float iobuffer[PTS]; //as input and output buffer
float x1[PTS]; //intermediate buffer
short i; //general purpose index variable
short buffercount = 0; //number of new samples in iobuffer
short flag = 0; //set to 1 by ISR when iobuffer full
COMPLEX w[PTS]; //twiddle constants stored in w
COMPLEX samples[PTS]; //primary working buffer

main()
{
for (i = 0 ; i {
w[i].real = cos(2*PI*i/512.0); //Re component of twiddle constants
w[i].imag =-sin(2*PI*i/512.0); //Im component of twiddle constants
}
comm_intr(); //init DSK, codec, McBSP

while(1) //infinite loop
{
while (flag == 0) ; //wait until iobuffer is full
flag = 0; //reset flag
for (i = 0 ; i < PTS ; i++) //swap buffers
{
samples[i].real=iobuffer[i]; //buffer with new data
iobuffer[i] = x1[i]; //processed frame to iobuffer
}
for (i = 0 ; i < PTS ; i++)
samples[i].imag = 0.0; //imag components = 0

FFT(samples,PTS); //call function FFT.c

for (i = 0 ; i < PTS ; i++) //compute magnitude
{
x1[i] = sqrt(samples[i].real*samples[i].real
+ samples[i].imag*samples[i].imag)/32;
}
x1[0] = 32000.0; //negative spike(with AD535)for ref
} //end of infinite loop
} //end of main

interrupt void c_int11() //ISR
{
output_sample((int)(iobuffer[buffercount])); //out from iobuffer
iobuffer[buffercount++]=(float)(input_sample()); //input to iobuffer
if (buffercount >= PTS) //if iobuffer full
{
buffercount = 0; //reinit buffercount
flag = 1; //set flag
}
}
So is there any CCS-related reason that the sample_input and sample_output functions wouldn't work but the DSK6713_AIC23_ ones would? I've hooked up an oscilloscope to the output, and I've got some audio input. I've also tried to plot the output from iobuffer using view->graphs but this gives nothing.

Cheers,

Mike

_____________________________________
Mike-

> So is there any CCS-related reason that the sample_input
> and sample_output functions wouldn't work but the
> DSK6713_AIC23_ ones would? I've hooked up an oscilloscope
> to the output, and I've got some audio input. I've also
> tried to plot the output from iobuffer using view->graphs
> but this gives nothing.

You'd have to debug. What does sample_output() actually do? What does DSK6713_AIC23_write() actually do?
sample_output() sounds generic so one guess might be that it doesn't know about a specific board type, and doesn't
write the correct McBSP port and/or values.

In any case, this isn't a CSS issuec; CCS appears to be building and running code fine. The issue is which board and
which lib functions for that board. If it turns out that sample_output() should support the DSK 6713 but doesn't,
then you would want to ask Spectrum Digital (DSK provider) to explain.

-Jeff

> Thanks for the reply, Jeff. I believe that this is a CSS
> problem, as somebody has posted about the same problem before
> (can't find the link now) and fixed it by changing some linker settings in CCS. Here's an example of the code that
> doesn't work:
>
> //sine8_intr.c Sine generation using 8 points, f=Fs/(# of points)
> //Comm routines and support files included in C6xdskinit.c
>
> short loop = 0;
> short sin_table[8] = {0,707,1000,707,0,-707,-1000,-707}; //sine values
> short amplitude = 10; //gain factor
>
> interrupt void c_int11() //interrupt service routine
> {
> output_sample(sin_table[loop]*amplitude); //output each sine value
> if (loop < 7) ++loop; //increment index loop
> else loop = 0; //reinit index @ end of buffer
> return; //return from interrupt
> }
>
> void main()
> {
> comm_intr(); //init DSK, codec, McBSP
> while(1); //infinite loop
> }
>
> This is taken straight from the book and should work. However, using CCS's "tone" example does work. The only
> difference between these two examples appears to be the use of output_sample instead of DSK6713_AIC23_write. Here's
> the fft256 code that also doesn't work. Both examples use the intterupt routine that you described.
>
> //FFT256c.c FFT implementation calling a C-coded FFT function
>
> #include
> #define PTS 256 //# of points for FFT
> #define PI 3.14159265358979
> typedef struct {float real,imag;} COMPLEX;
> void FFT(COMPLEX *Y, int n); //FFT prototype
> float iobuffer[PTS]; //as input and output buffer
> float x1[PTS]; //intermediate buffer
> short i; //general purpose index variable
> short buffercount = 0; //number of new samples in iobuffer
> short flag = 0; //set to 1 by ISR when iobuffer full
> COMPLEX w[PTS]; //twiddle constants stored in w
> COMPLEX samples[PTS]; //primary working buffer
>
> main()
> {
> for (i = 0 ; i > {
> w[i].real = cos(2*PI*i/512.0); //Re component of twiddle constants
> w[i].imag =-sin(2*PI*i/512.0); //Im component of twiddle constants
> }
> comm_intr(); //init DSK, codec, McBSP
>
> while(1) //infinite loop
> {
> while (flag == 0) ; //wait until iobuffer is full
> flag = 0; //reset flag
> for (i = 0 ; i < PTS ; i++) //swap buffers
> {
> samples[i].real=iobuffer[i]; //buffer with new data
> iobuffer[i] = x1[i]; //processed frame to iobuffer
> }
> for (i = 0 ; i < PTS ; i++)
> samples[i].imag = 0.0; //imag components = 0
>
> FFT(samples,PTS); //call function FFT.c
>
> for (i = 0 ; i < PTS ; i++) //compute magnitude
> {
> x1[i] = sqrt(samples[i].real*samples[i].real
> + samples[i].imag*samples[i].imag)/32;
> }
> x1[0] = 32000.0; //negative spike(with AD535)for ref
> } //end of infinite loop
> } //end of main
>
> interrupt void c_int11() //ISR
> {
> output_sample((int)(iobuffer[buffercount])); //out from iobuffer
> iobuffer[buffercount++]=(float)(input_sample()); //input to iobuffer
> if (buffercount >= PTS) //if iobuffer full
> {
> buffercount = 0; //reinit buffercount
> flag = 1; //set flag
> }
> }
> So is there any CCS-related reason that the sample_input and sample_output functions wouldn't work but the
> DSK6713_AIC23_ ones would? I've hooked up an oscilloscope to the output, and I've got some audio input. I've also
> tried to plot the output from iobuffer using view->graphs but this gives nothing.
>
> Cheers,
>
> Mike

_____________________________________