Digital Signal Processing Reference
In-Depth Information
//
Squarewave.c
Generates a squarewave using a look-up table
#include "dsk6713_aic23.h" //codec-DSK interface support
Uint32 fs=DSK6713_AIC23_FREQ_8KHZ; //set sampling rate
#define table_size (int)0x40 //size of table=64
short data_table[table_size]; //data table array
int i;
interrupt void c_int11()
//interrupt service routine
{
output_sample(data_table[i]); //output value each Ts
if (i < table_size) ++i; //if table size is reached
else i = 0; //reinitialize counter
return; //return from interrupt
}
main()
{
for(i=0; i<table_size/2; i++) //set 1st half of buffer
data_table[i] = 0x7FFF; //with max value (2^15)-1
for(i=table_size/2;i<table_size;i++) //set 2nd half of buffer
data_table[i] = -0x8000; //with -(2^15)
i = 0; //reinit counter
comm_intr(); //init DSK, codec, McBSP
while (1); //infinite loop
}
FIGURE 2.13.
Square-wave generation program (
squarewave.c
).
will double the period of the square wave, and the discharging effect will be more
pronounced (time constant reduced relative to one-half of the period of the square
wave). Change the sampling frequency to 16 or 24 kHz and verify that the charch-
ing/discharging effect of the capacitor is less pronounced.
Example 2.8: Ramp Generation Using a Lookup Table (
ramptable
)
Figure 2.14 shows a listing of the program
ramptable.c
, which generates a ramp
using a lookup table. A buffer of size 1024 is created. Within
main
, the buffer table
is loaded with 1024 values:
0
,
0x20
,
0x40
,...,or 0,32,64,...,32,736 in decimal.
Build and run this project as
ramptable
. Verify that a ramp with an approxi-
mate peak value of 1.5 V is generated. The ramp has a negative slope due to the 2's-
complement format of the AIC23 codec.
Replace the value
0x20
with
-0x20
and verify that a ramp is generated with a
positive slope with a peak value of approximately 1.5 V.
Note that reducing the number of points will result in a “cleaner” ramp due to
AC coupling, as in the previous square wave generation example.
Search WWH ::
Custom Search