Documente Academic
Documente Profesional
Documente Cultură
USER MANUAL
TI-DIVISION
TI-DIVISION
TABLE OF CONTENTS
1. INSTALLATION PROCEDURE. 4
2. DSK FEAUTURES. 8
3. INTRODUCTON TO CODE COMPOSER STUDIO13
4. PROCEDURE TO WORK ON CCS....14
5. EXPERIMENTS USING DSK
a.
b.
c.
d.
e.
f.
b.
c.
g.
h.
i.
j.
k.
MINI PROJECT
TI-DIVISION
INSTALLATION PROCEDURE
SYSTEM REQUIREMENTS
Minimum
Recommended
128MB RAM
16bit Color
TI-DIVISION
TI-DIVISION
TI-DIVISION
DIAGNOSTIC:
Test the USB port by running DSK Port test from the start menu
(Available on desktop)
Select StartSelect 5416 DSK Diagnostic Utility
The Screen Look like as below. The below Screen will appear
Select Start Option
Utility Program will test the board
After testing Diagnostic Status you will get PASS
TI-DIVISION
TROUBLESHOOTING:1.
If installing on Windows XP and your PC is connected to the internet through a firewall the
USB install may take up to 15 minutes if you let it complete normally. The work-around for
this issue is to simply disconnect your network cable during the USB hardware install.
2. Make sure all of the Configuration Switches (SW3) are set in the off position. This configures
the DSK for the factory default settings of little endian processor mode booting out of the onboard Flash memory.
3. Some of the Help Files are links to Adobe Acrobat PDF files. If you intend to access these files
you must have Adobe Acrobat installed on your system.
4. If you want to verify a successful USB driver install, open your device manager by right
clicking on the My Computer icon on your desktop and selecting Properties --> HW -->
Device Manager. You should see a new class SD USB Based Debug Tools and one
Spectrum Digital TMS320C5416 DSK installed.
5. The BUSY LED above the USB connector comes on when power is applied to the DSK. Do not
launch Code Composer until the LED is off.
6. Go to CMOS setup Enable the USB Port Option
(The required Device drivers will load along with CCS Installation)
7. Message: Failed: USB device is NOT enumerated or plugged in.
Problem: Windows cannot find the DSK. Check power and USB Cable
8. Messages: Waiting for USB Enumeration.
Status: This is a status message which indicates that Code Composer Studio is waiting for
communication with the on-board JTAG emulator to be established. This should take less than 10
seconds. Do not hit the close button unless it is clear that something is wrong (the progress bar
runs forever).
TI-DIVISION
The 5416 DSP Starter Kit (DSK) is a low-cost platform, which lets enables customers to evaluate
and develop applications for the TI C54X DSP family.
The primary features of the DSK are:
160 MHz TMS320VC5416 DSP
PCM3002 Stereo Codec
Four Position User DIP Switch and Four User LEDs
On-board Flash and SRA
DSK Board Features
Features
TMS320VC5416 DSP
CPLD
External SRAM
External Flash
PCM3002 Codec
4 User LEDs
4 User DIP Switches
4 Jumpers
Daughter card Expansion Interface
HPI Expansion Interface
Embedded JTAG Emulator
Details
160MHz, fixed point, 128Kwords internal RAM
Programmable "glue" logic
64Kwords, 16-bit interface
256Kwords, 16-bit interface
Stereo, 6KHz 48KHz sample rate, 16 or 20 bit
samples, mic-in, line-in, line-out and speaker jacks
Writable through CPLD
Readable through CPLD
Selects power-on configuration and boot modes
Allows user to enhance functionality with add-on
daughter cards
Allows high speed communication with another DSP
Provides high speed JTAG debug through widely
accepted USB host interface
TI-DIVISION
On-chip PLL generates processor clock rate from slower external clock reference.
Timer generates periodic timer events as a function of the processor clock. Used by
DSP/BIOS to create time slices for multitasking.
DMA Controller 6 channel direct memory access controller for high speed data
transfers without intervention from the DSP.
3 McBSPs Multichannel buffered serial ports. Each McBSP can be used for high-speed
serial data transmission with external devices or reprogrammed as general purpose I/Os.
EMIF External memory interface. The EMIF provides a 16-bit bus on which external
memories and other devices can be connected. It also includes internal wait state and bank
switching controls.
10
TI-DIVISION
IDE
Debug IDE
Advanced watch windows
Integrated editor
File I/O, Probe Points, and graphical algorithm scope probes
Advanced graphical signal analysis
Interactive profiling
Automated testing and customization via scripting
Visual project management system
Compile in the background while editing and debugging
Multi-processor debugging
Help on the target DSP
Note:Launch the DSK help file by opening the following file using Windows Explorer.
C:\CCStudio_v3.1\docs\hlp\c5416dsk.hlp
Documents for Reference:
spru509 Code Composer Studio getting started guide.
spru598 Instruction set guide for 54xx family
spru131 CPU & Peripherals guide
pcm3002
ADC & DAC(CODEC) Data Manual.
spru172 mnemonic instruction guide
spru179 Algebraic Instruction set.
spru173 Application Guide.
Soft Copy of datasheets are available at : C:\CCStudio_v3.1\docs\pdf.
11
TI-DIVISION
Start Code Composer Studio (ignore this if CCS is already running) by double-clicking on the
C5416 DSK icon on your desktop.
Use the Debug Connect (Alt+c) menu option to open a debug connection to the DSK board
12
TI-DIVISION
13
TI-DIVISION
14
TI-DIVISION
C I/O library
Low-level support functions that provide I/O to the host operating system
15
TI-DIVISION
5. To Compile:
Project Compile File
6. To build or Link:
Project build,
Which will create the final executable (.out) file.(Eg. Sin. out).
7. Procedure to Load and Run program:
Load program to DSK:
16
TI-DIVISION
8. To execute project:
Debug Run.
17
TI-DIVISION
Sin.c
#include<stdio.h>
#include<math.h>
float a[100];
main()
{
int i;
for(i=0;i<99;i++)
{
a[i]= sin(2*3.14*5*i/100);
printf("%f",a[i]);
}
}
Graph Plotting
1. Goto CCS tool bar View Graph Time and frequency.
(In any graph the Start address is the important parameter to be checked.)
Refer fig.1.for the graph properties
Fig. 1
OUTPUT
18
TI-DIVISION
7. Similarly go to view & select CPU registers to view the changes happening in CPU
registers.
8. Repeat steps 2 to 6.
19
TI-DIVISION
Difference Equation
Description:An Nth order linear constant coefficient difference equation can be represented as
N
M
ak y(n-k) =
k=0
br x(n-r)
r=0
If we assume that the system is causal a linear difference equation provides an explicit relationship
between the input and output. This can be seen by rewriting above equation.
M
y(n) =
ak/a0 y y(n-k)
k=1
20
TI-DIVISION
PROCEDURE:
Open Code Composer Studio , make sure the DSP kit is turned on.
Start a new project using Project-new pull down menu, save it in a
separate directory(c:\CCStudio_v3.1\myprojects) with name Diff Eq.pjt.
Add the source files DIFF EQ1.c
to the project using Project
add files to project pull down menu.
Add the linker command file hello.cmd
(Path: C:\ CCStudio_v3.1\tutorial\sim54xx\hello1\hello.cmd)
Files of type Linker command file (*.cmd, *.lcf)
Add the run time support library file rts_EXT.lib
(Path: C:\ CCStudio_v3.1\c5400\cgtools\lib\rts_EXT.lib)
Files of type Object and library files (*.o*, *.l*)
Compile the program using the Project-compile pull down menu or by
clicking the shortcut icon on the left side of program window.
Build the program using the Project-Build pull down menu or by
clicking the shortcut icon on the left side of program window.
Load the program(Diff Eq.out) in program memory of DSP chip using the
File-load program pull down menu.
To View output graphically
Select view Graph Time and frequency.
21
TI-DIVISION
Note: To verify the Diffence Equation , Observe the output for high
frequency and low frequency by changing variable FREQ
in the program.
22
TI-DIVISION
LINEAR CONVOLUTION
Description:Linear Convolution Involves the following operations.
1. Folding
2. Multiplication
3. Addition
4. Shifting
These operations can be represented by a Mathematical Expression as follows:
x[n] = {1, 2, 3, 4}
h[k] = {1, 2, 3, 4}
r=
n= 0
1
2
3
0
1
2
3
4
5
x[0]h[0] x[0]h[1] x[0]h[2] x[0]h[3]
x[1]h[0] x[1]h[1] x[1]h[2] x[1]h[3]
x[2]h[0] x[2]h[1] x[2]h[2] x[2]h[3]
x[3]h[0] x[3]h[1] x[3]h[2]
Output:
x[3]h[3]
23
TI-DIVISION
conv.c:
/* prg to implement linear convolution */
#include<stdio.h>
#include<math.h>
int y[20];
main()
{
int m=6;
/*Lenght of i/p samples sequence*/
int n=6;
/*Lenght of impulse response Co-efficients */
int i=0,j;
int x[15]={1,2,3,4,5,6,0,0,0,0,0,0}; /*Input Signal Samples*/
int h[15]={1,2,3,4,5,6,0,0,0,0,0,0}; /*Impulse Response Co-efficients*/
for(i=0;i<m+n-1;i++)
{
y[i]=0;
for(j=0;j<=i;j++)
y[i]+=x[j]*h[i-j];
}
for(i=0;i<m+n-1;i++)
printf("%d\n",y[i]);
}
PROCEDURE:
Open Code Composer Studio, make sure the DSP kit is turned on.
Use the Debug Connect menu option to open a debug connection to the DSK board
Start a new project using Project-new pull down menu, save it in a
separate directory(C:\CCStudio_v3.1\myprojects) with name lconv.pjt.
Add the source files conv.c
to the project using Projectadd files to project pull down menu.
Add the linker command file hello.cmd .
(Path: C:\CCStudio_v3.1\tutorial\sim54xx\hello1\hello.cmd)
Add the run time support library file rts_EXT.lib
(Path: C:\CCStudio_v3.1\c5400\cgtools\lib\rts_EXT.lib)
Compile the program using the Project-compile pull down menu or by
clicking the shortcut icon on the left side of program window.
Build the program using the Project-Build pull down menu or by
clicking the shortcut icon on the left side of program window.
Load the program(lconv.out) in program memory of DSP chip using the
File-load program pull down menu.
24
TI-DIVISION
25
TI-DIVISION
CIRCULAR CONVOLUTION
Description:Steps for Cyclic Convolution
Steps for cyclic convolution are the same as the usual convolution, except all index calculations
are done "mod N" = "on the wheel"
Steps for Cyclic Convolution
Step1: Plot f[m] and h[m]
Figure 2: Step 2
Step 3: Point wise multiply the f[m] wheel and the h[nm] wheel. Sum=y[n]
Step 4: Repeat for all 0nN1
Example 1: Convolve (n = 4)
Subfigure 3.1
Subfigure 3.2
Figure 3: Two discrete-time signals to be convolved.
h[m] =
26
TI-DIVISION
Figure 4
Multiply f[m] and sum to yield: y[0] =3
h[1m]
Figure 5
Multiply f[m] and sum to yield: y[1] =5
h[2m]
Figure 6
Multiply f[m] and sum to yield: y[2] =3
h[3m]
Figure 7
Multiply f[m] and sum to yield: y[3] =1
TI-DIVISION
28
TI-DIVISION
IN PUT:
Eg:
OUT PUT
x[4]={1, 2, 3,4}
h[4]={1, 2, 3,4}
y[4]={26, 28, 26,20}
PROCEDURE:
Open Code Composer Studio; make sure the DSP kit is turned on.
Start a new project using Project-new pull down menu, save it in a
separate directory(C:\CCStudio_v3.1\myprojects) with name cir conv.pjt.
Add the source files Circular Convolution
to the project using Projectadd files to project pull down menu.
Add the linker command file hello.cmd.
(Path: C:\CCStudio_v3.1\tutorial\sim54xx\hello1\hello.cmd)
Add the run time support library file rts_EXT.lib
(Path: C:\CCStudio_v3.1\c5400\cgtools\lib\rts_EXT.lib)
Compile the program using the Project-compile pull down menu or by
clicking the shortcut icon on the left side of program window.
Build the program using the Project-Build pull down menu or by
clicking the shortcut icon on the left side of program window.
Load the program(lconv.out) in program memory of DSP chip using the
File-load program pull down menu.
29
TI-DIVISION
TI-DIVISION
HOW TO PROCEED
Open Code Composer Studio; make sure the DSP kit is turned on.
Use the Debug Connect menu option to open a debug connection to the DSK board
Start a new project using Project-new pull down menu, save it in a
Separate directory (C:\CCStudio\myprojects) with name FSK.pjt.
Add the source files FSK.c in the project using
Project add files to project pull down menu.
Add the linker command file hello.cmd
Add the rts file rts_EXT.lib
Compile the program using the Project-compile pull down menu or by
clicking the shortcut icon on the left side of program window.
Build the program using the Project-Build pull down menu or by
clicking the shortcut icon on the left side of program window.
Load the program in program memory of DSP chip using the File-load program pull
down menu.
Run the program and observe output using graph utility.
Graphical display:
1. After run, Go to View<Graph<Time and Frequency.
31
TI-DIVISION
32
TI-DIVISION
HOW TO PROCEED
Open Code Composer Studio; make sure the DSP kit is turned on.
Use the Debug Connect menu option to open a debug connection to the DSK board
Start a new project using Project-new pull down menu, save it in a
Separate directory (C:\CCStudio\myprojects) with name FSK.pjt.
Add the source files ASK.c in the project using
Project
add files to project pull down menu.
Add the linker command file hello.cmd
Add the rts file rts_EXT.lib
Compile the program using the Project-compile pull down menu or by
clicking the shortcut icon on the left side of program window.
Build the program using the Project-Build pull down menu or by
clicking the shortcut icon on the left side of program window.
Load the program in program memory of DSP chip using the File-load program pull
down menu.
Run the program and observe output using graph utility.
Graphical display:
1. After run, Go to View
Graph
Time and Frequency.
33
TI-DIVISION
2. Connect CRO/Desktop Speakers to the Socket Provided for LINE OUT or connect a
headphone to the Headphone out Socket.
3. Now Switch on the DSK and Bring Up Code Composer Studio on the PC.
4. Use the Debug Connect menu option to open a debug connection to the DSK board
34
TI-DIVISION
TI-DIVISION
appears.
13. Under General property set Breakpoint Emulation to Do Not Stop.
14. Under Transmit modes property set clock polarity to Falling Edge.
15. Under Transmit Lengths property set Word Length Phase1 to 32-bits and set
Words/Frame phase1 to 2.
16. Under Receive modes property set clock polarity to Rising Edge.
17. Under Receive Multichannel property set Rx Channel Enable to All 128 Channels.
18. Under Transmit Multichannel property set Tx Channel Enable to All 128 Channels.
19. Under the Receive Lengths property set Word Length Phase1 to 32-bits and set
Words/Frame phase1 to 2.
20. Under the Sample-Rate Gen property set Generator Clock Source to BCLKR pin.
Set Frame Width to 32 and Frame period to 64.
21. Select Apply and click O.K.
22. Select McBSP2 under the MCBSP Resource Manager.
23. Right click on McBSP2 and select properties where a McBSP2 Properties Window
appears. Enable the Open handle to McBSP option and pre-initialization option. Select
msbspCfg0 under the Pre-initialize pop-up menu and change the Specify Handle
Name property to C54XX_DMA_MCBSP_hMcbsp. Select Apply and click O.K.
24. Add the generated YYYYcfg.cmd file to the current project.
25. Add the given mcbsp_io.c file to the current project which has the main function and calls
all the other necessary routines.
26. View the contents of the generated file YYYYcfg_c.c and copy the include header file
YYYYcfg.h to the mcbsp_io.c file.
27. Add the library file dsk5416f.lib from the location C:\ti\C5400\dsk5416\lib\dsk5416f.lib
to the current project
28. Select project
build options
Compiler
Advance and enable the use Far calls option.
29. Build, Load and Run the program.
30. You can notice the input signal of 500 Hz. appearing on the CRO verifying the McBSP
configuration.
31. You can also pass an audio input and hear the output signal through the speakers.
32. You can also vary the sampling frequency using the DSK5416_PCM3002_setFreq Function
in the mcbsp_io.c file and repeat the above steps.
33. Open the File Menu new Source file
34. Type the code in editor window. Save the file in project folder. (Eg: Codec.c).
Important note: Save your source code with preferred language extension. For ASM
codes save the file as code(.asm) For C and C++ codes code (*.c,*.cpp) respectively.
35. Add the saved Codec.c file to the current project which has the main function and calls all
the other necessary routines.
Project Add files to Project Codec.c
36
TI-DIVISION
5.0 Conclusion:
The codec PCM3002 successfully configured using the board support library
and verified.
37
TI-DIVISION
Mcbsp_io.c:
#include "YYYYcfg.h"
#include <dsk5416.h>
#include <dsk5416_pcm3002.h>
short left_input,right_input;
DSK5416_PCM3002_Config setup = {
0x1ff,
0x1ff,
0x2,
0x0
};
void main ()
{
DSK5416_PCM3002_CodecHandle hCodec;
// Initialize the board support library
DSK5416_init();
// Start the codec
hCodec = DSK5416_PCM3002_openCodec(0, &setup);
// Set codec frequency
DSK5416_PCM3002_setFreq(hCodec, 48000);
// Endless loop IO audio codec
while(1){
// Read 16 bits of codec data, loop to retry if data port is busy
while(!DSK5416_PCM3002_read16(hCodec, &left_input));
while(!DSK5416_PCM3002_read16(hCodec, &right_input));
// Write 16 bits to the codec, loop to retry if data port is busy
while(!DSK5416_PCM3002_write16(hCodec, left_input));
while(!DSK5416_PCM3002_write16(hCodec, right_input));
}
}
38
TI-DIVISION
EQUIPMENTS NEEDED :
39
TI-DIVISION
ALGORITHM TO IMPLEMENT:
We need to realize the Kaiser high pass FIR filter by implementing the difference equation y[n] =
b0x[n] + b1x[n-1])+b2x[n-2]b2x[n-25] where b0 b25 are feed forward coefficients [Assume
25thorder of filter] . These coefficients are calculated using MATLAB. A direct form I
implementation approach is taken.
Step 1 - Initialize the McBSP, the DSP board and the on board codec.
Kindly refer the Topic Configuration of 5416 McBSP using CSL
Step 2 - Initialize the discrete time system, that is, specify the initial conditions. Generally
zero initial conditions are assumed.
Step 3 - Take sampled data from codec while input is fed to DSP kit from the signal
generator. Since Codec is stereo , take average of input data read from left and right channel .
Store sampled data at a memory location.
Step 4 - Perform filter operation using above said difference equation and store filter Output
at a memory location.
Step 5 - Output the value to codec (left channel and right channel) and view the output at
Oscilloscope.
Step 6 - Go to step 3.
II.
III.
IV.
40
TI-DIVISION
41
TI-DIVISION
Rectangular
Triangular
Kaisar [Where 8-->Beta Co-efficient]
42
TI-DIVISION
T.1 : Matlab generated Coefficients for FIR Low Pass Kaiser filter:
Cutoff -500Hz
float b_kai1[51]={-0,0,0.0001,0.0002,0.0005,0.0008,0.0012,0.0013,0.001,-0,-0.0018,-0.0045,
-0.0076,-0.0106,-0.0125,-0.0121,0.0082,0,0.0129,0.0302,0.0506,0.0723,0.0929,0.1099,0.1211,0.125,0.1211,0.1099,0.0929,0.0723,
0.0506,0.0302,0.0129,0,-0.0082,-0.0121,-0.0125,-0.0106,-0.0076,-0.0045,-0.0018,0,0.001,0.0013,0.0012,0.0008,0.0005,0.0002,0.0001,0,-0};
Cutoff -1000Hz
IMPLEMENTATION OF AN FIR FILTER :
float b_kai2[51]={- 0,-0,-0.0001,-0.0003,-0.0004,0,0.0009,0.0019,0.0018,-0,-0.0034,-0.0064,0.0059,0,0.0096,0.0171,0.0152,-0,-0.0238,-0.0426,ALGORITHM TO IMPLEMENT :
0.0387,0,0.0711,0.1554,0.2237,0.25,0.2237,0.1554,0.0711,0,-0.0387,-0.0426,-0.0238,0,0.0152,0.0171,0.0096,0,-0.0059,-0.0064,-0.0034,-0,0.0018,0.0019,0.0009,0,-0.0004,-0.0003,We need to realize an advance FIR filter by implementing its difference equation as per the
0.0001,-0,0};
specifications. A direct form I implementation approach is taken. (The filter coefficients are taken
as ai as generated by the Matlab program.)
Cutoff -1500Hz
float b_kai3[51]={ 0,0.0001,0.0002,0.0001,-0.0003,-0.0008,-0.001,0,0.002,0.0035,0.0024,
0.0022,-0.0078,-0.0092,-0.0023,0.011,0.0214,0.0173,-0.0059,-0.0369,-0.0514,0.0247,0.0503,0.153,0.2424,0.2778,0.2424,0.153,0.0503,-0.0247,-0.0514,-0.0369,0.0059,0.0173,0.0214,0.011,-0.0023,-0.0092,-0.0078,-0.0022,0.0024,0.0035,0.002,0,-0.001,0.0008,-0.0003,0.0001,0.0002,0.0001,0};
T.2 :Matlab generated Coefficients for FIR Low Pass Rectangular filter
Cutoff -500Hz
float b_rect1[51]={-0.0046,0,0.005,0.0097,0.0133,0.0151,0.0147,0.0118,0.0068,-0,-0.0077,0.0152,-0.0214,-0.0251,-0.0253,-0.0213,0.0128,0,0.0165,0.0355,0.0557,0.0754,0.0929,0.1066,0.1154,0.1184,0.1154,0.1066,0.0929,0.0754
,0.0557,0.0355,0.0165,0,-0.0128,-0.0213,-0.0253,-0.0251,-0.0214,-0.0152,-0.0077,0,0.0068,0.0118,0.0147,0.0151,0.0133,0.0097,0.005,0,-0.0046};
Cutoff -1000Hz
float b_rect2[51]={-0.0091,-0,-0.0099,-0.0147,-0.0109,0,0.012,0.0179,0.0134,-0,-0.0152,0.0231,-0.0176,0,0.0207,0.0323,0.0254,-0,-0.0326,-0.0538,0.0456,0,0.0761,0.1614,0.2282,0.2535,0.2282,0.1614,0.0761,0,-0.0456,-0.0538,-0.0326,0,0.0254,0.0323,0.0207,0,-0.0176,-0.0231,-0.0152,-0,0.0134,0.0179,0.012,0,-0.0109,-0.0147,0.0099,-0,0.0091};
Cutoff -1500Hz
float b_rect2[51]={- 0.0021,0.0112,0.0126,0.0048,-0.0074,-0.0152,0.0125,0,0.0139,0.019,0.0103,-0.0076,-0.0224,-0.0223,-0.0049,0.0199,0.0344,0.0249,-0.0077,0.0447,-0.0582,-0.0265,0.0516,0.1524,0.237,0.27,0.237,0.1524,0.0516,-0.0265,-0.0582,-0.0447,T.3
: Matlab generated Coefficients for FIR Low Pass Triangular filter
0.0077,0.0249,0.0344,0.0199,-0.0049,-0.0223,-0.0224,-0.0076,0.0103,0.019,0.0139,0,-0.0125,0.0152,-0.0074,0.0048,0.0126,0.0112,0.0021};
43
TI-DIVISION
T.3 : Matlab generated Coefficients for FIR Low Pass Triangular filter
Cutoff -500Hz
float b_tri1[51]={ [0,0,0.0005,0.0013,0.0024,0.0034,0.004,0.0037,0.0024,-0,-0.0035,-0.0075,0.0116,-0.0147,-0.016,-0.0144,0.0092,0,0.0134,0.0304,0.0502,0.0713,0.092,0.1105,0.1248,0.1334,0.1248,0.1105,0.092,0.071
3,0.0502,0.0304,0.0134,0,-0.0092,-0.0144,-0.016,-0.0147,-0.0116,-0.0075,-0.0035,0,0.0024,0.0037,0.004,0.0034,0.0024,0.0013,0.0005,0,0;]};
Cutoff -1000Hz
float b_tri2[51]={ 0,-0,-0.0008,-0.0018,-0.0018,0,0.0029,0.0051,0.0044,-0,-0.0062,-0.0103,0.0086,0,0.0118,0.0197,0.0165,-0,-0.0239,-0.0416,0.0372,0,0.0682,0.1512,0.2232,0.2582,0.2232,0.1512,0.0682,0,-0.0372,-0.0416,-0.0239,0,0.0165,0.0197,0.0118,0,-0.0086,-0.0103,-0.0062,-0,0.0044,0.0051,0.0029,0,-0.0018,-0.0018,0.0008,-0,0};
Cutoff -1500Hz
float b_tri3[51]={ 0,0.0005,0.0011,0.0006,-0.0012,-0.0032,-0.0032,0,0.0047,0.0073,0.0044,0.0035,-0.0114,-0.0123,-0.0029,0.0126,0.0233,0.0179,-0.0058,-0.0359,-0.0492,0.0235,0.048,0.1483,0.2407,0.2857,0.2407,0.1483,0.048,-0.0235,-0.0492,-0.0359,0.0058,0.0179,0.0233,0.0126,-0.0029,-0.0123,-0.0114,-0.0035,0.0044,0.0073,0.0047,0,0.0032,-0.0032,-0.0012,0.0006,0.0011,0.0005,0};
44
TI-DIVISION
Initialize Counter = 0
Initialize Output = 0 , i = 0
Output += coeff[N-i]*val[i]
Shift the input value by one
No
Is the loop
Cnt = order
Poll the ready bit, when
asserted proceed.
Yes
Output += coeff[0]*data
Put the data in val array.
45
TI-DIVISION
};
void main ()
{
DSK5416_PCM3002_CodecHandle hCodec;
// Initialize the board support library
DSK5416_init();
// Start the codec
hCodec = DSK5416_PCM3002_openCodec(0, &setup);
// Set codec frequency
DSK5416_PCM3002_setFreq(hCodec,8000);
// Endless loop IO audio codec
while(1)
{
// Read 16 bits of codec data, loop to retry if data port is busy
while(!DSK5416_PCM3002_read16(hCodec, &left_input));
while(!DSK5416_PCM3002_read16(hCodec, &right_input));
left_output=FIR_FILTER(&filter_Coeff ,left_input);
right_output=left_output;
// Write 16 bits to the codec, loop to retry if data port is busy
46
TI-DIVISION
while(!DSK5416_PCM3002_write16(hCodec, left_output));
while(!DSK5416_PCM3002_write16(hCodec, right_output));
}
}
signed int FIR_FILTER(float * h, signed int x)
{
int i=0;
signed long output=0;
in_buffer[0] = x; /* new input at buffer[0] */
for(i=51;i>0;i--)
in_buffer[i] = in_buffer[i-1]; /* shuffle the buffer */
for(i=0;i<51;i++)
output = output + h[i] * in_buffer[i];
return(output);
}
HOW TO PROCEED:
TI-DIVISION
11. Add the saved Fir.c file to the current project which has the main function and calls all
the other necessary routines.
Project Add files to Project Codec.c
12. Add the library file dsk5416f.lib to the current project
Path C:\CCStudio_v3.1\C5400\dsk5416\lib\dsk5416f.lib
Files of type Object and library files (*.o*, *.l*)
13. Copy header files dsk5416.h and dsk5416_pcm3002.h from and paste it in current
project folder.
C:\CCStudio_v3.1\C5400\dsk5416\include.
14. Add the header file generated within xyzcfg_c.c to Fir.c
Note:- Double click on xyzcfg_c.c Copy the first line header (eg.xyzcfg.h) and paste that in
source file (eg.Fir.c).
15. Compile the program using the Project-compile pull down menu or by
clicking the shortcut icon on the left side of program window.
16. Build the program using the Project-Build pull down menu or by clicking the shortcut
icon on the left side of program window.
17. Load the program (Codec.out) in program memory of DSP chip using the
File-load program pull down menu.
18. Debug
Run
48
TI-DIVISION
49
TI-DIVISION
EQUIPMENTS NEEDED:
50
TI-DIVISION
ALGORITHM TO IMPLEMENT:
We need to realize the Butter worth band pass IIR filter by implementing the difference equation
y[n] = b0x[n] + b1x[n-1]+b2x[n-2]-a1y[n-1]-a2y[n-2] where b0 b2, a0-a2 are feed forward and
feedback word coefficients respectively [Assume 2nd order of filter].These coefficients are
calculated using MATLAB.A direct form I implementation approach is taken.
Step 1 - Initialize the McBSP, the DSP board and the on board codec.
Kindly refer the Topic Configuration of 5416Codec using BSL
Step 2 - Initialize the discrete time system, that is, specify the initial conditions. Generally
zero initial conditions are assumed.
Step 3 - Take sampled data from codec while input is fed to DSP kit from the signal
generator. Since Codec is stereo, take average of input data read from left and right channel.
Store sampled data at a memory location.
Step 4 - Perform filter operation using above said difference equation and store filter Output
at a memory location.
Step 5 - Output the value to codec (left channel and right channel) and view the output at
Oscilloscope.
Step 6 - Go to step 3.
51
TI-DIVISION
Start
output = x[0]b0+x[-1]b1+
x[-2]b2 - y[-1]a1 - y[-2]a2
x[-1]=x[0]
Poll for ready bit
Poll the ready bit, when
asserted proceed.
Stop
F.1 : Flowchart for implementing IIR filter.
52
TI-DIVISION
53
TI-DIVISION
w=(w/max(w))*12000;
plot(w,20*log10(abs(h)),'linewidth',2,'color','r')
grid on
legend('Butterworth','Chebyshev Type-1');
xlabel('Frequency in Hertz');
ylabel('Magnitude in Decibels');
title('Magnitude response of Low pass IIR filters (Fc=2500Hz)');
figure(2);
[h,w]=freqz(num_bw2,den_bw2);
w=(w/max(w))*12000;
plot(w,20*log10(abs(h)),'linewidth',2)
hold on
[h,w]=freqz(num_cb2,den_cb2);
w=(w/max(w))*12000;
plot(w,20*log10(abs(h)),'linewidth',2,'color','r')
grid on
legend('Butterworth','Chebyshev Type-1 (Ripple: 3dB)');
xlabel('Frequency in Hertz');
ylabel('Magnitude in Decibels');
title('Magnitude response in the passband');
axis([0 12000 -20 20]);
Fc=2500Hz
Floating Point
Values
0.044408
0.088815
0.044408
1.000000
-1.412427
0.663336
Fixed Point
Values(Q15)
1455
1455[B1/2]
1455
32767
-23140[A1/2]
21735
Fc=800Hz
Floating Point
Values
0.005147
0.010295
0.005147
1.000000
-1.844881
0.873965
Fixed Point
Values(Q15)
168
168[B1/2]
168
32767
-30225[A1/2]
28637
Fc=8000Hz
Floating Point
Values
0.354544
0.709088
0.354544
1.000000
0.530009
0.473218
Fixed Point
Values(Q15)
11617
11617[B1/2]
11617
32767
8683[A1/2]
15506
Note: We have Multiplied Floating Point Values with 32767(215) to get Fixed Point Values.
Fc=2500Hz
Floating Point
Values
0.072231
0.144462
0.072231
1.000000
-1.109229
0.398152
Fixed Point
Values(Q15)
2366
2366[B1/2]
2366
32767
-18179[A1/2]
13046
Fc=800Hz
Floating Point
Values
0.009526
0.019052
0.009526
1.000000
-1.705552,
0.743655
Fixed Point
Values(Q15)
312
312[B1/2]
312
32767
-27943[A1/2]
24367
Fc=8000Hz
Floating Point
Values
0.465153
0.930306
0.465153
1.000000
0.620204
0.240408
Fixed Point
Values(Q15)
15241
15241[B1/2]
15241
32767
10161[A1/2]
7877
Note: We have Multiplied Floating Point Values with 32767(215) to get Fixed Point Values.
54
TI-DIVISION
Fc=2500Hz
Floating Point
Values
0.388513
-0.777027
0.388513
1.000000
-1.118450
0.645091
Fixed Point
Values(Q15)
12730
-12730[B1/2]
12730
32767
-18324[A1/2]
21137
Fc=4000Hz
Floating Point
Values
0.282850
-0.565700
0.282850
1.000000
-0.451410
0.560534
Fixed Point
Values(Q15)
9268
-9268[B1/2]
9268
32767
-7395[A1/2]
18367
Fc=7000Hz
Floating Point
Values
0.117279
-0.234557
0.117279
1.000000
0.754476
0.588691
Fixed Point
Values(Q15)
3842
-3842[B1/2]
3842
32767
12360[A1/2]
19289
Note: We have Multiplied Floating Point Values with 32767(215) to get Fixed Point Values.
Fc=2500Hz
Floating Point
Values
0.626845
-1.253691
0.626845
1.000000
-1.109229
0.398152
Fixed Point
Values(Q15)
20539
-20539[B1/2]
20539
32767
-18173[A1/2]
13046
Fc=4000Hz
Floating Point
Values
0.465153
-0.930306
0.465153
1.000000
-0.620204
0.240408
Fixed Point
Values(Q15)
15241
-15241[B1/2]
15241
32767
-10161[A1/2]
7877
Fc=7000Hz
Floating Point
Values
0.220195
-0.440389
0.220195
1.000000
0.307566
0.188345
Fixed Point
Values(Q15)
7215
-7215[B1/2]
7215
32767
5039[A1/2}
6171
Note: We have Multiplied Floating Point Values with 32767(215) to get Fixed Point Values.
TI-DIVISION
//22586,-22586,22586,32767,-20964,15649
//20539,-20539,20539,32767,-18173,13046
//15241,-15241,15241,32767,-10161,7877
};
/*Select particular set of co-efficients different Cut-off frequencies from given Tables */
DSK5416_PCM3002_Config setup = {
0x1ff,
0x1ff,
0x2,
0x0
};
void main ()
{
DSK5416_PCM3002_CodecHandle hCodec;
// Initialize the board support library
DSK5416_init();
// Start the codec
hCodec = DSK5416_PCM3002_openCodec(0, &setup);
// Set codec frequency
DSK5416_PCM3002_setFreq(hCodec,24000);
// Endless loop IO audio codec
while(1)
{
// Read 16 bits of codec data, loop to retry if data port is busy
while(!DSK5416_PCM3002_read16(hCodec, &left_input));
while(!DSK5416_PCM3002_read16(hCodec, &right_input));
left_output=IIR_FILTER(&filter_Coeff , left_input);
right_output=left_output;
// Write 16 bits to the codec, loop to retry if data port is busy
while(!DSK5416_PCM3002_write16(hCodec, left_output));
while(!DSK5416_PCM3002_write16(hCodec, right_output));
}
}
signed int IIR_FILTER(const signed int * h, signed int x1)
{
signed int x[6] = { 0, 0, 0, 0, 0, 0 }; /* x(n), x(n-1), x(n-2). Must be static */
signed int y[6] = { 0, 0, 0, 0, 0, 0 }; /* y(n), y(n-1), y(n-2). Must be static */
long temp=0;
temp = x1;
x[0] = (signed int) temp;
temp = ( (long)h[0] * x[0]) ;
temp += ( (long)h[1] * x[1]);
temp += ( (long)h[1] * x[1]);
TI-DIVISION
/* B2 * x(n-2) */
/* A1/2 * y(n-1) */
/* A1/2 * y(n-1) */
/* A2 * y(n-2) */
TI-DIVISION
11. Add the saved Iir.c file to the current project which has the main function and calls all
the other necessary routines.
Project Add files to Project Codec.c
12. Add the library file dsk5416f.lib to the current project
Path C:\CCStudio_v3.1\C5400\dsk5416\lib\dsk5416f.lib
13. Copy header files dsk5416.h and dsk5416_pcm3002.h from and paste it in current
project folder.
C:\CCStudio_v3.1\C5400\dsk5416\include.
14. Add the header file generated within xyzcfg_c.c to Iir.c
Note:- Double click on xyzcfg_c.c Copy the first line header (eg.xyzcfg.h) and paste that in
source file (eg.Fir.c).
15. Compile the program using the Project-compile pull down menu or by
Clicking the shortcut icon on the left side of program window.
16. Build the program using the Project-Build pull down menu or by clicking the shortcut
icon on the left side of program window.
17. Load the program (Iir.out) in program memory of DSP chip using the
File-load program pull down menu.
18. Debug
Run
58
TI-DIVISION
59
TI-DIVISION
Twiddle Factor
In the Definition of the DFT, there is a factor called the Twiddle Factor
where N = number of samples.
If we take an 8 bit sample sequence we can represent the twiddle factor as a vector in the unit
circle. e.g.
Note that
It is periodic. (i.e. it goes round and round the circle !!)
1. That the vectors are symmetric
2. The vectors are equally spaced around the circle.
Why the FFT?
If you look at the equation for the Discrete Fourier Transform you will see that it is quite
complicated to work out as it involves many additions and multiplications involving complex
60
TI-DIVISION
numbers. Even a simple eight sample signal would require 49 complex multiplications and 56
complex additions to work out the DFT. At this level it is still manageable, however a realistic
signal could have 1024 samples which requires over 20,000,000 complex multiplications and
additions. As you can see the number of calculations required soon mounts up to unmanageable
proportions.
The Fast Fourier Transform is a simply a method of laying out the computation, which is much
faster for large values of N, where N is the number of samples in the sequence. It is an ingenious
way of achieving rather than the DFT's clumsy P^2 timing.
The idea behind the FFT is the divide and conquer approach, to break up the original N point
sample into two (N / 2) sequences. This is because a series of smaller problems is easier to solve
than one large one. The DFT requires (N-1)^2 complex multiplications and N(N-1) complex
additions as opposed to the FFT's approach of breaking it down into a series of 2 point samples
which only require 1 multiplication and 2 additions and the recombination of the points which is
minimal.
For example Seismic Data contains hundreds of thousands of samples and would take months to
evaluate the DFT. Therefore we use the FFT.
FFT Algorithm
The FFT has a fairly easy algorithm to implement, and it is shown step by step in the list below.
Thjis version of the FFT is the Decimation in Time Method
1. Pad input sequence, of N samples, with ZERO's until the number of samples is the nearest
power of two.
e.g. 500 samples are padded to 512 (2^9)
2. Bit reverse the input sequence.
e.g. 3 = 011 goes to 110 = 6
3. Compute (N / 2) two sample DFT's from the shuffled inputs.
See "Shuffled Inputs"
4. Compute (N / 4) four sample DFT's from the two sample DFT's.
See "Shuffled Inputs"
5. Compute (N / 2) eight sample DFT's from the four sample DFT's.
See "Shuffled Inputs"
6. Until the all the samples combine into one N-sample DFT
61
TI-DIVISION
Shuffled Inputs
The process of decimating the signal in the time domain has caused the INPUT samples to be reordered. For an 8 point signal the original order of the samples is
0, 1, 2, 3, 4, 5, 6, 7
But after decimation the order is
0, 4, 2, 6, 1, 5, 3, 7
At first it may look as if there is no order to this new sequence, BUT if the numbers are
represented as binary a patter soon becomes apparent.
What has happened is that the bit patterns representing the sample number has been reversed. This
new sequence is the order that the samples enter the FFT.
ALGORITHM TO IMPLEMENT FFT:
Step 2 Generate a sine wave of frequency f (eg: 10 Hz with a sampling rate = No. of
Points of FFT(eg. 64)) using math library function.
62
TI-DIVISION
TI-DIVISION
fft.c:
#define PTS 64
//# of points for FFT
typedef struct {float real,imag;} COMPLEX;
extern COMPLEX w[PTS];
//twiddle constants stored in w
void FFT(COMPLEX *Y, int N) //input sample array, # of points
{
COMPLEX temp1,temp2;
//temporary storage variables
int i,j,k;
//loop counter variables
int upper_leg, lower_leg;
//index of upper/lower butterfly leg
int leg_diff;
//difference between upper/lower leg
int num_stages = 0;
//number of FFT stages (iterations)
int index, step;
//index/step through twiddle constant
i = 1;
//log(base2) of N points= # of stages
do
{
num_stages +=1;
i = i*2;
}while (i!=N);
leg_diff = N/2;
//difference between upper&lower legs
step = (PTS*2)/N; //step between values in twiddle.h
for (i = 0;i < num_stages; i++) //for N-point FFT
{
index = 0;
for (j = 0; j < leg_diff; j++)
{
for (upper_leg = j; upper_leg < N; upper_leg += (2*leg_diff))
{
lower_leg = upper_leg+leg_diff;
temp1.real = (Y[upper_leg]).real + (Y[lower_leg]).real;
temp1.imag = (Y[upper_leg]).imag + (Y[lower_leg]).imag;
temp2.real = (Y[upper_leg]).real - (Y[lower_leg]).real;
temp2.imag = (Y[upper_leg]).imag - (Y[lower_leg]).imag;
(Y[lower_leg]).real = temp2.real*(w[index]).real
-temp2.imag*(w[index]).imag;
(Y[lower_leg]).imag = temp2.real*(w[index]).imag
+temp2.imag*(w[index]).real;
(Y[upper_leg]).real = temp1.real;
(Y[upper_leg]).imag = temp1.imag;
}
index += step;
}
leg_diff = leg_diff/2;
step *= 2;
}
64
j = 0;
for (i = 1; i < (N-1); i++)
{
k = N/2;
while (k <= j)
{
j = j - k;
k = k/2;
}
j = j + k;
TI-DIVISION
if (i<j)
{
temp1.real = (Y[j]).real;
temp1.imag = (Y[j]).imag;
(Y[j]).real = (Y[i]).real;
(Y[j]).imag = (Y[i]).imag;
(Y[i]).real = temp1.real;
(Y[i]).imag = temp1.imag;
}
}
return;
}
HOW TO PROCEED
1. Open Code Composer Studio; make sure the DSP kit is turned on.
2. Start a new project using Project-new pull down menu, save it in a
separate directory(C:\CCstudio_v3.1\myprojects) with name FFT.pjt.
3. Add the source files FFT256.c and FFT.C in the project using
Project
add files to project pull down menu.
4. Add the linker command file hello.cmd
5. Add the rts file rts_EXT.lib
6. Compile the program using the Project-compile pull down menu or by
clicking the shortcut icon on the left side of program window.
7. Project
Build
8. Load the program in program memory of DSP chip using the File-load program pull
down menu.
9. Run the program and observe output using graph utility.
65
TI-DIVISION
Input:
Output:
66
TI-DIVISION
POWER SPECTRUM
Description:The total or the average power in a signal is often not of as great an interest. We are most often
interested in the PSD or the Power Spectrum. We often want to see is how the input power has
been redistributed by the channel and in this frequency-based redistribution of power is where
most of the interesting information lies. The total area under the Power Spectrum or PSD is equal
to the total avg. power of the signal. The PSD is an even function of frequency or in other words
To compute PSD:
The value of the auto-correlation function at zero-time equals the total power in the signal. To
compute PSD We compute the auto-correlation of the signal and then take its FFT. The autocorrelation function and PSD are a Fourier transform pair. (Another estimation method called
period gram uses sampled FFT to compute the PSD.)
E.g.: For a process x(n) correlation is defined as:
R ( ) = E { x ( n ) x ( n + ) }
= lim
1
N
x(n ) x (n + )
n =1
S ( ) = F T ( R ( )) = lim
R ( ) = F T
( S ( )) =
R ( ) e j
= N +1
1
2
S ( ) e
Step 2 Generate a sine wave of frequency f (eg: 10 Hz with a sampling rate = No. of
Points of FFT (eg. 64)) using math library function.
TI-DIVISION
#include <math.h>
#define PTS 128
#define PI 3.14159265358979
TI-DIVISION
//imag components = 0
//call function FFT.c
//end of main
69
TI-DIVISION
FFT.c:
#define PTS 128
TI-DIVISION
step *= 2;
}
j = 0;
for (i = 1; i < (N-1); i++)
//bit reversal for resequencing data
{
k = N/2;
while (k <= j)
{
j = j - k;
k = k/2;
}
j = j + k;
if (i<j)
{
temp1.real = (Y[j]).real;
temp1.imag = (Y[j]).imag;
(Y[j]).real = (Y[i]).real;
(Y[j]).imag = (Y[i]).imag;
(Y[i]).real = temp1.real;
(Y[i]).imag = temp1.imag;
}
}
return;
}
HOW TO PROCEED
1. Open Code Composer Studio, make sure the DSP kit is turned on.
2. Start a new project using Project-new pull down menu, save it in a
separate directory(c:\ti\myprojects) with name PSD.pjt.
3. Add the source files PSD.c and FFT.c in the project using
Projectadd files to project pull down menu.
4. Add the linker command file hello.cmd .
5. Add the rts file rts_EXT.lib
6. Compile the program using the Project-compile pull down menu or by
clicking the shortcut icon on the left side of program window.
7. Load the program in program memory of DSP chip using the File-load program pull
down menu.
8. Run the program and observe output using graph utility.
71
TI-DIVISION
INPUT:
OUTPUT
72
TI-DIVISION
73