Digital Signal Processing Reference
In-Depth Information
help menu in CCS. The next preprocessor directive defines the fixed point
number PI, which approximates the irrational number
. Before compiling,
the preprocessor will replace every occurrence of PI in
Sine_gen.c
with the
number specified.
The next six lines (6 through 8) define the global variables: f0, fs, angle,
offset, sine_value, and amplitude. The variables fs, sine_value, and ampli-
tude are of type
short
, which means they hold 16-bit signed integer values.
The variables f0, angle, and offset are of type float, which means they hold
IEEE single precision (32-bit) floating-point numbers.
3
Notice that all of the
lines that contain statements end with a semicolon. This is standard in C
code. The only lines that do not get semicolons are function names, such as
c_int11()
, conditional statements such as
if()
, and opening and closing braces
({ }) associated with them.
The last section of code (lines 22 through 26) contains the function
main()
.
The format of the
main()
function will
not
change from program to program.
Lines 22, 23, and 26 will always be the first two lines and last line, respectively
of this routine. The first line in
main()
(line 24) calls the function
comm intr()
.
This function is located within the file
C6xdskinit.c
, which is one of the
support
files given to you. This function initializes the on-board codec, spec-
ifies that the transmit interrupt XINT0 will occur in SP0, initializes the
interrupt INT11 to handle this interrupt, and allows interrupts INT4 through
INT15 to be recognized by the DSP chip. To learn more about configuring
the DSP chip for handling interrupts, examine the code in
C6xdskinit.c
and
π
refer to
References 3
-
6
in this chapter. Now, the DSP chip and codec have
been configured to communicate via interrupts, which the codec will gen-
erate every 0.125ms. The program
Sine_gen.c
now waits for an interrupt
from the codec, so an infinite loop keeps the processor idle until an interrupt
occurs. This does not have to be the case, since an interrupt will halt the CPU
regardless of whether it is processing or idling. But in this program, there is
no other processing, so we must keep the processor idling while waiting for
an interrupt.
The middle section of code (lines 9 through 20) is used to define the
Interrupt Service Routine
or
ISR
. When an interrupt occurs, the program
branches to the ISR
c_int11()
as specified by
vectors 11.asm
. This interrupt
generates the current sample of the sinusoid and outputs it to the codec.
Line 11 determines the offset value 2
fo/fs
. For a given
fo
, this value will not
change, so it does not need to be calculated every time an interrupt occurs.
However, by calculating this value here, we will be able to change the value
of our sinusoid using a
Watch Window
. This is demonstrated in the next
section. Line 12 calculates the current sample point by taking the value stored
in the global variable angle and adding the offset value to it. The angle
variable is, of course, the angle (in radians) that is passed to the sine function.
NB: In C the command
angle += offset
; is shorthand for the command
angle =
angle + offset;
. The
sin
(
x
) function in C approximates the value of sin(
x
) for
any value of
x
, but a better and more efficient approximation will be computed
π