MPDSP - Lab Manual Nmrec

Download as pdf or txt
Download as pdf or txt
You are on page 1of 44

EXPERIMENT-1

Aim: Write an Embedded C program to blinky led with software delay, delay generated using systick
timer
.
Apparatus:

S. No Name of the equipment Quantity

1 MCB1700 Trainer kit 1


2 5V Adapter 1
3 RS-232 Cable 1
4 Keil software 1

Program:
/*----------------------------------------------------------------------------
* Name: LED.c
* Purpose: low level LED functions*/
#include "LPC17xx.H" /* LPC17xx definitions */
#include "LED.h"

const unsigned long led_mask[] = { 1UL<<28, 1UL<<29, 1UL<<31, 1UL<< 2,


1UL<< 3, 1UL<< 4, 1UL<< 5, 1UL<< 6 };

/*----------------------------------------------------------------------------
initialize LED Pins
*----------------------------------------------------------------------------*/
Void main()
{
void LED_Init (void) {

LPC_SC->PCONP |= (1 << 15); /* enable power to GPIO & IOCON */

LPC_GPIO1->FIODIR |= 0xB0000000; /* LEDs on PORT1 are output */


LPC_GPIO2->FIODIR |= 0x0000007C; /* LEDs on PORT2 are output */
}

/*----------------------------------------------------------------------------

Function that turns on requested LED


*----------------------------------------------------------------------------*/
void LED_On (unsigned int num) {
if (num < 3) LPC_GPIO1->FIOPIN |= led_mask[num];
else LPC_GPIO2->FIOPIN |= led_mask[num];
}

/*----------------------------------------------------------------------------
Function that turns off requested LED
*----------------------------------------------------------------------------*/
void LED_Off (unsigned int num) {

if (num < 3) LPC_GPIO1->FIOPIN &= ~led_mask[num];


else LPC_GPIO2->FIOPIN &= ~led_mask[num];
}

/*----------------------------------------------------------------------------
Function that outputs value to LEDs
*----------------------------------------------------------------------------*/
void LED_Out(unsigned int value) {
int i;

for (i = 0; i < LED_NUM; i++) {


if (value & (1<<i)) {
LED_On (i);
} else {
LED_Off(i);
}
}
}
}

Output: You can see the all led‟s blinking


EXPERIMENT-2
Aim : Write an embedded C program to take analog readings on rotation of rotary potentiometer
connected to an ADC channel.
Apparatus:

S. No Name of the equipment Quantity

1 MCB1700 Trainer kit 1


2 5V Adapter 1
3 RS-232 Cable 1
4 Keil software 1

Source Code:
/*----------------------------------------------------------------------------
* Name: ADC.c
* Purpose: low level ADC functions
* Note(s): possible defines select the used ADC interface:
* __ADC_IRQ - ADC works in Interrupt mode
* - ADC works in polling mode (default) */
#include "LPC17xx.H" /* LPC17xx definitions */
#include "ADC.h"

uint16_t AD_last; /* Last converted value */


uint8_t AD_done = 0; /* AD conversion done flag */
void main()
{
/*----------------------------------------------------------------------------
Function that initializes ADC
*----------------------------------------------------------------------------*/
void ADC_Init (void) {

LPC_SC->PCONP |= ((1 << 12) | (1 << 15)); /* enable power to ADC & IOCON */

LPC_PINCON->PINSEL1 &= ~( 3 << 18);


LPC_PINCON->PINSEL1 |= ( 1 << 18); /* P0.25 is AD0.2 */
LPC_PINCON->PINMODE1 &= ~( 3 << 18);
LPC_PINCON->PINMODE1 |= ( 2 << 18); /* P0.25 no pull up/down */

LPC_ADC->ADCR = ( 1 << 2) | /* select AD0.2 pin */


( 4 << 8) | /* ADC clock is 25MHz/5 */
( 1 << 21); /* enable ADC */
#ifdef __ADC_IRQ
LPC_ADC->ADINTEN = ( 1 << 8); /* global enable interrupt */

NVIC_EnableIRQ(ADC_IRQn); /* enable ADC Interrupt */


#endif
}

/*----------------------------------------------------------------------------
start AD Conversion
*----------------------------------------------------------------------------*/
void ADC_StartCnv (void) {
LPC_ADC->ADCR &= ~( 7 << 24); /* stop conversion */
LPC_ADC->ADCR |= ( 1 << 24); /* start conversion */
}

/*----------------------------------------------------------------------------
stop AD Conversion
*----------------------------------------------------------------------------*/
void ADC_StopCnv (void) {

LPC_ADC->ADCR &= ~( 7 << 24); /* stop conversion */


}

/*----------------------------------------------------------------------------
get converted AD value
*----------------------------------------------------------------------------*/
uint16_t ADC_GetCnv (void) {

#ifndef __ADC_IRQ
while (!(LPC_ADC->ADGDR & ( 1UL << 31))); /* Wait for Conversion end */
AD_last = (LPC_ADC->ADGDR >> 4) & ADC_VALUE_MAX; /* Store converted value */

AD_done = 1;
#endif

return(AD_last);
}

/*----------------------------------------------------------------------------
A/D IRQ: Executed when A/D Conversion is done
*----------------------------------------------------------------------------*/
#ifdef __ADC_IRQ
void ADC_IRQHandler(void) {
volatile uint32_t adstat;
adstat = LPC_ADC->ADSTAT; /* Read ADC clears interrupt */

AD_last = (LPC_ADC->ADGDR >> 4) & ADC_VALUE_MAX; /* Store converted value */

AD_done = 1;
}
#endif
}
Output: You can see the message on LCD.analog readings if required reset the board.
EXPERIMENT-3

Aim : Write an embedded C program to control intensity of a led using pwm implemented in
software.
Apparatus:

S. No Name of the equipment Quantity

1 MCB1700 Trainer kit 1


2 5V Adapter 1
3 RS-232 Cable 1
4 Keil software 1

Source Code:
#include <lpc17xx.h>
#include "pwm.h"
#include "delay.h"

#define CYCLE_TIME 255

/* start the main program */


int main()
{
int dutyCycle;
SystemInit(); /* Clock and PLL configuration */
PWM_Init(CYCLE_TIME); /* Initialize the PWM module and the Cycle time(Ton+Toff) is set
to 255(similar to arduino)*/
PWM_Start(PWM_1|PWM_2|PWM_3|PWM_4); /* Enable PWM output on PWM_1-PWM_4
(P2_0 - P2_3) */

while(1)
{

for(dutyCycle=0;dutyCycle<CYCLE_TIME;dutyCycle++) /* Increase the Brightness of the Leds


*/
{
PWM_SetDutyCycle(PWM_1,dutyCycle); //P2_0
PWM_SetDutyCycle(PWM_2,dutyCycle); //P2_1
PWM_SetDutyCycle(PWM_3,dutyCycle); //P2_2
PWM_SetDutyCycle(PWM_4,dutyCycle); //P2_3
DELAY_ms(5);
}

for(dutyCycle=CYCLE_TIME;dutyCycle>0;dutyCycle--) /* Decrease the Brightness of the Leds


*/
{
PWM_SetDutyCycle(PWM_1,dutyCycle); //P2_0
PWM_SetDutyCycle(PWM_2,dutyCycle); //P2_1
PWM_SetDutyCycle(PWM_3,dutyCycle); //P2_2
PWM_SetDutyCycle(PWM_4,dutyCycle); //P2_3
DELAY_ms(5);
}
}
}

Output: In this program control intensity of an led using pwm implemented in software. You can see
output on display
EXPERIMENT-4
Aim : To write an embedded C program for Temperature indication on an RGB LED
and to Verify the output in the Cortex-M3 kit
Apparatus:

S. No Name of the equipment Quantity

1 Cortex-M Trainer kit 1


2 5V Adapter 1
3 RS-232 Cable 1
4 Keil software 1

Source code:
#include "adc.h"
#include "lcd.h"
#include "LPC17xx.h"
#include "delay.h"
int main()
{
int adcValue;
float temp;
SystemInit();
ADC_Init(); /* Initialize the ADC module */

/*Connect RS, RW, EN and data bus to PORT0.4 to PORT0.7*/


LCD_SetUp(P2_0,P2_1,P2_2,P_NC,P_NC,P_NC,P_NC,P1_24,P1_25,P1_26,P1_27);
LCD_Init(2,16);

while(1)
{
adcValue = ADC_GetAdcValue(0); // Read the ADC value of channel zero where the
temperature sensor(LM35) is connected

/* Convert the raw ADC value to equivalent temperature with 5v as ADC reference
Step size of AdC= (5v/1023)=4.887mv = 5mv.
for every degree celcius the Lm35 provides 10mv voltage change.
1 step of ADC=5mv=0.5'c, hence the Raw ADC value can be divided by 2 to get
equivalent temp*/

temp = adcValue/2.0; // Divide by 2 to get the temp value.


LCD_GoToLine(0);
LCD_Printf("ADC0 Value:%4d \nTemp:%f\n\r",adcValue,temp); // Display adc value and
temp LCD
}

34
}

RESULT:

Thus the Embedded C program for temperature indication on an RGB LED is written and
executed. The output is verified in the CORTEX kit.

35
EXPERIMENT-5
AIM: Calculate the Euclidian distance between any two points Using DSK Code composer studio
EQUIPMENTS:

S. No Name of the equipment Quantity


1 TMS 320C6713 Kit 1
2 RS232 Serial Cable 1
3 Power Cord 1
4 Operating System – Windows XP 1
5 Software – CCStudio_v3.1 1

THEORY:

Formula:

C Code:

#include <stdio.h>

#include <math.h>

int main() {

float x1, y1, x2, y2, gdistance;

printf("Input x1: ");

scanf("%f", &x1);

printf("Input y1: ");

scanf("%f", &y1);

36
printf("Input x2: ");

scanf("%f", &x2);

printf("Input y2: ");

scanf("%f", &y2);

gdistance = ((x2-x1)*(x2-x1))+((y2-y1)*(y2-y1));

printf("Distance between the said points: %.4f", sqrt(gdistance));

printf("\n");

return 0;

Sample Output:

Input x1: 25
Input y1: 15
Input x2: 35
Input y2: 10
Distance between the said points: 11.1803

37
EXPERIMENT-6

AIM: Verify the linear convolution operation Using DSK Code composer studio

EQUIPMENTS:

S. No Name of the equipment Quantity


1 TMS 320C6713 Kit 1
2 RS232 Serial Cable 1
3 Power Cord 1
4 Operating System – Windows XP 1
5 Software – CCStudio_v3.1 1

THEORY:

Convolution is a formal mathematical operation, just as multiplication, addition, and integration.


Addition takes two numbers and produces a third number, while convolution takes two signals and
produces a third signal. Convolution is used in the mathematics of many fields, such as probability
and statistics. In linear systems, convolution is used to describe the relationship between three
signals of interest: the input signal, the impulse response, and the output signal.
N 1
y ( n)   x ( k ) h( n  k )
k 0
0  n  N 1

In this equation, x(k), h(n-k) and y(n) represent the input to and output from the system at time n.
Here we could see that one of the input is shifted in time by a value every time it is multiplied with
the other input signal. Linear Convolution is quite often used as a method of implementing filters
of various types.
PROGRAM:

// Linear convolution program in c language using ccstudio


#include<stdio.h>
int x[15],h[15],y[15];
main()
{
int i,j,m,n;
printf("\n enter the length of first sequence m:");
scanf("%d",&m);
38
printf("\n enter the length of second sequence n:");
scanf("%d",&n);
printf("enter values for i/p sequence x(n):\n");
for(i=0;i<m;i++)
scanf("%d",&x[i]);
printf("enter values for i/p sequence h(n): \n");
for(i=0;i<n; i++)
scanf("%d",&h[i]);
// padding of zeros
for(i=m;i<=m+n-1;i++)
x[i]=0;
for(i=n;i<=m+n-1;i++)
h[i]=0;
/* convolution operation */
for(i=0;i<m+n-1;i++)
{
y[i]=0;
for(j=0;j<=i;j++)
{
y[i]=y[i]+(x[j]*h[i-j]);
}
}
//displaying the o/p
for(i=0;i<m+n-1;i++)
printf("\n the value of output y[%d]=%d\t",i,y[i]);
}

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
(D: 11951A0xxx) with name linear convolution.
 Write the program and save it as linearconv.c

39
 Add the source files linearconv.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
 Build the program using the „Project-Build‟ pull down menu
 Load the program (linearconv.out) in program memory of DSP chip using the „File-
load program‟ pull down menu.
 Debug-> Run
 To View output graphically Select view ->graph ->time and frequency.

OUTPUT AND WAVEFORM:

Enter first sequence length m: 4


Enter second sequence length n: 3
Enter i/p sequence for x (n):
1234
Enter i/p sequence for h (n):
231
Output (Linear Convolution) sequence is:
y[0]=2 y[1]=7 y[2]=13 y[3]=19 y[4]=15 y[5]=4

40
EMPTY SPACE FOR CALCULATIONS

INSERT GRAPH SHEET (NORMAL)

41
EXPERIMENT-7

AIM: Verify the circular convolution operation using DSK code composer studio

EQUIPMENTS:

S. No Name of the equipment Quantity


1 TMS 320C6713 Kit 1
2 RS232 Serial Cable 1
3 Power Cord 1
4 Operating System – Windows XP 1
5 Software – CCStudio_v3.1 1

THEORY:

Circular convolution is another way of finding the convolution sum of two input signals. It
resembles the linear convolution, except that the sample values of one of the input signals is folded
and right shifted before the convolution sum is found. Also note that circular convolution could
also be found by taking the DFT of the two input signals and finding the product of the two
frequency domain signals. The Inverse DFT of the product would give the output of the signal in
the time domain which is the circular convolution output. The two input signals could have been of
varying sample lengths. But we take the DFT of higher point, which ever signals levels to. For e.g.
If one of the signals is of length 256 and the other spans 51 samples, then we could only take 256
point DFT. So the output of IDFT would be containing 256 samples instead of 306 samples, which
follows N1+N2 – 1 where N1 & N2 are the lengths 256 and 51 respectively of the two inputs.
Thus the output which should have been 306 samples long is fitted into 256 samples. The 256
points end up being a distorted version of the correct signal. This process is called circular
convolution.

42
PROGRAM:

//program to implement circular convolution


#include<stdio.h>
int m,n,x[30],h[30],y[30],i,j, k,x2[30],a[30];
void main()
{
printf("\n Enter the length of the first sequence\n");
scanf("%d",&m);
printf("\n Enter the length of the second sequence\n");
scanf("%d",&n);
printf("\n Enter the first sequence\n");
for(i=0;i<m;i++)
scanf("%d",&x[i]);
printf("\n 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*/
{

43
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("\n The circular convolution is: \n");
for(i=0;i<n;i++)
printf("%d \t",y[i]);
}
44
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(D:11951A0xxx) with name circular convolution.
 Write the program and save it as circularconv.c
 Add the source files circularconv.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
 Build the program using the „Project-Build‟ pull down menu
 Load the program (circularconv.out) in program memory of DSP chip using the„File-
load program‟ pull down menu.
 Debug-> Run
 To View output graphically Select view ->graph ->time and frequency.

OUTPUT AND WAVEFORM:

Enter the length of the first sequence 4


Enter the length of the second sequence 3
Enter the first sequence
1234
Enter the second sequence
123
The circular convolution is
18 16 10 16

45
EMPTY SPACE FOR CALCULATIONS

INSERT GRAPH SHEET (NORMAL)

46
EXPERIMENT-8

AIM: To generate a real time fir filter through Rectangular window using TMS320C6713 DSK

EQUIPMENTS:

S. No Name of the equipment Quantity


1 TMS 320C6713 Kit 1
2 RS232 Serial Cable 1
3 Power Cord 1
4 Operating System – Windows XP 1
5 Software – CCStudio_v3.1 1

PROCEDURE:

1. Connect CRO to the LINE OUT sockets.


2. Now switch ON the DSK and bring up Code Composer Studio on PC
3. Create a new project with name sinewave.pjt
4. From File menu->New->DSP/BIOS Configuration->Select dsk6713.cdb and save
it as “ firfliter.cdb”
5. Add firfilter.cdb to the current project
6. Create a new source file and save it as firfilter.c
7. Add the source file firfilter.c to the project
8. Add the library file “dsk6713bsl.lib” to the project
(Path: C:\CCStudio\C6000\dsk6713\lib\dsk6713bsl.lib)
9. Copy files “dsk6713.h” and “dsk6713_aic23.h” to the Project folder
(Path: C:\CCStudio_v3.1\C6000\dsk6713\include)
10. Build (F7) and load the program to the DSP Chip ( File->Load Program(.out file))
11. Run the program (F5)
12. Observe the waveform that appears on the CRO screen and ccstudio simulator.

47
// c program for generation of fir filter using c6713 DSK
#include "firfiltercfg.h"
#include "dsk6713.h"
#include "dsk6713_aic23.h"
#include "stdio.h"
Float filter_coeff[ ]={-0.020203,-0.016567,0.009656,0.027335,0.011411,-0.023194,-
0.033672,0.000000,0.043293,0.038657,-0.025105,-0.082004,-
0.041842,0.115971,0.303048,
0.386435,0.303048,0.115971,-0.041842,-0.082004,-
0.025105,0.038657,0.043293,0.000000,-0.033672,-
0.023194,0.011411,0.027335,0.009656,-0.016567,-0.020203};//FIR Low pass
Rectangular Filter pass band range 0-1500Hz
DSK6713_AIC23_Config
config={0x0017,0x0017,0x00d8,0x00d8,0x0011,0x0000,0x0000,0x0043,0x0081,0x0001}
;
void main()
{
DSK6713_AIC23_CodecHandle hCodec;
Uint32 l_input, r_input,l_output, r_output;
DSK6713_init();
hCodec = DSK6713_AIC23_openCodec(0, &config);
DSK6713_AIC23_setFreq(hCodec, 1);
while(1)
{
while(!DSK6713_AIC23_read(hCodec, &l_input));
while(!DSK6713_AIC23_read(hCodec, &r_input));
l_output=(Int16)FIR_FILTER(&filter_coeff ,l_input);
r_output=l_output;
while(!DSK6713_AIC23_write(hCodec, l_output));
while(!DSK6713_AIC23_write(hCodec, r_output));
}
48
DSK6713_AIC23_closeCodec(hCodec);
}
signed int FIR_FILTER(float * h, signed int x)
{
int i=0;
signed long output=0;
static short int in_buffer[100];
in_buffer[0] = x;
for(i=30;i>0;i--)
in_buffer[i] = in_buffer[i-1];
for(i=0;i<32;i++)
output = output + h[i] * in_buffer[i];
return(output);
}

WAVEFORM:

a) Waveforms of input and output from cro

b) Function generator (input signal frequency at 1 KHz)

49
c) C6713 DSK

d) Function generator (input signal frequency at 1500Hz)

e) Waveforms of input and output from CRO (output signal attenuates)

d) Function generator (input signal frequency at 2000Hz)

50
a) Waveforms of input and output from CRO (output signal fully attenuated)

INSERT GRAPH SHEET (NORMAL)

51
EXPERIMENT-9

AIM:

To generate a real time fir filter through Kaiser Window using TMS320C6713 DSK and
Sample sound using a microphone and display sound levels on LEDs

EQUIPMENTS:

S. No Name of the equipment Quantity


1 TMS 320C6713 Kit 1
2 RS232 Serial Cable 1
3 Power Cord 1
4 Operating System – Windows XP 1
5 Software – CCStudio_v3.1 1

PROCEDURE:

1. Connect CRO to the LINE OUT sockets.


2. Now switch ON the DSK and bring up Code Composer Studio on PC
3. Create a new project with name sinewave.pjt
4. From File menu->New->DSP/BIOS Configuration->Select dsk6713.cdb and save
it as “firfliter_kaiser.cdb”
5. Add firfilter.cdb to the current project
6. Create a new source file and save it as firfilter_kaiser.c
7. Add the source file firfilter_kaiser.c to the project
8. Add the library file “dsk6713bsl.lib” to the project
(Path: C:\CCStudio\C6000\dsk6713\lib\dsk6713bsl.lib)
9. Copy files “dsk6713.h” and “dsk6713_aic23.h” to the Project folder
(Path: C:\CCStudio_v3.1\C6000\dsk6713\include)
10. Build (F7) and load the program to the DSP Chip (File->Load Program (.out file))
11. Run the program (F5)
12. Observe the waveform that appears on the CRO screen and ccstudio simulator.

52
// c program for generation of fir filter using c6713 DSK
#include "firfilter_kaisercfg.h"
#include "dsk6713.h"
#include "dsk6713_aic23.h"
#include "stdio.h"
float filter_coeff[ ]={0.000000,-0.000138,-0.000611,-0.001345,-0.001607, 0.000000, 0.004714,
0.012033,0.018287,0.016731,0.000000,-0.035687,-0.086763,-0.141588,-0.184011,0.800005, -
0.184011,-0.141588,-0.086763,-0.035687,0.000000,0.016731,0.018287,0.012033,0.004714, -
0.000000,-0.001607,-0.001345,-0.000611,-0.000138,0.000000};//FIR High pass Kaiser filter pass
band range 800Hz-3.5KHz
void main()
{
DSK6713_AIC23_CodecHandle hCodec;
Uint32 l_input, r_input,l_output, r_output;
DSK6713_init();
hCodec = DSK6713_AIC23_openCodec(0, &config);
DSK6713_AIC23_setFreq(hCodec, 1);
while(1)
{
while(!DSK6713_AIC23_read(hCodec, &l_input));
while(!DSK6713_AIC23_read(hCodec, &r_input));
l_output=(Int16)FIR_FILTER(&filter_coeff ,l_input);
r_output=l_output;
while(!DSK6713_AIC23_write(hCodec, l_output));
while(!DSK6713_AIC23_write(hCodec, r_output));
}
DSK6713_AIC23_closeCodec(hCodec);
}
signed int FIR_FILTER(float * h, signed int x)
{
int i=0;
signed long output=0;
53
static short int in_buffer[100];
in_buffer[0] = x;
for(i=30;i>0;i--)
in_buffer[i] = in_buffer[i-1];
for(i=0;i<32;i++)
output = output + h[i] * in_buffer[i];
//output = x;
return(output);
}

WAVEFORM:

a) Waveforms of input and output from CRO

b) function generator (input signal frequency at 500Hz)

54
c) C6713 DSK

d) Function generator (input signal frequency at 800Hz)

e) Waveforms of input and output from CRO

d) Function generator (input signal frequency at 1.1kHz)

e) Waveforms of input and output from CRO

55
Insert Graph Sheet (Normal)

56
EXPERIMENT-10

AIM:

To generate a real time iir filter through Butterworth approximation using TMS320C6713
DSK

EQUIPMENTS:

S. No Name of the equipment Quantity


1 TMS 320C6713 Kit 1
2 RS232 Serial Cable 1
3 Power Cord 1
4 Operating System – Windows XP 1
5 Software – CCStudio_v3.1 1

PROCEDURE:

1. Connect CRO to the LINE OUT socket.


2. Now switch ON the DSK and bring up Code Composer Studio on PC
3. Create a new project with name sinewave.pjt
4. From File menu->New->DSP/BIOS Configuration->Select dsk6713.cdb and save
it as “iirfliter.cdb”
5. Add firfilter.cdb to the current project
6. Create a new source file and save it as iirfilter.c
7. Add the source file iirfilter.c to the project
8. Add the library file “dsk6713bsl.lib” to the project
(Path: C:\CCStudio\C6000\dsk6713\lib\dsk6713bsl.lib)
9. Copy files “dsk6713.h” and “dsk6713_aic23.h” to the Project folder
(Path: C:\CCStudio_v3.1\C6000\dsk6713\include)
10. Build (F7) and load the program to the DSP Chip ( File->Load Program(.out file))
11. Run the program (F5)
12. Observe the waveform that appears on the CRO screen and ccstudio simulator.

57
// c program for generation of iir filter using c6713 DSK

#include "iirfiltercfg.h"
#include "dsk6713.h"
#include "dsk6713_aic23.h"
#include "stdio.h"
const signed int filter_coeff [ ] = {15241,15241,15241,32761,10161,7877};
//IIR_BUTERWORTH_LP FILTER pass band range 0-8kHz
DSK6713_AIC23_Config
config={0x0017,0x0017,0x00d8,0x00d8,0x0011,0x0000,0x0000,0x0043,0x0081,0x0001}
;
void main()
{
DSK6713_AIC23_CodecHandle hCodec;
Uint32 l_input, r_input,l_output, r_output;
DSK6713_init();
hCodec = DSK6713_AIC23_openCodec(0, &config);
DSK6713_AIC23_setFreq(hCodec, 3);
while(1)
{
while(!DSK6713_AIC23_read(hCodec, &l_input));
while(!DSK6713_AIC23_read(hCodec, &r_input));
l_output=IIR_FILTER(&filter_coeff ,l_input);
r_output=l_output;
while(!DSK6713_AIC23_write(hCodec, l_output));
while(!DSK6713_AIC23_write(hCodec, r_output));
}
DSK6713_AIC23_closeCodec(hCodec);
}
signed int IIR_FILTER(const signed int * h, signed int x1)
{
static signed int x[6] = {0,0,0,0,0,0};
static signed int y[6] = {0,0,0,0,0,0};

58
int temp=0;
temp = (short int)x1;
x[0] = (signed int) temp;
temp = ( (int)h[0] * x[0]);
temp += ( (int)h[1] * x[1]);
temp += ( (int)h[1] * x[1]);
temp += ( (int)h[2] * x[2]);
temp -= ( (int)h[4] * y[1]);
temp -= ( (int)h[4] * y[1]);
temp -= ( (int)h[5] * y[2]);
temp >>=15;
if ( temp > 32767 )
{
temp = 32767;
}
else if ( temp < -32767)
{
temp = -32767;
}
y[0] = temp;
y[2] = y[1];
y[1] = y[0];
x[2] = x[1];
x[1] = x[0];
return (temp<<2);
}

59
RESULT:

a) Waveforms of input and output from CRO

b) Function generator (input signal frequency at 1KHz)

b) C6713 DSK

c) function generator (input signal frequency at 8kHz)

d) Waveforms of input and output from CRO

60
e) function generator (input signal frequency at 10kHz)

g) Waveforms of input and output from CRO (output signal attenuated)

Insert Graph Sheet (Normal)

61
EXPERIMENT-11

AIM: Verify the convolution operation Using DSK Code composer studio

EQUIPMENTS:

S. No Name of the equipment Quantity


1 TMS 320C6713 Kit 1
2 RS232 Serial Cable 1
3 Power Cord 1
4 Operating System – Windows XP 1
5 Software – CCStudio_v3.1 1

THEORY:

In this program the Discrete Fourier Transform (DFT) of a sequence x[n] is generated by
using the formula,

N-1

X (k) = Σ x(n) e-2πjk / N Where, X(k)  DFT of

sequence x[n] n=0

N represents the sequence length and it is calculated by using the command „length‟. The
DFT of any sequence is the powerful computational tool for performing frequency analysis
of discrete-time signals.

PROGRAM:

#include

<stdio.h>

#include

<math.h> int

N,k,n,i;
62
float

pi=3.1416,sumre=0,sumim=0,out_real[8]={0.0},out_imag[8]={0.0}

; int x[32];

void main(void)

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

scanf("%d",&N);

printf("\nenter the sequence\n");


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

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

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

sumre=0;

sumim=0;

for(n=0;n<N

;n++)

sumre=sumre+x[n]*cos(2*pi*k*

n/N); sumim=sumim-

x[n]*sin(2*pi*k*n/N);

out_real[k]=sum

re;

out_imag[k]=su

63
mim;

printf("DFT of the sequence:\n");

printf("x[%d]=\t%f\t+\t%fi\n",k,out_real[k],out_ima

g[k]);

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(d:11951a0xxx) with name dft.
 Write the program and save it as dft.c
 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


 Build the program using the „project-build‟ pull down menu
 Load the program (dft.out) in program memory of dsp chip using the„file-load program‟
pull down menu.
 Debug-> run
 To view output graphically select view ->graph ->time and frequency.

OUTPUT AND WAVEFORM:

enter the length of the sequence

64
4

enter the sequence

1234

DFT of the sequence:

x[0]= 10.000000 + 0.000000i

DFT of the sequence:

x[1]= -1.999963 + 2.000022i

DFT of the sequence:

x[2]= -2.000000 + 0.000059i

DFT of the sequence:


x[3]= -2.000108 + -1.999934i

Empty Space for

Calculations Insert Graph

Sheet (Normal)

65
EXPERIMENT-12

AIM: To design and implement filters in C to enhance the features of given input sequence/signal

EQUIPMENTS:

S. No Name of the equipment Quantity


1 TMS 320C6713 Kit 1
2 RS232 Serial Cable 1
3 Power Cord 1
4 Operating System – Windows XP 1
5 Software – CCStudio_v3.1 1

PROCEDURE:

1. Connect CRO to the LINE OUT socket.


2. Now switch ON the DSK and bring up Code Composer Studio on PC
3. Create a new project with name sinewave.pjt
4. From File menu->New->DSP/BIOS Configuration->Select dsk6713.cdb and save
it as “iirfliter.cdb”
5. Add firfilter.cdb to the current project
6. Create a new source file and save it as iirfilter.c
7. Add the source file iirfilter.c to the project
8. Add the library file “dsk6713bsl.lib” to the project
(Path: C:\CCStudio\C6000\dsk6713\lib\dsk6713bsl.lib)
9. Copy files “dsk6713.h” and “dsk6713_aic23.h” to the Project folder
(Path: C:\CCStudio_v3.1\C6000\dsk6713\include)
10. Build (F7) and load the program to the DSP Chip ( File->Load Program(.out file))
11. Run the program (F5)
12. Observe the waveform that appears on the CRO screen and ccstudio simulator.

66
// c program for generation of iir filter using c6713 DSK

#include "iirfiltercfg.h"
#include "dsk6713.h"
#include "dsk6713_aic23.h"
#include "stdio.h"
const signed int filter_coeff [ ] = {15241,15241,15241,32761,10161,7877};
//IIR_BUTERWORTH_LP FILTER pass band range 0-8kHz
DSK6713_AIC23_Config
config={0x0017,0x0017,0x00d8,0x00d8,0x0011,0x0000,0x0000,0x0043,0x0081,0x0001}
;
void main()
{
DSK6713_AIC23_CodecHandle hCodec;
Uint32 l_input, r_input,l_output, r_output;
DSK6713_init();
hCodec = DSK6713_AIC23_openCodec(0, &config);
DSK6713_AIC23_setFreq(hCodec, 3);
while(1)
{
while(!DSK6713_AIC23_read(hCodec, &l_input));
while(!DSK6713_AIC23_read(hCodec, &r_input));
l_output=IIR_FILTER(&filter_coeff ,l_input);
r_output=l_output;
while(!DSK6713_AIC23_write(hCodec, l_output));
while(!DSK6713_AIC23_write(hCodec, r_output));
}
DSK6713_AIC23_closeCodec(hCodec);
}
signed int IIR_FILTER(const signed int * h, signed int x1)
{
static signed int x[6] = {0,0,0,0,0,0};
static signed int y[6] = {0,0,0,0,0,0};
67
int temp=0;
temp = (short int)x1;
x[0] = (signed int) temp;
temp = ( (int)h[0] * x[0]);
temp += ( (int)h[1] * x[1]);
temp += ( (int)h[1] * x[1]);
temp += ( (int)h[2] * x[2]);
temp -= ( (int)h[4] * y[1]);
temp -= ( (int)h[4] * y[1]);
temp -= ( (int)h[5] * y[2]);
temp >>=15;
if ( temp > 32767 )
{
temp = 32767;
}
else if ( temp < -32767)
{
temp = -32767;
}
y[0] = temp;
y[2] = y[1];
y[1] = y[0];
x[2] = x[1];
x[1] = x[0];
return (temp<<2);
}

RESULT:

a) Waveforms of input and output from CRO

68
b) Function generator (input signal frequency at 1KHz)

f) C6713 DSK

g) function generator (input signal frequency at 8kHz)

h) Waveforms of input and output from CRO

i) function generator (input signal frequency at 10kHz)

69
g) Waveforms of input and output from CRO (output signal attenuated)

Insert Graph Sheet (Normal)

70

You might also like