65
TMS320C6713 DSK USER MANUAL Cranes Software International Limited (TI-Division) #5, Airport Road, Domlur Layout, Bangalore – 560 071. Phone: 91-80-25352636/37/25353038/4532/25354496 Fax : 25356299 [email protected]

Cranes Dsp1 User Manual 6713

Embed Size (px)

Citation preview

Page 1: Cranes Dsp1 User Manual 6713

TMS320C6713 DSK

USER MANUAL

Cranes Software International Limited (TI-Division)

#5, Airport Road, Domlur Layout, Bangalore – 560 071. Phone: 91-80-25352636/37/25353038/4532/25354496 Fax : 25356299

[email protected]

Page 2: Cranes Dsp1 User Manual 6713

Cranes Software Int. Ltd. TI-DIVISION

2

Copyright © 2008 Cranes Software International Limited. All rights reserved.

Cranes Software believes the information in this publication is accurate as of

its publication date. The information is subject to change without notice. THE

INFORMATION IN THIS PUBLICATION IS PROVIDED "AS IS." CRANES SOFTWARE MAKES NO

REPRESENTATIONS OR WARRANTIES OF ANY KIND WITH RESPECT TO THE INFORMATION IN

THIS PUBLICATION, AND SPECIFICALLY DISCLAIMS IMPLIED WARRANTIES OF

MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.

Use, copying, and distribution of any part in this publication requires an

applicable

Software license.

Page 3: Cranes Dsp1 User Manual 6713

Cranes Software Int. Ltd. TI-DIVISION

3

TABLE OF CONTENTS

1. INSTALLATION PROCEDURE………………………………………. 4

2. DSK FEAUTURES……………………………………….……………… 8

3. INTRODUCTON TO CODE COMPOSER STUDIO…………………13

4. EXPERIMENTS USING DSK

a. LINEAR CONVOLUTION OF TWO GIVEN SEQUENCES

b. CIRCULAR CONVOLUTION OF TWO GIVEN SEQUENCES

c. COMPPUTATAION OF N- POINT DFT OF A GIVEN SEQUANCE

d. REALIZATION OF FIR FILTER IN REALTIME.

e. AUDIO APPLICATION

a. PLOT A SPECTROGRAM

f. NOISE REMOVAL USING ADAPTIVE FILTERS.

g. IMPLUSE RESPONSE

h. MINI PROJECT

Page 4: Cranes Dsp1 User Manual 6713

Cranes Software Int. Ltd. TI-DIVISION

4

INSTALLATION PROCEDURE

SYSTEM REQUIREMENTS

Minimum

Recommended • 233MHz or Higher Pentium-

Compatible CPU

• 600MB of free hard disk space

• 128MB of RAM or more

• SVGA (800 x 600 ) display

• Internet Explorer (4.0 or later) or

• Netscape Navigator (4.7 or later)

• Local CD-ROM drive

• 500MHz or Higher Pentium –

Compatible CPU

• 128MB RAM

• 16bit Color

Supported Operating Systems • Windows NT® 4.0 Service Pack 4 or higher

• Windows® 2000 Service Pack 1

• Windows® Me

• Windows® XP

DSK HARDWARE INSTALLATION

• Shut down and power off the PC

• Connect the supplied USB port cable to the board

• Connect the other end of the cable to the USB port of PC

Note: If you plan to install a Microphone, speaker, or

Signal generator/CRO these must be plugged in properly

before you connect power to the DSK

• Plug the power cable into the board

• Plug the other end of the power cable into a power outlet

• The user LEDs should flash several times to indicate board is operational

• When you connect your DSK through USB for the first time on a Windows loaded PC the

new hardware found wizard will come up. So, Install the drivers (The CCS CD contains

the require drivers for C6713 DSK).

• Install the CCS software for C6713 DSK.

Page 5: Cranes Dsp1 User Manual 6713

Cranes Software Int. Ltd. TI-DIVISION

5

DSK SOFTWARE INSTALLATION

You must install the hardware before you install the software on your system.

The requirements for the operating platform are;

• Insert the installation CD into the CD-ROM drive

An install screen appears like below; if not, goes to the windows Explorer

and run setup.exe

Page 6: Cranes Dsp1 User Manual 6713

Cranes Software Int. Ltd. TI-DIVISION

6

• Choose the option to install Code Composer Studio

If you already have C6000 CC Studio IDE installed on your PC,

do not install DSK software. CC Studio IDE full tools supports

the DSK platform

• Respond to the dialog boxes as the installation program runs.

• The Installation program automatically configures CC Studio IDE for operation with your

DSK and creates a “6713 DSK CCStudio_v3.1” IDE DSK icon on your desktop.

DIAGNOSTIC:-

• Test the USB port by running DSK Port test from the start menu

Use Start�Programs�Texas Instruments�Code Composer Studio�Code Composer Studio

C6713 DSK Tools�C6713 DSK Diagnostic Utilities

Page 7: Cranes Dsp1 User Manual 6713

Cranes Software Int. Ltd. TI-DIVISION

7

(Available on desktop)

• Select� Start�Select 6713 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

If the board still fails to detect

Page 8: Cranes Dsp1 User Manual 6713

Cranes Software Int. Ltd. TI-DIVISION

8

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 on-

board 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 TMS320C6713 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).

Page 9: Cranes Dsp1 User Manual 6713

Cranes Software Int. Ltd. TI-DIVISION

9

TMS320C6713 DSK BOARD FEATURES

Package Contents

The C6713™ DSK builds on TI's industry-leading line of low cost, easy-to-use DSP Starter Kit

(DSK) development boards. The high-performance board features the TMS320C6713 floating-

point DSP. Capable of performing 1350 million floating-point operations per second (MFLOPS),

the C6713 DSP makes the C6713 DSK the most powerful DSK development board.

The DSK is USB port interfaced platform that allows to efficiently develop and test applications

for the C6713. The DSK consists of a C6713-based printed circuit board that will serve as a

hardware reference design for TI’s customers’ products. With extensive host PC and target DSP

software support, including bundled TI tools, the DSK provides ease-of-use and capabilities that

are attractive to DSP engineers.

The following checklist details items that are shipped with the C6713 DSK.

� TMS320C6713 DSK TMS320C6713 DSK development board

� Other hardware External 5VDC power supply

IEEE 1284 compliant male-to-female cable

� CD-ROM Code Composer Studio DSK tools

� Technical reference manual

Page 10: Cranes Dsp1 User Manual 6713

Cranes Software Int. Ltd. TI-DIVISION

10

The C6713 DSK has a TMS320C6713 DSP onboard that allows full-speed verification of code

with Code Composer Studio. The C6713 DSK provides:

� A USB Interface � SDRAM and Flash ROM � An analog interface circuit for Data conversion (AIC) � An I/O port � Embedded JTAG emulation support

Connectors on the C6713 DSK provide DSP external memory interface (EMIF) and peripheral

signals that enable its functionality to be expanded with custom or third party daughter boards.

The DSK provides a C6713 hardware reference design that can assist you in the development of

your own C6713-based products. In addition to providing a reference for interfacing the DSP to

various types of memories and peripherals, the design also addresses power, clock, JTAG, and

parallel peripheral interfaces.

The C6713 DSK includes a stereo codec. This analog interface circuit (AIC) has the following

characteristics:

High-Performance Stereo Codec

• 90-dB SNR Multibit Sigma-Delta ADC (A-weighted at 48 kHz)

• 100-dB SNR Multibit Sigma-Delta DAC (A-weighted at 48 kHz)

• 1.42 V – 3.6 V Core Digital Supply: Compatible With TI C54x DSP Core Voltages

• 2.7 V – 3.6 V Buffer and Analog Supply: Compatible Both TI C54x DSP Buffer

Voltages

• 8-kHz – 96-kHz Sampling-Frequency Support

Software Control Via TI McBSP-Compatible Multiprotocol Serial Port

• I 2 C-Compatible and SPI-Compatible Serial-Port Protocols

• Glueless Interface to TI McBSPs

Audio-Data Input/Output Via TI McBSP-Compatible Programmable Audio Interface

• I 2 S-Compatible Interface Requiring Only One McBSP for both ADC and DAC

• Standard I 2 S, MSB, or LSB Justified-Data Transfers

• 16/20/24/32-Bit Word Lengths

The TMS320C6713™ DSP compose the floating-point DSP generation in the TMS320C6000™

DSP platform. The C6713 device is based on the high-performance, advanced very-long-

instruction-word (VLIW) architecture developed by Texas Instruments (TI), making this DSP an

excellent choice for multichannel and multifunction applications. The 6713 DSK is a low-cost

standalone development platform that enables customers to evaluate and develop applications for

the TI C67XX DSP family. The DSK also serves as a hardware reference design for the

TMS320C6713 DSP. Schematics, logic equations and application notes are available to ease

hardware development and reduce time to market.

Page 11: Cranes Dsp1 User Manual 6713

Cranes Software Int. Ltd. TI-DIVISION

11

Operating at 225 MHz, the C6713 delivers up to 1350 million floating-point operations per second

(MFLOPS), 1800 million instructions per second (MIPS), and with dual fixed-/floating-point

multipliers up to 450 million multiply-accumulate operations per second (MMACS).The DSK uses

the 32-bit EMIF for the SDRAM (CE0) and daughter card expansion interface (CE2 and CE3).

The Flash is attached to CE1 of the EMIF in 8-bit mode.

An on-board AIC23 codec allows the DSP to transmit and receive analog signals. McBSP0 is used

for the codec control interface and McBSP1 is used for data. Analog audio I/O is done through

four 3.5mm audio jacks that correspond to microphone input, line input, line output and headphone

output. The codec can select the microphone or the line input as the active input. The analog

output is driven to both the line out (fixed gain) and headphone (adjustable gain) connectors.

McBSP1 can be re-routed to the expansion connectors in software.

A programmable logic device called a CPLD is used to implement glue logic that ties the board

components together. The CPLD has a register based user interface that lets the user configure the

board by reading and writing to the CPLD registers. The registers reside at the midpoint of CE1.

The DSK includes 4 LEDs and 4 DIP switches as a simple way to provide the user with interactive

feedback. Both are accessed by reading and writing to the CPLD registers.

An included 5V external power supply is used to power the board. On-board voltage regulators

provide the 1.26V DSP core voltage, 3.3V digital and 3.3V analog voltages. A voltage supervisor

monitors the internally generated voltage, and will hold the boards in reset until the supplies are

within operating specifications and the reset button is released. If desired, JP1 and JP2 can be used

as power test points for the core and I/O power supplies.

Code Composer communicates with the DSK through an embedded JTAG emulator with a USB

host interface. The DSK can also be used with an external emulator through the external JTAG

connector.

TMS320C6713 DSP Features

� Highest-Performance Floating-Point Digital Signal Processor (DSP):

� Eight 32-Bit Instructions/Cycle

� 32/64-Bit Data Word

� 300-, 225-, 200-MHz (GDP), and 225-, 200-, 167-MHz (PYP) Clock Rates

� 3.3-, 4.4-, 5-, 6-Instruction Cycle Times

� 2400/1800, 1800/1350, 1600/1200, and 1336/1000 MIPS /MFLOPS

� Rich Peripheral Set, Optimized for Audio

� Highly Optimized C/C++ Compiler

� Extended Temperature Devices Available

� Advanced Very Long Instruction Word (VLIW) TMS320C67x™ DSP Core

� Eight Independent Functional Units:

� Two ALUs (Fixed-Point)

� Four ALUs (Floating- and Fixed-Point)

� Two Multipliers (Floating- and Fixed-Point)

� Load-Store Architecture With 32 32-Bit General-Purpose Registers

Page 12: Cranes Dsp1 User Manual 6713

Cranes Software Int. Ltd. TI-DIVISION

12

� Instruction Packing Reduces Code Size

� All Instructions Conditional

� Instruction Set Features

� Native Instructions for IEEE 754

� Single- and Double-Precision

� Byte-Addressable (8-, 16-, 32-Bit Data)

� 8-Bit Overflow Protection

� Saturation; Bit-Field Extract, Set, Clear; Bit-Counting; Normalization

� L1/L2 Memory Architecture

� 4K-Byte L1P Program Cache (Direct-Mapped)

� 4K-Byte L1D Data Cache (2-Way)

� 256K-Byte L2 Memory Total: 64K-Byte L2 Unified Cache/Mapped RAM, and 192K-Byte

Additional L2 Mapped RAM

� Device Configuration

� Boot Mode: HPI, 8-, 16-, 32-Bit ROM Boot

� Endianness: Little Endian/Big Endian

� 32-Bit External Memory Interface (EMIF)

� Glueless Interface to SRAM, EPROM, Flash, SBSRAM, and SDRAM

� 512M-Byte Total Addressable External Memory Space

� Enhanced Direct-Memory-Access (EDMA) Controller (16 Independent Channels)

� 16-Bit Host-Port Interface (HPI)

� Two Multichannel Buffered Serial Ports (McBSPs)

� Two Independent Clock Zones Each (1 TX and 1 RX)

� Eight Serial Data Pins Per Port:

Individually Assignable to any of the Clock Zones

� Each Clock Zone Includes:

� Programmable Clock Generator

� Programmable Frame Sync Generator

� TDM Streams From 2-32 Time Slots

� Support for Slot Size:

8, 12, 16, 20, 24, 28, 32 Bits

� Data Formatter for Bit Manipulation

� Wide Variety of I2S and Similar Bit Stream Formats

� Integrated Digital Audio Interface Transmitter (DIT) Supports:

� S/PDIF, IEC60958-1, AES-3, CP-430 Formats

� Up to 16 transmit pins

� Enhanced Channel Status/User Data

� Extensive Error Checking and Recovery

� Two Inter-Integrated Circuit Bus (I2C Bus™) Multi-Master and Slave Interfaces

� Two 32-Bit General-Purpose Timers

� Dedicated GPIO Module With 16 pins (External Interrupt Capable)

� Flexible Phase-Locked-Loop (PLL) Based Clock Generator Module

� IEEE-1149.1 (JTAG ) Boundary-Scan-Compatible

� Package Options:

Page 13: Cranes Dsp1 User Manual 6713

Cranes Software Int. Ltd. TI-DIVISION

13

� 208-Pin Power PAD™ Plastic (Low-Profile) Quad Flat pack (PYP)

� 272-BGA Packages (GDP and ZDP)

� 0.13-µm/6-Level Copper Metal Process

� CMOS Technology

� 3.3-V I/Os, 1.2 -V Internal (GDP & PYP)

� 3.3-V I/Os, 1.4-V Internal (GDP)(300 MHz only)

TMS320C6713 DSK Overview Block Diagram

Page 14: Cranes Dsp1 User Manual 6713

Cranes Software Int. Ltd. TI-DIVISION

14

INTRODUCTION TO CODE COMPOSER STUDIO

Code Composer is the DSP industry's first fully integrated development environment (IDE) with

DSP-specific functionality. With a familiar environment liked MS-based C++TM, Code Composer

lets you edit, build, debug, profile and manage projects from a single unified environment. Other

unique features include graphical signal analysis, injection/extraction of data signals via file I/O,

multi-processor debugging, automated testing and customization via a C-interpretive scripting

language and much more.

CODE COMPOSER FEATURES INCLUDE:

• 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\c6713dsk.hlp

Documents for Reference:

spru509 ���� Code Composer Studio getting started guide.

spru189 ���� TMS320C6000 CPU & Instruction set guide

spru190 ���� TMS320C6000 Peripherals guide

slws106d ����Codec(TLV320AIC23) Data Manual.

spru402 ���� Programmer’s Reference Guide.

sprs186j ���� TMS320C6713 DSP

Soft Copy of datasheets are available at : C:\CCStudio_v3.1\docs\pdf.

Page 15: Cranes Dsp1 User Manual 6713

Cranes Software Int. Ltd. TI-DIVISION

15

Starting Code Composer To start Code Composer Studio, double click the 6713 DSK CCStudio_v3.1 icon on your desktop.

Start Code Composer Studio (ignore this if CCS is already running) by double-clicking on the

C6713 DSK icon on your desktop.

Use the Debug ���� Connect menu option to open a debug connection to the DSK board

Page 16: Cranes Dsp1 User Manual 6713

Cranes Software Int. Ltd. TI-DIVISION

16

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[ ]= Input signal Samples

h[ ]= Impulse response co-efficient.

y[ ]= Convolution output.

n = No. of Input samples

h = No. of Impulse response co-efficient.

Algorithm to implement ‘C’ or Assembly program for Convolution:

Eg: x[n] = {1, 2, 3, 4}

h[k] = {1, 2, 3, 4}

Where: n=4, k=4. ;Values of n & k should be a multiple of 4.

If n & k are not multiples of 4, pad with zero’s to make

multiples of 4

r= n+k-1 ; Size of output sequence.

= 4+4-1

= 7.

r= 0 1 2 3 4 5 6

n= 0 x[0]h[0] x[0]h[1] x[0]h[2] x[0]h[3]

1 x[1]h[0] x[1]h[1] x[1]h[2] x[1]h[3]

2 x[2]h[0] x[2]h[1] x[2]h[2] x[2]h[3]

3 x[3]h[0] x[3]h[1] x[3]h[2] x[3]h[3]

Output: y[r] = { 1, 4, 10, 20, 25, 24, 16}.

NOTE: At the end of input sequences pad ‘n’ and ‘k’ no. of zero’s

C PROGRAM TO IMPLEMENT LINEAR CONVOLUTION

Page 17: Cranes Dsp1 User Manual 6713

Cranes Software Int. Ltd. TI-DIVISION

17

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 ‘Project�add files to project’ pull down menu. � Add the linker command file hello.cmd .

(Path: C:\CCStudio_v3.1\tutorial\dsk6713\hello1\hello.cmd)

� Add the run time support library file rts6700.lib (Path: C:\CCStudio_v3.1\c6000\cgtools\lib\rts6700.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.

� To View output graphically

Page 18: Cranes Dsp1 User Manual 6713

Cranes Software Int. Ltd. TI-DIVISION

18

Select view ���� graph ���� time and frequency.

Configure the graphical window as shown below

Page 19: Cranes Dsp1 User Manual 6713

Cranes Software Int. Ltd. TI-DIVISION

19

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]

Subfigure 1.1 Subfigure 1.2

Step 2: "Spin" h[−m] n times Anti Clock Wise (counter-clockwise) to get h[n-m]

(i.e. Simply rotate the sequence, h[n], clockwise by n steps)

Figure 2: Step 2

Step 3: Point wise multiply the f[m] wheel and the h[n−m] wheel. Sum=y[n]

Step 4: Repeat for all 0≤n≤N−1

Example 1: Convolve (n = 4)

Subfigure 3.1 Subfigure 3.2

Figure 3: Two discrete-time signals to be convolved.

• h[−m] =

Page 20: Cranes Dsp1 User Manual 6713

Cranes Software Int. Ltd. TI-DIVISION

20

Figure 4

Multiply f[m] and sum to yield: y[0] =3

• h[1−m]

Figure 5

Multiply f[m] and sum to yield: y[1] =5

• h[2−m]

Figure 6

Multiply f[m] and sum to yield: y[2] =3

• h[3−m]

Figure 7

Multiply f[m] and sum to yield: y[3] =1

C Program to Implement Circular Convolution

#include<stdio.h>

#include<math.h>

int m,n,x[30],h[30],y[30],i,j,temp[30],k,x2[30],a[30];

void main()

{

printf(" enter the length of the first sequence\n");

scanf("%d",&m);

printf(" enter the length of the second sequence\n");

Page 21: Cranes Dsp1 User Manual 6713

Cranes Software Int. Ltd. TI-DIVISION

21

scanf("%d",&n);

printf(" enter the first sequence\n");

for(i=0;i<m;i++)

scanf("%d",&x[i]);

printf(" enter the second sequence\n");

for(j=0;j<n;j++)

scanf("%d",&h[j]);

if(m-n!=0) /*If length of both sequences are not equal*/

{

if(m>n) /* Pad the smaller sequence with zero*/

{

for(i=n;i<m;i++)

h[i]=0;

n=m;

}

for(i=m;i<n;i++)

x[i]=0;

m=n;

}

y[0]=0;

a[0]=h[0];

for(j=1;j<n;j++) /*folding h(n) to h(-n)*/

a[j]=h[n-j];

/*Circular convolution*/

for(i=0;i<n;i++)

y[0]+=x[i]*a[i];

for(k=1;k<n;k++)

{

y[k]=0;

/*circular shift*/

for(j=1;j<n;j++)

x2[j]=a[j-1];

x2[0]=a[n-1];

for(i=0;i<n;i++)

{

a[i]=x2[i];

y[k]+=x[i]*x2[i];

}

}

/*displaying the result*/

printf(" the circular convolution is\n");

for(i=0;i<n;i++)

printf("%d \t",y[i]);

}

IN PUT:

Eg: x[4]={1, 2, 3,4}

Page 22: Cranes Dsp1 User Manual 6713

Cranes Software Int. Ltd. TI-DIVISION

22

h[4]={1, 2, 3,4}

OUT PUT 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 ‘Project�add files to project’ pull down menu. � Add the linker command file hello.cmd.

(Path: C:\CCStudio_v3.1\tutorial\dsk6713\hello1\hello.cmd)

� Add the run time support library file rts6700.lib (Path: C:\CCStudio_v3.1\c6000\cgtools\lib\rts6700.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.

Page 23: Cranes Dsp1 User Manual 6713

Cranes Software Int. Ltd. TI-DIVISION

23

DFT Introduction:

In mathematics, the discrete Fourier transform (DFT) is one of the specific forms of Fourier

analysis. As such, it transforms one function into another, which is called the frequency domain

representation, or simply the DFT, of the original function (which is often a function in the time

domain). But the DFT requires an input function that is discrete and whose non-zero values have a

limited (finite) duration. Such inputs are often created by sampling a continuous function, like a

person's voice. And unlike the discrete-time Fourier transform (DTFT), it only evaluates enough

frequency components to reconstruct the finite segment that was analyzed. Its inverse transform

cannot reproduce the entire time domain, unless the input happens to be periodic (forever).

Therefore it is often said that the DFT is a transform for Fourier analysis of finite-domain discrete-

time functions. The sinusoidal basis functions of the decomposition have the same properties.

C program for DFT

#include <stdio.h>

#include <math.h>

short x[8];

void dft(short *x, short k, int *out); //function prototype

#define N 8 //number of data values

float pi = 3.1416;

int sumRe,sumIm;

short x[N] = {1,2,3,4,5,6,7,8}; //1-cycle cosine

//short x[N]={0,602,974,974,602,0,-602,-974,-974,-602,

// 0,602,974,974,602,0,-602,-974,-974,-602};//2-cycles sine

int out[2] = {0,0};

int real[8],imag[8],k=0; //init Re and Im results

void dft(short *x, short k, int *out) //DFT function

{

int sumRe = 0, sumIm = 0; //init real/imag components

float cs = 0, sn = 0; //init cosine/sine components

int i = 0;

for (i = 0; i < N; i++) //for N-point DFT

{

cs = cos(2*pi*(k)*i/N); //real component

sn = sin(2*pi*(k)*i/N); //imaginary component

sumRe = sumRe + x[i]*cs; //sum of real components

sumIm = sumIm - x[i]*sn; //sum of imaginary components

}

out[0] = sumRe; //sum of real components

out[1] = sumIm;

real[k]= sumRe;

imag[k]= sumIm;

k++;

if(k>N)k=0;

Page 24: Cranes Dsp1 User Manual 6713

Cranes Software Int. Ltd. TI-DIVISION

24

//printf("\n%d",sumRe);

//printf("\n%d",sumIm);

printf("\n%d",out[0]);

// printf("\n%d",out[1]); //sum of imaginary components

}

void main()

{

int j;

for (j = 0; j < N; j++)

{

dft(x,j,out); //call DFT function

}

}

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 dft.pjt.

� Add the source files dft.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\dsk6713\hello1\hello.cmd)

� Add the run time support library file rts6700.lib (Path: C:\CCStudio_v3.1\c6000\cgtools\lib\rts6700.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(dft.out) in program memory of DSP chip using the ‘File-load program’ pull down menu.

Page 25: Cranes Dsp1 User Manual 6713

Cranes Software Int. Ltd. TI-DIVISION

25

Procedure for Real time Programs :

1. Connect a Signal Generator/audio input to the LINE IN Socket or connect a microphone to the

MIC IN Socket.

Note:- To use microphone input change the analog audio path control register value

(Register no. 4) in Codec Configuration settings of the Source file (Codec.c) from 0x0011

to 0x0015.

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

5. Create a new project with name codec.pjt.

6. Open the File Menu � new � DSP/BIOS Configuration ����select

Page 26: Cranes Dsp1 User Manual 6713

Cranes Software Int. Ltd. TI-DIVISION

26

“dsk6713.cdb” and save it as “xyz.cdb”

7. Add “xyz.cdb” to the current project. Project���� Add files to project ����xyz.cdb

8. Automatically three files are added in the Generated file folder in project pane

xyzcfg.cmd� Command and linking file

xyzcfg.s62 � optimized assembly code for configuration

xyzcfg_c.c � Chip support initialization

9. Open the File Menu � new � Source file

10. 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.

11. 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

12. Add the library file “dsk6713bsl.lib” to the current project Path � “C:\CCStudio_v3.1\C6000\dsk6713\lib\dsk6713bsl.lib”

Files of type � Object and library files (*.o*, *.l*)

Page 27: Cranes Dsp1 User Manual 6713

Cranes Software Int. Ltd. TI-DIVISION

27

13. Copy header files “dsk6713.h” and “dsk6713_aic23.h” from and paste it in current project folder.

C:\CCStudio_v3.1\C6000\dsk6713\include.

14. Add the header file generated within xyzcfg_c.c to codec.c

Note:- Double click on xyzcfg_c.c. Copy the first line header (eg.#include “xyzcfg.h”) and

paste that in source file (eg.codec.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

19. You can notice the input signal of 500 Hz. appearing on the CRO verifying the codec configuration.

20. You can also pass an audio input and hear the output signal through the speakers. 21. You can also vary the sampling frequency using the DSK6713_AIC23_setFreq Function in

the “codec.c” file and repeat the above steps.

5.0 Conclusion:

The codec TLV320AIC23 successfully configured using the board support library

and verified.

Page 28: Cranes Dsp1 User Manual 6713

Cranes Software Int. Ltd. TI-DIVISION

28

Finite Impulse Response Filter(FIR)

DESIGNING AN FIR FILTER :

Following are the steps to design linear phase FIR filters Using Windowing Method.

I. Clearly specify the filter specifications.

Eg: Order = 30;

Sampling Rate = 8000 samples/sec

Cut off Freq. = 400 Hz.

II. Compute the cut-off frequency Wc

Eg: Wc = 2*pie* fc / Fs

= 2*pie* 400/8000

= 0.1*pie

III. Compute the desired Impulse Response h d (n) using particular Window

Eg: b_rect1=fir1 (order, Wc , 'high',boxcar(31));

IV. Convolve input sequence with truncated Impulse Response x (n)*h (n)

USING MATLAB TO DETERMINE FILTER COEFFICIENTS:

Using FIR1 Function on Matlab

B = FIR1(N,Wn) designs an N'th order lowpass FIR digital filter

and returns the filter coefficients in length N+1 vector B.

The cut-off frequency Wn must be between 0 < Wn < 1.0, with 1.0

corresponding to half the sample rate. The filter B is real and

has linear phase, i.e., even symmetric coefficients obeying B(k) =

B(N+2-k), k = 1,2,...,N+1.

If Wn is a two-element vector, Wn = [W1 W2], FIR1 returns an

order N bandpass filter with passband W1 < W < W2.

B = FIR1(N,Wn,'high') designs a highpass filter.

B = FIR1(N,Wn,'stop') is a bandstop filter if Wn = [W1 W2].

If Wn is a multi-element vector,

Wn = [W1 W2 W3 W4 W5 ... WN],

FIR1 returns an order N multiband filter with bands

0 < W < W1, W1 < W < W2, ..., WN < W < 1.

B = FIR1(N,Wn,'DC-1') makes the first band a passband.

B = FIR1(N,Wn,'DC-0') makes the first band a stopband.

For filters with a passband near Fs/2, e.g., highpass and bandstop filters, N must be even.

By default FIR1 uses a Hamming window. Other available windows, including Boxcar,

Hanning, Bartlett, Blackman, Kaiser and Chebwin can be specified with an optional trailing

argument. For example,

Page 29: Cranes Dsp1 User Manual 6713

Cranes Software Int. Ltd. TI-DIVISION

29

B = FIR1(N,Wn,kaiser(N+1,4)) uses a Kaiser window with beta=4.

B = FIR1(N,Wn,'high',chebwin(N+1,R)) uses a Chebyshev window.

By default, the filter is scaled so the center of the first pass band has magnitude exactly one after

windowing. Use a trailing 'noscale' argument to prevent this scaling,

e.g. B = FIR1(N,Wn,'noscale'),

B = FIR1(N,Wn,'high','noscale'), B = FIR1(N,Wn,wind,'noscale').

Matlab Program to generate ‘FIR Filter-Low Pass’ Coefficients using FIR1

% FIR Low pass filters using rectangular, triangular and kaiser windows

% sampling rate – 8000

order = 50;

cf=[500/4000,1000/4000,1500/4000]; cf--> contains set of cut-off frequencies[Wc ]

% cutoff frequency – 500

b_rect1=fir1(order,cf(1),boxcar(51)); %Rectangular

b_tri1=fir1(order,cf(1),bartlett(51)); %Triangular

b_kai1=fir1(order,cf(1),kaiser(51,8)); %Kaisar [Where 8-->Beta Co-efficient]

% cutoff frequency - 1000

b_rect2=fir1(order,cf(2),boxcar(51));

b_tri2=fir1(order,cf(2),bartlett(51));

b_kai2=fir1(order,cf(2),kaiser(31,8));

% cutoff frequency - 1500

b_rect3=fir1(order,cf(3),boxcar(51));

b_tri3=fir1(order,cf(3),bartlett(51));

b_kai3=fir1(order,cf(3),kaiser(51,8));

fid=fopen('FIR_lowpass_rectangular.txt','wt');

fprintf(fid,'\t\t\t\t\t\t%s\n','Cutoff -400Hz');

fprintf(fid,'\nfloat b_rect1[31]={');

fprintf(fid,'%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,\n',b_rect1);

fseek(fid,-1,0);

fprintf(fid,'};');

fprintf(fid,'\n\n\n\n');

fprintf(fid,'\t\t\t\t\t\t%s\n','Cutoff -800Hz');

fprintf(fid,'\nfloat b_rect2[31]={');

fprintf(fid,'%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,\n',b_rect2);

fseek(fid,-1,0);

fprintf(fid,'};');

fprintf(fid,'\n\n\n\n');

fprintf(fid,'\t\t\t\t\t\t%s\n','Cutoff -1200Hz');

fprintf(fid,'\nfloat b_rect3[31]={');

fprintf(fid,'%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,\n',b_rect3);

fseek(fid,-1,0);

fprintf(fid,'};');

Page 30: Cranes Dsp1 User Manual 6713

Cranes Software Int. Ltd. TI-DIVISION

30

fclose(fid);

winopen('FIR_highpass_rectangular.txt');

T.1 : Matlab generated Coefficients for FIR Low Pass Kaiser filter:

IMPLEMENTATION OF AN FIR FILTER :

ALGORITHM TO IMPLEMENT :

We need to realize an advance FIR filter by implementing its difference equation as per the

specifications. A direct form I implementation approach is taken. (The filter coefficients are taken

as ai as generated by the Matlab program.)

T.2 :Matlab generated Coefficients for FIR Low Pass Rectangular filter

T.3 : Matlab generated Coefficients for FIR Low Pass Triangular 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 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,-

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,-

0.0001,-0,0};

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};

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,-

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};

Page 31: Cranes Dsp1 User Manual 6713

Cranes Software Int. Ltd. TI-DIVISION

31

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};

Page 32: Cranes Dsp1 User Manual 6713

Cranes Software Int. Ltd. TI-DIVISION

32

FLOWCHART FOR FIR:

No

Yes

Initialize Counter = 0

Initialize Output = 0 , i = 0

Output += coeff[N-i]*val[i]

Shift the input value by one

Initialize the DSP Board.

Take a new input in ‘data’

from the analog in of codec in

‘data’

Is the loop

Cnt = order

Output += coeff[0]*data

Put the ‘data’ in ‘val’ array.

Write the value ‘Output’ to

Analog output of the codec

Poll the ready bit, when

asserted proceed.

Start

Page 33: Cranes Dsp1 User Manual 6713

Cranes Software Int. Ltd. TI-DIVISION

33

C PROGRAM TO IMPLEMENT FIR FILTER:

fir.c

#include "xyzcfg.h"

#include "dsk6713.h"

#include "dsk6713_aic23.h"

float filter_Coeff[] ={0.000000,-0.001591,-0.002423,0.000000,0.005728,

0.011139,0.010502,-0.000000,-0.018003,-0.033416,-0.031505,0.000000,

0.063010,0.144802,0.220534,0.262448,0.220534,0.144802,0.063010,0.000000,

-0.031505,-0.033416,-0.018003,-0.000000,0.010502,0.011139,0.005728,

0.000000,-0.002423,-0.001591,0.000000 };

static short in_buffer[100];

DSK6713_AIC23_Config config = {\

0x0017, /* 0 DSK6713_AIC23_LEFTINVOL Leftline input channel volume */\

0x0017, /* 1 DSK6713_AIC23_RIGHTINVOL Right line input channel volume*/\

0x00d8, /* 2 DSK6713_AIC23_LEFTHPVOL Left channel headphone volume */\

0x00d8, /* 3 DSK6713_AIC23_RIGHTHPVOL Right channel headphone volume */\

0x0011, /* 4 DSK6713_AIC23_ANAPATH Analog audio path control */\

0x0000, /* 5 DSK6713_AIC23_DIGPATH Digital audio path control */\

0x0000, /* 6 DSK6713_AIC23_POWERDOWN Power down control */\

0x0043, /* 7 DSK6713_AIC23_DIGIF Digital audio interface format */\

0x0081, /* 8 DSK6713_AIC23_SAMPLERATE Sample rate control */\

0x0001 /* 9 DSK6713_AIC23_DIGACT Digital interface activation */ \

};

/*

* main() - Main code routine, initializes BSL and generates tone

*/

void main()

{

DSK6713_AIC23_CodecHandle hCodec;

Uint32 l_input, r_input,l_output, r_output;

/* Initialize the board support library, must be called first */

DSK6713_init();

/* Start the codec */

hCodec = DSK6713_AIC23_openCodec(0, &config);

DSK6713_AIC23_setFreq(hCodec, 1);

Page 34: Cranes Dsp1 User Manual 6713

Cranes Software Int. Ltd. TI-DIVISION

34

while(1)

{ /* Read a sample to the left channel */

while (!DSK6713_AIC23_read(hCodec, &l_input));

/* Read a sample to the right channel */

while (!DSK6713_AIC23_read(hCodec, &r_input));

l_output=(Int16)FIR_FILTER(&filter_Coeff ,l_input);

r_output=l_output;

/* Send a sample to the left channel */

while (!DSK6713_AIC23_write(hCodec, l_output));

/* Send a sample to the right channel */

while (!DSK6713_AIC23_write(hCodec, r_output));

}

/* Close the codec */

DSK6713_AIC23_closeCodec(hCodec);

}

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 :

1. Connect a Signal Generator/audio input to the LINE IN Socket or connect a microphone to

the MIC IN Socket.

Note:- To use microphone input change the analog audio path control register value

(Register no. 4) in Codec Configuration settings of the Source file (Fir.c) from 0x0011 to

0x0015.

Page 35: Cranes Dsp1 User Manual 6713

Cranes Software Int. Ltd. TI-DIVISION

35

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

5. Create a new project with name Fir.pjt.

6. Open the File Menu � new � DSP/BIOS Configuration ����select

“dsk6713.cdb” and save it as “xyz.cdb”

Page 36: Cranes Dsp1 User Manual 6713

Cranes Software Int. Ltd. TI-DIVISION

36

7. Add “xyz.cdb” to the current project. Project���� Add files to project ����xyz.cdb

8. Automatically three files are added in the Generated file folder in project pane

xyzcfg.cmd� Command and linking file

xyzcfg.s62 � optimized assembly code for configuration

xyzcfg_c.c � Chip support initialization

9. Open the File Menu � new � Source file

10. 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.

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 “dsk6713bsl.lib” to the current project

Path � “C:\CCStudio_v3.1\C6000\dsk6713\lib\dsk6713bsl.lib”

13. Copy header files “dsk6713.h” and “dsk6713_aic23.h” from and paste it in current project folder.

C:\CCStudio_v3.1\C6000\dsk6713\include.

Page 37: Cranes Dsp1 User Manual 6713

Cranes Software Int. Ltd. TI-DIVISION

37

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

MATLAB GENERATED FREQUENCY RESPONSE

High Pass FIR filter(Fc= 800Hz).

Low Pass FIR filter (Fc=1000Hz)

Page 38: Cranes Dsp1 User Manual 6713

Cranes Software Int. Ltd. TI-DIVISION

38

Page 39: Cranes Dsp1 User Manual 6713

Cranes Software Int. Ltd. TI-DIVISION

39

Audio Application

Page 40: Cranes Dsp1 User Manual 6713

Cranes Software Int. Ltd. TI-DIVISION

40

Spectrogram with RTDX using MATLAB

This version of project makes use of RTDX with MATLAB for transferring data from the

DSK to the PC host. This section introduces configuration file(.CDB) file and RTDX with

MATLAB.

This project uses source program spectrogram_rtdx_mtl.c that runs on the DSK which

computes 256 point FFT and enables an RTDX output channel to write/send the resulting

FFT data to the PC running MATLAB for finding the spectrogram. A total of N/2 (128

points )are sent. The (.CDB) configuration file is used to set interrupt INT11. From this

configuration file select Input/Output ���� RTDX. Right click on properties and change the

RTDX buffer size to 8200. Within CCS, select tools ���� RTDX ���� Configure to set the host

buffer size to 2048(from 1024).

An input signal is read in blocks of 256 samples. Each block of data is then multiplied with a

hamming window of length 256 points. The FFT of the windowed data is calculated and

squared. Half of the resulting FFT of each block of 256 points is then transferred to the PC

running MATLAB to find the specrtrogram.

Page 41: Cranes Dsp1 User Manual 6713

Cranes Software Int. Ltd. TI-DIVISION

41

Spectrogram_rtdx_mtl.c Time-Frequency analysis of signals Using RTDX-MATLAB

#include "dsk6713_aic23.h" //codec-DSK support file

Uint32 fs=DSK6713_AIC23_FREQ_8KHZ; //set sampling rate

#include <rtdx.h> //RTDX support

file

#include <math.h>

#include "hamming.cof" //Hamming window coefficients

#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],iobuffer1[PTS],a[PTS]; //input and

output buffer

float x1[PTS]; //intermediate buffer

short i; //general purpose index

variable

int j, k,l, curr_block = 0; //index variables

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

RTDX_CreateOutputChannel(ochan); //create output channel C6x-

>PC

main()

{

for (i = 0 ; i<PTS ; i++) //set up twiddle constants in w

{

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(!RTDX_isOutputEnabled(&ochan)) //wait for PC to enable RTDX

puts("\n\n Waiting . . . "); //while waiting

for(l=0;l<256;l++)

a[l]=cos(2*3.14*1500*l/8000);

for(k=0;k<5000;k++) //infinite loop

{

while (flag == 0) ; //wait until iobuffer is full

flag = 0; //reset flag

for (i = 0 ; i < PTS ; i++) //swap buffers

{ iobuffer1[i]=iobuffer[i]+a[i];

samples[i].real=h[i]*iobuffer1[i]; //multiply by Hamming window coeffs

iobuffer1[i] = x1[i]; //process frame to iobuffer

}

for (i = 0 ; i < PTS ; i++)

Page 42: Cranes Dsp1 User Manual 6713

Cranes Software Int. Ltd. TI-DIVISION

42

samples[i].imag = 0.0; //imag components = 0

FFT(samples,PTS); //call C-coded FFT function

for (i = 0 ; i < PTS ; i++) //compute square of FFT magnitude

{

x1[i] = (samples[i].real*samples[i].real

+ samples[i].imag*samples[i].imag)/16; //FFT data scaling

}

RTDX_write(&ochan, x1, sizeof(x1)/2); //send 128 samples to PC

} //end of infinite loop

} //end of main

interrupt void c_int11() //ISR

{

output_sample((short)(iobuffer[buffercount])); //out from iobuffer

iobuffer[buffercount++]=(short)(input_sample()); //input to iobuffer

if (buffercount >= PTS) //if iobuffer full

{

buffercount = 0;

//reinit buffercount

flag = 1;

//reset flag

}

}

FFT.c C callable FFT function in C

#define PTS 256 //# 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 = 512/N; //step between values in twiddle.h

for (i = 0;i < num_stages; i++) //for N-point FFT

Page 43: Cranes Dsp1 User Manual 6713

Cranes Software Int. Ltd. TI-DIVISION

43

{

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;

}

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;

}

Page 44: Cranes Dsp1 User Manual 6713

Cranes Software Int. Ltd. TI-DIVISION

44

Spectrogram_RTDX.m For spectrogram plot using RTDX with MATLAB

clc;

ccsboardinfo %board info

cc=ccsdsp('boardnum',0); %set up CCS object

reset(cc); %reset board

visible(cc,1); %for CCS window

enable(cc.rtdx); %enable RTDX

if ~isenabled(cc.rtdx);

error('RTDX is not enabled')

end

cc.rtdx.set('timeout',50); %set 50sec timeout for RTDX

open(cc,'spectrogram1.pjt'); %open CCS project

load(cc,'./debug/spectrogram1.out'); %load executable file

run(cc); %run program

configure(cc.rtdx,2048,1); %configure one RTDX channel

open(cc.rtdx,'ochan','r'); %open output channel

pause(3) %wait for RTDX channel to open

enable(cc.rtdx,'ochan'); %enable channel from DSK

isenabled(cc.rtdx,'ochan');

M = 256; %window size

N = round(M/2);

Page 45: Cranes Dsp1 User Manual 6713

Cranes Software Int. Ltd. TI-DIVISION

45

B = 128; %No. of blocks (128)

fs = 8000; %sampling rate

t=(1:B)*(M/fs); %spectrogram axes generation

f=((0:(M-1)/2)/(M-1))*fs;

set(gcf,'DoubleBuffer','on');

y = ones(N,B);

column = 1;

set(gca,'NextPlot','add');

axes_handle = get(gcf,'CurrentAxes');

set(get(axes_handle,'XLabel'),'String','Time (s)');

set(get(axes_handle,'YLabel'),'String','Frequency (Hz)');

set(get(axes_handle,'Title'),'String','\fontname{times}\bf Real-Time Spectrogram');

set(gca,'XLim', [0 4.096]);

set(gca,'YLim', [0 4000]);

set(gca,'XLimMode','manual');

set(gca,'YLimMode','manual');

for i = 1:32768

w=readmsg(cc.rtdx,'ochan','single'); %read FFT data from DSK

w=double(w(1:N));

y(:, column) = w';

Page 46: Cranes Dsp1 User Manual 6713

Cranes Software Int. Ltd. TI-DIVISION

46

imagesc(t,f,dB(y)); %plot spectrogram

column = mod(column, B) + 1;

end

halt(cc); %halt processor

close(cc.rtdx,'ochan'); %close channel

clear cc %clear object

NOTE: For this example works with CCS 2.2 and Matlab 6.5.

Procedure: 22. Create a new project with name spectrogram.pjt. 23. Open “spectrogram.cdb” from given CD and save it in your new

project folder. 24. Copy the following files from the CD to your new project folder

1) c6713dskinit . c 2) FFT.c 3) spectrogram_rtdx_mtl.c 4) c6713dskinit . h 5) hamming.cof 6) spectrogram_RTDX.m

25. Add “spectrogram.cdb”, “c6713dskinit.c” and “spectrogram_rtdx_mtl.c” to the

current project. 26. Add the library file “dsk6713bsl.lib” to the current project

Path � “C:\CCStudio\C6000\dsk6713\lib\dsk6713bsl.lib” 5. Set the following compiler options. Select Project ���� Build options. Select the following for compiler option with Basic ( for category):

(1) c671x{mv6710} (for target version) (2) Full symbolic debug (for Generate Debug info) (3) Speed most critical(for Opt Speed vs. Size) (4) None (for Opt Level and Program Level Opt)

Select The Preprocessor Category and Type for Define Symbols{d}:

Page 47: Cranes Dsp1 User Manual 6713

Cranes Software Int. Ltd. TI-DIVISION

47

CHIP_6713, and from Feedback category, select for Interlisting: OPT / C and ASM{-s} 6 Build project. 7. Close CCS 8. Open MATLAB 6.5 and Run spectrogram_RTDX.m . within MATLAB ,CCS will enable RTDX and will load and run the COFF(.out) executable file. Then MATLAB will plot the spectrogram of an input signal .

Page 48: Cranes Dsp1 User Manual 6713

Cranes Software Int. Ltd. TI-DIVISION

48

Noise removal using Adaptive Filters

Page 49: Cranes Dsp1 User Manual 6713

Cranes Software Int. Ltd. TI-DIVISION

49

Page 50: Cranes Dsp1 User Manual 6713

Cranes Software Int. Ltd. TI-DIVISION

50

Page 51: Cranes Dsp1 User Manual 6713

Cranes Software Int. Ltd. TI-DIVISION

51

Page 52: Cranes Dsp1 User Manual 6713

Cranes Software Int. Ltd. TI-DIVISION

52

C PROGRAM TO IMPLEMENT NOISE CANCELLATION :

#include "xyzcfg.h"

#include "dsk6713.h"

#include "dsk6713_aic23.h"

#define beta 1E-12 //rate of convergence

#define N 30

short int adaptive_filter(short int ,short int );

float delay[N];

float w[N];

//union{unsigned int uint; short channel[2];} AIC23_data;

DSK6713_AIC23_Config config = {\

0x0017, /* 0 DSK6713_AIC23_LEFTINVOL Left line input channel volume */ \

0x0017, /* 1 DSK6713_AIC23_RIGHTINVOL Right line input channel volume */\

0x00d8, /* 2 DSK6713_AIC23_LEFTHPVOL Left channel headphone volume */ \

0x00d8, /* 3 DSK6713_AIC23_RIGHTHPVOL Right channel headphone volume */ \

0x0011, /* 4 DSK6713_AIC23_ANAPATH Analog audio path control */ \

0x0000, /* 5 DSK6713_AIC23_DIGPATH Digital audio path control */ \

0x0000, /* 6 DSK6713_AIC23_POWERDOWN Power down control */ \

0x0043, /* 7 DSK6713_AIC23_DIGIF Digital audio interface format */ \

0x0081, /* 8 DSK6713_AIC23_SAMPLERATE Sample rate control */ \

0x0001 /* 9 DSK6713_AIC23_DIGACT Digital interface activation */ \

};

/*

* main() - Main code routine, initializes BSL and generates tone

*/

void main()

{

DSK6713_AIC23_CodecHandle hCodec;

int l_input, r_input;

int l_output, r_output, T;

/* Initialize the board support library, must be called first */

DSK6713_init();

/* Start the codec */

hCodec = DSK6713_AIC23_openCodec(0, &config);

DSK6713_AIC23_setFreq(hCodec, 1);

Page 53: Cranes Dsp1 User Manual 6713

Cranes Software Int. Ltd. TI-DIVISION

53

for (T = 0; T < 30; T++)

{

w[T] = 0; //init buffer for weights

delay[T] = 0; //init buffer for delay samples

}

while(1)

{

/* Read a sample to the left channel */

while (!DSK6713_AIC23_read(hCodec,&l_input));

/* Read a sample to the right channel */

while (!DSK6713_AIC23_read(hCodec, &r_input));

l_output=(short int)adaptive_filter(l_input,r_input);

r_output=l_output;

/* Send a sample to the left channel */

while (!DSK6713_AIC23_write(hCodec, l_output));

/* Send a sample to the right channel */

while (!DSK6713_AIC23_write(hCodec, r_output));

}

/* Close the codec */

DSK6713_AIC23_closeCodec(hCodec);

}

short int adaptive_filter(short l_input1,short r_input1) //ISR

{

short i,output,T;

float yn=0, E=0, dplusn=0, desired=0, noise=0;

desired = l_input1;

noise = r_input1;

dplusn = desired + noise; //desired+noise

delay[0] = noise; //noise as input to adapt FIR

for (i = 0; i < N; i++) //to calculate out of adapt FIR

yn += (w[i] * delay[i]); //output of adaptive filter

E = (desired + noise) - yn; //"error" signal=(d+n)-yn

for (i = N-1; i >= 0; i--) //to update weights and delays

{

w[i] = w[i] + beta*E*delay[i]; //update weights

Page 54: Cranes Dsp1 User Manual 6713

Cranes Software Int. Ltd. TI-DIVISION

54

delay[i] = delay[i-1]; //update delay samples

}

output=((short)E); //error signal as overall output

//output=((short)dplusn);//output (desired+noise)

//overall output result

return(output);

}

PROCEDURE :

� Switch on the DSP board.

� Open the Code Composer Studio.

� Create a new project Project � New (File Name. pjt , Eg: noisecancellation.pjt)

� Initialize on board codec.

Note: “Kindly refer the Topic Configuration of 6713 Codec using BSL”

� Add the above ‘C’ source file to the current project (remove codec.c source file from the

project if you have already added).

� Desired Signal ���� 400 Hz

Noise ���� 3.0 KHz

Input a desired sinusoidal signal into the Left channel and Noise signal of 3KHz into the

Right channel

� Build the project.

� Load the generated object file(*.out) on to Target board.

� Run the program.

� Observe the waveform that appears on the CRO screen. Verify that the 3 KHz noise signal is being cancelled gradually.

Page 55: Cranes Dsp1 User Manual 6713

Cranes Software Int. Ltd. TI-DIVISION

55

IMPULSE RESPONSE

‘C’ Program to Implement Impulse response: #include <stdio.h>

#define Order 2 #define Len 10

float y[Len]={0,0,0},sum;

main() {

int j,k;

float a[Order+1]={0.1311, 0.2622, 0.1311}; float b[Order+1]={1, -0.7478, 0.2722};

for(j=0;j<Len;j++) {

sum=0; for(k=1;k<=Order;k++) {

if((j-k)>=0) sum=sum+(b[k]*y[j-k]);

} if(j<=Order) {

y[j]=a[j]-sum; }

else { y[j]=-sum;

} printf("Respose[%d] = %f\n",j,y[j]);

} }

Page 56: Cranes Dsp1 User Manual 6713

Cranes Software Int. Ltd. TI-DIVISION

56

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 Impulse_response.pjt.

� Add the source files impulse_res.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\dsk6713\hello1\hello.cmd)

� Add the run time support library file rts6700.lib (Path: C:\CCStudio_v3.1\c6000\cgtools\lib\rts6700.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(Impulse_response.out) in program memory of DSP chip using the

‘File-load program’ pull down menu.

� Execute the program. Debug����run

Result: The result is displayed on the Debug window.

Page 57: Cranes Dsp1 User Manual 6713

Cranes Software Int. Ltd. TI-DIVISION

57

MINI PROJECT

(DISCRETE COSINE TRANSFORM)

Page 58: Cranes Dsp1 User Manual 6713

Cranes Software Int. Ltd. TI-DIVISION

58

The Discrete Cosine Transform

Introduction:-

The discrete cosine transform (DCT) helps separate the image into parts (or spectral sub-bands) of

differing importance (with respect to the image's visual quality). The DCT is similar to the discrete

Fourier transform: it transforms a signal or image from the spatial domain to the frequency

domain. With an input image, A, the coefficients for the output "image," B, are:

The input image is N2 pixels wide by N1 pixels high; A(i,j) is the intensity of the pixel in row i

and column j; B(k1,k2) is the DCT coefficient in row k1 and column k2 of the DCT matrix. All

DCT multiplications are real. This lowers the number of required multiplications, as compared to

the discrete Fourier transform. The DCT input is an 8 by 8 array of integers. This array contains

each pixel's gray scale level; 8 bit pixels have levels from 0 to 255. The output array of DCT

coefficients contains integers; these can range from -1024 to 1023. For most images, much of the

signal energy lies at low frequencies; these appear in the upper left corner of the DCT. The lower

right values represent higher frequencies, and are often small - small enough to be neglected with

little visible distortion.

IMPLEMENTATION OF DCT

� DCT-based codecs use a two-dimensional version of the transform.

� The 2-D DCT and its inverse (IDCT) of an N x N block are shown below:

2-D DCT:

2-D IDCT:

� One of the properties of the 2-D DCT is that it is separable meaning that it can be separated into a pair of 1-D DCTs. To obtain the 2-D DCT of a block a 1-D DCT is first performed

on the rows of the block then a 1-D DCT is performed on the columns of the resulting

block.

� The same applies to the IDCT. � This process is illustrated below.

∑∑−

=

=

++=

1

0

1

0

]2

)12(cos[]

2

)12(cos[),()()(

2),(

N

y

N

x N

vy

N

uxyxfvCuC

NvuF

ππ

∑∑−

=

=

++=

1

0

1

0

]2

)12(cos[]

2

)12(cos[),()()(

2),(

N

v

N

u N

vy

N

uxvuFvCuC

Nyxf

ππ

Page 59: Cranes Dsp1 User Manual 6713

Cranes Software Int. Ltd. TI-DIVISION

59

� Precalculate the DCT coefficients and scale them

Page 60: Cranes Dsp1 User Manual 6713

Cranes Software Int. Ltd. TI-DIVISION

60

Note that the values in the decimal format does not include the factor [Sqrt(2/n)=>sqrt(2/8)=>1/2].

The reason for this is that dividing the coefficients by 2 before converting to Q12 may result in

some loss in precision. More precision can be obtained by ignoring this division and then

multiplying by 211 (instead of 212) to convert to Q12. The reason for using Q12 instead of Q15 (as

one would expect) is as follows. Referring to Equation [3], we notice that the DCT calculation

involves a summation of N terms. Looking at the DCT coefficients in Figure 1, we observe that the

terms entering in the summation may be close to 1. Thus, such summation may cause overflows.

To avoid this, each term must be scaled down by 1/N. For N=8, this can be achieved by working in

Q12 format instead of Q15 format.

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 “image.pjt”.

3. From the File Menu � new � DSP/BIOS Configuration ���� select “dsk6713.cdb” and

save it as “image1.cdb” and add it to the project.

4. Add the source files “main.c“ ,”dct.c” and “idct.c” in the project using

‘Project����add files to project’ pull down menu.

5. Add the linker command file “MY_LNK_CMD.cmd” to your project

6. Copy the header files “scenary.h” and “dct.h” and paste it in your project folder.

7. Compile the program using the ‘Project-compile’ pull down menu or by

clicking the shortcut icon on the left side of program window.

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 image utility.

Page 61: Cranes Dsp1 User Manual 6713

Cranes Software Int. Ltd. TI-DIVISION

61

Main.c: #include <stdio.h>

#include <stdlib.h>

#include "dct.h"

#include "scenary.h" /* Header file containing input image as a 1D array */

#pragma DATA_SECTION (image_in,"ext_sdram")

#pragma DATA_SECTION (image_out,"ext_sdram")

/* 1D array to hold output image */

unsigned char image_out[IMAGE_SIZE];

/* 1D array to hold the current block */

short block[BLOCK_SIZE];

/* Q12 DCT coefficients (actual coefficient x 2^12 ) */

const short coe[8][8]=

{

4096, 4096, 4096, 4096, 4096, 4096, 4096, 4096,

5681, 4816, 3218, 1130, -1130, -3218, -4816, -5681,

5352, 2217, -2217, -5352, -5352, -2217, 2217, 5352,

4816, -1130, -5681, -3218, 3218, 5681, 1130, -4816,

4096, -4096, -4096, 4096, 4096, -4096, -4096, 4096,

3218, -5681, 1130, 4816, -4816, -1130, 5681, -3218,

2217, -5352, 5352, -2217, -2217, 5352, -5352, 2217,

1130, -3218, 4816, -5681, 5681, -4816, 3218, -1130

};

extern void dct(void);

extern void idct(void);

void main()

{

int i,x;

/* Perform block by block processing */

for(i=0;i<IMAGE_SIZE;i+=BLOCK_SIZE)

{

/* Get the block from the input image */

for(x=0;x<BLOCK_SIZE;++x)

{

block[x] = (short) image_in[i+x];

}

/* Perform DCT on this block */

dct();

Page 62: Cranes Dsp1 User Manual 6713

Cranes Software Int. Ltd. TI-DIVISION

62

/* Perform IDCT on this block */

idct();

/* Store block to output image */

for(x=0;x<BLOCK_SIZE;++x)

{

if(block[x]<0)

{

image_out[i+x]=(unsigned char) (-block[x]); /* Quick fix for errors

occuring due to negative a values occuring after IDCT! */

}

else

{

image_out[i+x]=(unsigned char) block[x];

}

}

}

//for (;;); /* Wait */

}

dct.c:

/*********************************************************************/

/* dct.c Function to perform a 8 point 2D DCT */

/* DCT is performed using direct matrix multiplication */

/*********************************************************************/

#include "dct.h"

extern unsigned char image_in[IMAGE_SIZE];

extern unsigned char image_out[IMAGE_SIZE];

extern short block[BLOCK_SIZE];

extern const short coe[8][8];

void dct(void)

{

int i,j,x,y;

int value[8];

/* Perform 1D DCT on the columns */

for(j=0;j<8;j++)

{

for(y=0;y<8;++y)

{

value[y]=0;

Page 63: Cranes Dsp1 User Manual 6713

Cranes Software Int. Ltd. TI-DIVISION

63

for(x=0;x<8;++x)

{

value[y] += (int)(coe[y][x]*block[j+(x*8)]);

}

}

for(y=0;y<8;++y)

{

block[j+(y*8)] = (short)(value[y]>>12);

}

}

/* Perform 1D DCT on the resulting rows */

for(i=0;i<64;i+=8)

{

for(y=0;y<8;++y)

{

value[y] = 0;

for(x=0;x<8;++x)

{

value[y] += (int)(coe[y][x]*block[i+x]);

}

}

for(y=0;y<8;++y)

{

block[i+y] = (short)(value[y]>>15);

}

}

}

idct.c:

/*********************************************************************/

/* idct.c performs a 8 point 2D Inverse DCT function */

/*********************************************************************/

#include "dct.h"

extern unsigned char image_in[IMAGE_SIZE];

extern unsigned char image_out[IMAGE_SIZE];

extern short block[BLOCK_SIZE];

extern const short coe[8][8];

void idct(void)

{

Page 64: Cranes Dsp1 User Manual 6713

Cranes Software Int. Ltd. TI-DIVISION

64

int i,j,x,y;

int value[8];

/* Perform 1D IDCT on the columns */

for(j=0;j<8;j++)

{

for(y=0;y<8;++y)

{

value[y] = 0;

for(x=0;x<8;++x)

{

value[y] += (int)(coe[x][y]*block[j+(x*8)]);

}

}

for(y=0;y<8;++y)

{

block[j+(y*8)] = (short)(value[y]>>12);

}

}

/* Perform 1D IDCT on the resulting rows */

for(i=0;i<64;i+=8)

{

for(y=0;y<8;++y)

{

value[y] = 0;

for(x=0;x<8;++x)

{

value[y] += (int)(coe[x][y]*block[i+x]);

}

}

for(y=0;y<8;++y)

{

block[i+y] = (short)(value[y]>>15);

}

}

}

Page 65: Cranes Dsp1 User Manual 6713

Cranes Software Int. Ltd. TI-DIVISION

65

MY_LNK_CMD.cmd:

-l imagecfg.cmd

SECTIONS

{

mydata > SDRAM

mycode > SDRAM

ext_sdram > SDRAM

}

Image in:

Image out: