real time program in tms320c6713

Status
Not open for further replies.

shivani04

Newbie level 4
Joined
May 2, 2012
Messages
5
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,283
Activity points
1,333
i have to calculate harmonic distrotion using tms320c6713 in code composer studio. i want to take real time samples on a supply voltage(sine wave) and then apply fft to finally calculate THD. please if any one can help me out with a real time program.
 

Do u want to calculate how much the signal is distorted or Analyse the signal at different frequencies using FFT algotrithm, If it is the latter case then I can provide my inputs.
 

Do u want to calculate how much the signal is distorted or Analyse the signal at different frequencies using FFT algotrithm, If it is the latter case then I can provide my inputs.

well we do want to calculate the distortion but first we will analyse the signal at different frequencies using fft algorithm and then using the fft values that we get we will calculate the total harmonic distortion.
 
Okay that's good...Well May I know where are you upto as of now, So that I can be needful for the exact matter....
 

Okay that's good...Well May I know where are you upto as of now, So that I can be needful for the exact matter....
#include<stdio.h>
#include<math.h>
#define pi 3.14285714
#define N 4
float rx[N+1]={1.0,1.0,-1.0,-1.0,0.0};
float ix[N+1]={0.0,0.0,0.0,0.0,0.0};
float X[N];
main()
{
int k,n;
float tmp=0.0,tmp1=0.0;
for(k=0;k<N;k++)
{ float ry0=0.0,iy0=0.0;
for(n=0;n<=N;n++)
{
tmp=ry0;
tmp1=iy0;
ry0=rx[n]+tmp*cos(2.0*pi*(float)k/(float)N)-tmp1*sin(2.0*pi*(float)k/(float)N);
iy0=ix[n]+tmp1*cos(2.0*pi*(float)k/(float)N)+tmp*sin(2.0*pi*(float)k/(float)N);
}
X[k]=sqrt(ry0*ry0+iy0*iy0);
printf("\n%f",X[k]);
}
}
this is the dft program we have written for offline program but now we have to implement this by taking real time signal. we have to take the supply voltage and then take its samples and compute the dft(or fft) for the samples.this program is working offline but not with real time inputs.actually we dont know how to take samples of real time input at proper intervals.
 

Ok for real time analysis you need to interface/communicate with the AIC23 codec which is available inbuilt in DSP. Find the datasheet and user manual for the same you will get the code and needful help.
 
we have consulted the user manual bt all we get is the program to input and output the signal bt we are nt able to figure out how to take the samples of the input and then incorporate the dft program
this is the simple input output program bt now hw to take the samples
#include "c:\ccstudio_v3.1\c6000\dsk6713\include\dsk6713.h"
#include "c:\ccstudio_v3.1\c6000\dsk6713\include\dsk6713_aic23.h"

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;

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

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=l_input;
r_output=r_input;

/* 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);
}
 
ok now all u need to do is as follows
1) Step down the voltage of single phase supply to DSK compatible voltage (say 5V) using power resistor

2) Connect the 2V to left jack of DSK(Now your are taking the samples from left channel which is l_input in the program) . Simultaneously connect it to the CRO you can see the 2V singnal.
 
Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…