MPDSP - Lab Manual Nmrec
MPDSP - Lab Manual Nmrec
MPDSP - Lab Manual Nmrec
Aim: Write an Embedded C program to blinky led with software delay, delay generated using systick
timer
.
Apparatus:
Program:
/*----------------------------------------------------------------------------
* Name: LED.c
* Purpose: low level LED functions*/
#include "LPC17xx.H" /* LPC17xx definitions */
#include "LED.h"
/*----------------------------------------------------------------------------
initialize LED Pins
*----------------------------------------------------------------------------*/
Void main()
{
void LED_Init (void) {
/*----------------------------------------------------------------------------
/*----------------------------------------------------------------------------
Function that turns off requested LED
*----------------------------------------------------------------------------*/
void LED_Off (unsigned int num) {
/*----------------------------------------------------------------------------
Function that outputs value to LEDs
*----------------------------------------------------------------------------*/
void LED_Out(unsigned int value) {
int i;
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"
LPC_SC->PCONP |= ((1 << 12) | (1 << 15)); /* enable power to ADC & IOCON */
/*----------------------------------------------------------------------------
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) {
/*----------------------------------------------------------------------------
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_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:
Source Code:
#include <lpc17xx.h>
#include "pwm.h"
#include "delay.h"
while(1)
{
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:
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 */
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*/
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:
THEORY:
Formula:
C Code:
#include <stdio.h>
#include <math.h>
int main() {
scanf("%f", &x1);
scanf("%f", &y1);
36
printf("Input x2: ");
scanf("%f", &x2);
scanf("%f", &y2);
gdistance = ((x2-x1)*(x2-x1))+((y2-y1)*(y2-y1));
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:
THEORY:
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:
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.
40
EMPTY SPACE FOR CALCULATIONS
41
EXPERIMENT-7
AIM: Verify the circular convolution operation using DSK code composer studio
EQUIPMENTS:
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:
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.
45
EMPTY SPACE FOR CALCULATIONS
46
EXPERIMENT-8
AIM: To generate a real time fir filter through Rectangular window using TMS320C6713 DSK
EQUIPMENTS:
PROCEDURE:
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:
49
c) C6713 DSK
50
a) Waveforms of input and output from CRO (output signal fully attenuated)
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:
PROCEDURE:
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:
54
c) C6713 DSK
55
Insert Graph Sheet (Normal)
56
EXPERIMENT-10
AIM:
To generate a real time iir filter through Butterworth approximation using TMS320C6713
DSK
EQUIPMENTS:
PROCEDURE:
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:
b) C6713 DSK
60
e) function generator (input signal frequency at 10kHz)
61
EXPERIMENT-11
AIM: Verify the convolution operation Using DSK Code composer studio
EQUIPMENTS:
THEORY:
In this program the Discrete Fourier Transform (DFT) of a sequence x[n] is generated by
using the formula,
N-1
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)
scanf("%d",&N);
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("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)
64
4
1234
Sheet (Normal)
65
EXPERIMENT-12
AIM: To design and implement filters in C to enhance the features of given input sequence/signal
EQUIPMENTS:
PROCEDURE:
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:
68
b) Function generator (input signal frequency at 1KHz)
f) C6713 DSK
69
g) Waveforms of input and output from CRO (output signal attenuated)
70