Digital Signal Processing Reference
In-Depth Information
//
Loop_print.c
Data acquisition.Loop with data printed to a file
#include "DSK6713_AIC23.h" //codec-DSK support file
Uint32 fs=DSK6713_AIC23_FREQ_8KHZ; //set sampling rate
#include <stdio.h>
#define BUFFER_SIZE 64 //buffer size
int i=0, j=0;
short buffer[BUFFER_SIZE]; //buffer for data
FILE *fptr;
//file pointer
interrupt void c_int11()
//ISR
{
buffer[i]=((short)input_sample()); //store data in buffer
i++;
//increment buffer count
if (i==BUFFER_SIZE - 1)
//if buffer full
{
fptr = fopen("sine.dat","w"); //create output data file
for (j=0; j<BUFFER_SIZE; j++)
fprintf(fptr,"%d\n",buffer[j]);//write buffer data to file
fclose(fptr); //close file
i = 0;
//initialize buffer count
puts("done");
//finished storing to file
}
output_sample((short)input_sample());
//output data
return;
//return from ISR
}
void main()
{
comm_intr(); //init DSK, codec, McBSP
puts("start\n"); //print "start" indicator
while(1);
//infinite loop
}
FIGURE 2.12.
Loop program to store I/O data in memory and in a file (
loop_print.c
).
Example 2.6: Loop with Data in a Buffer Printed to a File (
loop_print
)
This example extends the preceding loop program so that the acquired input data
are stored in a memory buffer and then printed to a file. Figure 2.12 shows the C
source program
loop_print.c
(included in the folder
loop_print
) that imple-
ments this example. It takes a long time (more than 3000 cycles) to execute the
printf
statement in the program (see Example 1.3). This can be reduced to about
30 cycles using DSP/BIOS, introduced in Chapter 9.
After initialization of the DSK, the
puts
statement prints the word
start
as an
indicator within the CCS command window; then execution proceeds to the infinite
while loop. Upon each interrupt, execution proceeds to ISR, and a newly acquired
data value is stored in a buffer of size 64.
Search WWH ::
Custom Search