Sie sind auf Seite 1von 17

PLEASE FIRST

ATTACH THE
RESPECTED THEORY
PAPERS WITH THE
RESPECTED
PROGRAMS………
PROGRAMS………
……………..
……………..
/********* ScintTECH Technology Pvt. Ltd. **********/

/***************************************************************************/
/* */
/* R T D X S I N E . C */
/* */
/* DSP program generate the sinwave using lookup table */
/* and produces an output stream.Output data are sent to host files */
/* ousing RTDX channels.Interface CCstudio with VB and display */
/* the wave on VB graph screen */
/***************************************************************************/

#include <std.h>

#include <log.h>
#include <rtdx.h>

#include "rtdxsinecfg.h"

#include "target.h"

#define BUFSIZE 64
#define BUFFERLENGTH 64
#define MINVOLUME 1

typedef Int sample; /* representation of a data sample from A2D */

/* Global declarations */
sample inp_buffer[BUFSIZE];
int out_buffer[BUFFERLENGTH];

Int volume=0;

/* RTDX channels */
RTDX_CreateInputChannel(control_channel);
RTDX_CreateInputChannel(A2D_channel);
RTDX_CreateOutputChannel(D2A1_channel);

/*
* ======== main ========
*/
Void main()
{
sample *input = inp_buffer;
Uns size = BUFSIZE;
int sin_table[8] = {0,707,1000,707,0,-707,-1000,-707};
int i=0,loop=0;

TARGET_INITIALIZE(); /* Enable RTDX interrupt */

LOG_printf(&trace,"\n Sine Wave Example Started");

/* enable volume control input channel */

RTDX_enableInput(&control_channel);

while (TRUE)
{
/* Read a new volume when the hosts send it */
if (!RTDX_channelBusy(&control_channel)) {
RTDX_readNB(&control_channel, &volume, sizeof(volume));
}

while (!RTDX_isInputEnabled(&A2D_channel)){
#if RTDX_POLLING_IMPLEMENTATION
RTDX_Poll(); /* poll comm channel for input*/
#endif
}

/*
* A2D: get digitized input (get signal from the host through RTDX).
* If A2D_channel is enabled, read data from the host.
*/
RTDX_read(&A2D_channel, input, size*sizeof(sample));

/*
* D2A: produce analog output (send signal to the host through RTDX).
* If D2A_channel is enabled, write data to the host.
*/

out_buffer[i]= sin_table[loop];
i++;
if (i== BUFFERLENGTH)
i=0;
if (++loop >7)
loop = 0;

RTDX_write(&D2A1_channel,out_buffer, size*sizeof(sample));

while(RTDX_writing)
{
#if RTDX_POLLING_IMPLEMENTATION
RTDX_Poll(); /* poll comm channel for output */
#endif
}

}
}
/********* ScintTECH Technology Pvt. Ltd. **********/

/***************************************************************************/
/* */
/* R T D X T R A N G . C */
/* */
/* DSP program generate the Trangularewave using lookup table
*/
/* and produces an output stream.Output data are sent to host files */
/* ousing RTDX channels.Interface CCstudio with VB and display */
/* the wave on VB graph screen through RTDX channel */
/***************************************************************************/

#include <std.h>
#include"rtdxtrangcfg.h"
#include "dsk6713_aic23.h"
#include "dsk6713.h"
#include <log.h>
#include <rtdx.h>
#include "target.h"

#define BUFSIZE 64
#define BUFFERLENGTH 64

/* Length of sine wave table */


#define TABLE_SIZE 24

typedef Int sample; /* representation of a data sample from A2D */

/* Global declarations */
sample inp_buffer[BUFSIZE];

Int volume=0;
// = MINVOLUME; /* the scaling factor for volume control */

/* RTDX channels */
RTDX_CreateInputChannel(control_channel);
RTDX_CreateInputChannel(A2D_channel);
RTDX_CreateOutputChannel(D2A1_channel);

int out_buffer[256];
int loop=0;
int i=0;
sample *input = inp_buffer;
Uns size = BUFSIZE;
int trang_table[TABLE_SIZE]=
{ 0, 2000, 4000, 6000, 8000, 10000, 12000, 10000, 8000, 6000,
4000, 2000, 0, -2000, -4000, -6000, -8000, -10000,-12000,-10000,
-8000, -6000 ,-4000, -2000 };//table values
int out_buffer[256]; //output buffer

void main()
{

TARGET_INITIALIZE(); /* Enable RTDX interrupt */


LOG_printf(&trace,"\n Trangularwave example started");

/* enable volume control input channel */


RTDX_enableInput(&control_channel);

while (TRUE)
{

/* Read a new volume when the hosts send it */


if (!RTDX_channelBusy(&control_channel)) {
RTDX_readNB(&control_channel, &volume, sizeof(volume));
}

while (!RTDX_isInputEnabled(&A2D_channel)){
#if RTDX_POLLING_IMPLEMENTATION
RTDX_Poll(); /* poll comm channel for input*/
#endif
}

/*
* A2D: get digitized input (get signal from the host through RTDX).
* If A2D_channel is enabled, read data from the host.
*/
RTDX_read(&A2D_channel, input, size*sizeof(sample));

/*
* D2A: produce analog output (send signal to the host through RTDX).
* If D2A_channel is enabled, write data to the host.
*/

out_buffer[i] = trang_table[loop]; //output to buffer


i++;
if(i==BUFFERLENGTH) i=0; //if @ bottom reinit count
if (++loop > 23)
loop = 0;

RTDX_write(&D2A1_channel,out_buffer, size*sizeof(sample));
printf("hello");

while(RTDX_writing)
{
#if RTDX_POLLING_IMPLEMENTATION
RTDX_Poll(); /* poll comm channel for output */
#endif
}

}
}
/********* ScintTECH Technology Pvt. Ltd. **********/

/***************************************************************************/
/* */
/* R T D X S Q U R E . C */
/* */
/* DSP program generate the Squarewave using lookup table */
/* and produces an output stream.Output data are sent to host files */
/* ousing RTDX channels.Interface CCstudio with VB and display */
/* the wave on VB graph screen through RTDX channel */
/***************************************************************************/

#include <std.h>

#include "rtdxsqurecfg.h"
#include "dsk6713_aic23.h"
#include "dsk6713.h"
#include <log.h>
#include <rtdx.h>
#include "target.h"

#define BUFSIZE 64
#define BUFFERLENGTH 64
#define table_size 8 //size of table=48

typedef Int sample; /* representation of a data sample from A2D */

/* Global declarations */
sample inp_buffer[BUFSIZE];
sample out_buffer[BUFFERLENGTH];

Int volume=0;

/* RTDX channels */
RTDX_CreateInputChannel(control_channel);
RTDX_CreateInputChannel(A2D_channel);
RTDX_CreateOutputChannel(D2A1_channel);

int data_table[table_size]; //data table array


sample *input = inp_buffer;
Uns size = BUFSIZE;
int i=0,j=0;

/*
* ======== main ========
*/
Void main()
{

TARGET_INITIALIZE(); /* Enable RTDX interrupt */

LOG_printf(&trace,"\n Square Wave Example Started");

/* enable volume control input channel */


RTDX_enableInput(&control_channel);

while (TRUE)
{
/* Read a new volume when the hosts send it */
if (!RTDX_channelBusy(&control_channel)) {
RTDX_readNB(&control_channel, &volume, sizeof(volume));
}

while (!RTDX_isInputEnabled(&A2D_channel)){
#if RTDX_POLLING_IMPLEMENTATION
RTDX_Poll(); /* poll comm channel for input*/
#endif
}

/*
* A2D: get digitized input (get signal from the host through RTDX).
* If A2D_channel is enabled, read data from the host.
*/
RTDX_read(&A2D_channel, input, size*sizeof(sample));

/*
* D2A: produce analog output (send signal to the host through RTDX).
* If D2A_channel is enabled, write data to the host.
*/

for(i=0; i<=table_size/2; i++) //set 1st half of buffer


{
data_table[i] = 0x7FFF; //with max value (2^15)-1
}
for(i=table_size/2;i<table_size;i++) //set 2nd half of buffer
{
data_table[i] = -0x8000; //with -(2^15)
}
i = 0;

for(i=0; i<table_size/2; i++)


{
out_buffer[j] = data_table[i]; //output to buffer
j++;
if(j==BUFFERLENGTH) j=0;
}
for(i=table_size/2;i<table_size;i++)
{
out_buffer[j] = data_table[i]; //output to buffer
j++;
if(j==BUFFERLENGTH) j=0;
}
i=0;

RTDX_write(&D2A1_channel,out_buffer, size*sizeof(sample));
printf("hello");

while(RTDX_writing){
#if RTDX_POLLING_IMPLEMENTATION
RTDX_Poll(); /* poll comm channel for output */
#endif
}

}
}
/* *****************************GENERATE NOISE*****************************/

#include"noisecfg.h"
#include"dsk6713.h"
#include "dsk6713_aic23.h" //codec-DSK support file
Uint32 fs=DSK6713_AIC23_FREQ_8KHZ;//set sampling rate
#include "noise_gen.h" //header file for noise sequence
short fb;
shift_reg sreg; //shift reg structure

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;
//int input;

//short amplitude= 2;
short l_output;
sreg.regval = 0xFFFF; //set shift register
fb = 1;
/************************8 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);

while(1)
{

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


channel**************** */

if(sreg.bt.b0) //sequence{1,-1}based on bit b0


l_output = -8000; //scaled negative noise level
else
l_output = 8000; //scaled positive noise level
fb =(sreg.bt.b0)^(sreg.bt.b1); //XOR bits 0,1
fb ^=(sreg.bt.b11)^(sreg.bt.b13);//with bits 11,13 ->fb
sreg.regval<<=1; //shift register 1 bit to left
sreg.bt.b0 = fb; //close feedback path

/*************************8 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,l_output));

/* Close the codec */


//DSK6713_AIC23_closeCodec(hCodec);
}

}
//BPSK.c Generates a binary phase shift keying modulation
// squarewave length = 32 and out_buffer length=256
#include<std.h>
#include"bpskcfg.h"
#include "dsk6713_aic23.h"
#include "dsk6713.h"
#define table_size 4 //size of table=96
#define buffer_size 8

/* Codec configuration settings */


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
0x0001, // 8 DSK6713_AIC23_SAMPLERATE Sample rate control
0x0001 // 9 DSK6713_AIC23_DIGACT Digital interface activation
};

Uint32 fs = DSK6713_AIC23_FREQ_8KHZ; //set sampling rate


int cos_table[buffer_size] = {0,7070,10000,7070,0,-7070,-10000,-7070};
int data_table[table_size]; //data table array
int out_buffer[256];
int sqr_data[256];
int sine_buffer[256];
const int BUFFERLENGTH = 256;
int loop=0,j=0;
int k=0;
int i,l=0,m=0;

void main()
{
DSK6713_AIC23_CodecHandle hCodec;
Int16 sample,msec;

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


DSK6713_init();

/* Start the codec */


hCodec = DSK6713_AIC23_openCodec(0, &config);

/* Set the codec sample rate frequency */


DSK6713_AIC23_setFreq(hCodec,fs);

while(1)
{

puts ("Binary Phase Shift Keying Example Started\n");

/* Generate the Square wave*/


for(i=0; i<=table_size/2; i++) //set 1st half of buffer
data_table[i] = 20000; //with max value (2^15)-1
for(i=table_size/2;i<table_size;i++) //set 2nd half of buffer
data_table[i] = -20000; //with -(2^15)
i=0;

/* store the squarewave in sqr_data*/

for(i=0; i<table_size/2; i++)


{
sqr_data[k] = data_table[i]; //output to buffer
k++;
}
for(i=table_size/2;i<table_size;i++)
{
sqr_data[k] = data_table[i]; //output to buffer
k++;
}
if(k==BUFFERLENGTH) k=0;
i=0;

/* store the sinewave in sine_buffer to display the sine wave on the graph*/
for(m=0;m<buffer_size;m++)
{
sine_buffer[l] = cos_table[m]; //output to buffer
l++; //increment buffer count
}
if(l==BUFFERLENGTH) l=0; //if @ bottom reinit count
//if (++m >buffer_size-1 )
m = 0; //check for end of table

/* show the result in to Oscilloscope*/


for(msec=0;msec<2000;msec++)
{
for(i=0;i<table_size;i++)
{
if(data_table[i]>0)
{
for(sample=0;sample<buffer_size;sample++)
{

/* Send a sample to the left channel */


while (!DSK6713_AIC23_write(hCodec,-1*cos_table[sample]));

/* Send a sample to the right channel */


while (!DSK6713_AIC23_write(hCodec, -1*cos_table[sample]));

}
}
else for(sample=0; sample<buffer_size; sample++)
{

/* Send a sample to the left channel */


while (!DSK6713_AIC23_write(hCodec, cos_table[sample]));

/* Send a sample to the right channel */


while (!DSK6713_AIC23_write(hCodec, cos_table[sample]));
}
}
}

for(i=0;i<table_size;i++)
{
if(data_table[i]>0)
{
for(sample=0;sample<buffer_size;sample++)
{
out_buffer[j]= cos_table[sample];
j++;
}
}
else for(sample=0;sample<buffer_size;sample++)
{
out_buffer[j]= -1*cos_table[sample];
j++;
}
}
if(j==BUFFERLENGTH) j=0;
i=0;
}
}
/************************************************************************
********

Scientech Technologies Pvt.Ltd.


* This Program tells how to perform FFT of a sine wave.*/
/************************************************************************
**********/

/************************************************************************
*********/
#include "fftrtdx2cfg.h"
#include"dsk6713.h"
#include"dsk6713_aic23.h"
#include <rtdx.h>
#include "target.h"
#include<stdio.h>
#include <math.h>
#define BUFSIZE 64
#define MINVOLUME 1
#define PI 3.14159265358979
typedef Int sample; /* representation of a data sample from A2D */
/************************************************************************
*************/

typedef struct {float real,imag;} COMPLEX;

extern COMPLEX w[BUFSIZE];

void FFT(COMPLEX *Y, int n);

int flag = 0; //set to 1 by ISR when iobuffer full


float y[128];
COMPLEX w[BUFSIZE]; //twiddle constants stored in w
COMPLEX samples[BUFSIZE];

/* Global declarations */
sample inp_buffer[BUFSIZE];
float out_buffer[BUFSIZE];

Int volume =MINVOLUME; /* the scaling factor for volume control */

/* RTDX channels */

RTDX_CreateInputChannel(control_channel);
RTDX_CreateInputChannel(A2D_channel);
RTDX_CreateOutputChannel(D2A1_channel);
RTDX_CreateOutputChannel(D2A2_channel);
RTDX_CreateOutputChannel(D2A3_channel);

DSK6713_AIC23_Config config = { \
0x001c, /* 0 DSK6713_AIC23_LEFTINVOL Left line input channel volume */ \
0x001c, /* 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 */ \
};

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

void main()
{

sample *input = inp_buffer;


float *output = out_buffer;
Uns size = BUFSIZE;
int i=0,x1[BUFSIZE];
DSK6713_AIC23_CodecHandle hCodec;

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


*/
DSK6713_init();
/* Start the codec */
hCodec = DSK6713_AIC23_openCodec(0, &config);

/* Set the codec sample rate frequency */


DSK6713_AIC23_setFreq(hCodec,1);

TARGET_INITIALIZE(); /* Enable RTDX interrupt */

/* enable volume control input channel */


RTDX_enableInput(&control_channel);

while (TRUE) {
/* Read a new volume when the hosts send it */
if (!RTDX_channelBusy(&control_channel)) {
RTDX_readNB(&control_channel, &volume, sizeof(volume));
}

while (!RTDX_isInputEnabled(&A2D_channel))
{
#if RTDX_POLLING_IMPLEMENTATION
RTDX_Poll(); /* poll comm channel for input*/
#endif
}

/*
* A2D: get digitized input (get signal from the host through
RTDX).
* If A2D_channel is enabled, read data from the host.
*/
RTDX_read(&A2D_channel,input, size*sizeof(sample));

/*
* Vector Scale: Scale the input signal by the volume factor
to
* produce the output signal.
*/

while(size--)
{

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


{
w[i].real = cos(2*PI*i/(BUFSIZE*2.0));
/*Re component of twiddle constants*/

w[i].imag =-sin(2*PI*i/(BUFSIZE*2.0));
/*Im component of twiddle constants*/
}

for(i=0;i<BUFSIZE;i++)
{
out_buffer[i] = sin(2*PI*10*i/64);/*10- > freq,100 -> sampling
freq*/
/*User can change the frequency and get the result of FFT
according to required frequency*/

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


{
samples[i].real=out_buffer[i]; //buffer with new data
}

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


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

FFT(samples,BUFSIZE); //call function FFT.c

for (i = 0 ; i < BUFSIZE ; i++) //compute magnitude


{

x1[i] = sqrt(samples[i].real*samples[i].real
+ samples[i].imag*samples[i].imag);

}
*output++=x1[i++];
}

size = BUFSIZE;
input = inp_buffer;
output = out_buffer;

/*
* D2A: produce analog output (send signal to the host through
RTDX).
* If D2A_channel is enabled, write data to the host.
*/

RTDX_write(&D2A1_channel,out_buffer, size*sizeof(sample));

RTDX_write(&D2A2_channel,x1, size*sizeof(sample));
while(RTDX_writing)
{
#if RTDX_POLLING_IMPLEMENTATION

RTDX_Poll(); /* poll comm channel for output */


#endif

}}
}

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; //indexof 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 = (BUFSIZE*2)/N; //step between values in twiddle.h// 512
for (i = 0;i < num_stages; i++) //for N-point FFT
{
index = 0;
for (j = 0; j < leg_diff; j++)
{

for (upper_leg = j; upper_leg < N; upper_leg += (2*leg_diff))


{
lower_leg = upper_leg+leg_diff;
temp1.real = (Y[upper_leg]).real + (Y[lower_leg]).real;
temp1.imag = (Y[upper_leg]).imag + (Y[lower_leg]).imag;
temp2.real = (Y[upper_leg]).real - (Y[lower_leg]).real;
temp2.imag = (Y[upper_leg]).imag - (Y[lower_leg]).imag;
(Y[lower_leg]).real = temp2.real*(w[index]).real
-temp2.imag*(w[index]).imag;
(Y[lower_leg]).imag = temp2.real*(w[index]).imag
+temp2.imag*(w[index]).real;
(Y[upper_leg]).real = temp1.real;
(Y[upper_leg]).imag = temp1.imag;
}
index += step;
}
leg_diff = leg_diff/2;
step *= 2;
}
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;
}

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