Sign in

username:

password:



Not a member?

Search c54x



Search tips

Subscribe to c54x



c54x by Keywords

5409 | 5416 | AD5 | ADC | BIOS | Boot | Booting | Bootloader | C540 | C5402 | C5409 | C5416 | CCS | Codec | DMA | Dmad | DSK | DSKPlus | Dsplib | EVM | FFT | FIR | Flash | GPIO | HPI | Initialization | Interrupt | JTAG | LOG_printf | MCBSP | RFFT | RTDX | Sampling | STLM | UART | VC540

Discussion Groups

Discussion Groups | TMS320C54x | How to produce output file (.dat) using DSP

Technical discussions about the TI C54x DSPs (including the c5401, c5402, c5402a, c5404, c5407, c5409, c5409a, c5410, c5410a, c5416, c5420, c5421, c5441, c549, c5470 and c5471).

  

Post a new Thread

How to produce output file (.dat) using DSP - bayu...@yahoo.com - Apr 11 7:01:35 2008



Hi!
I'm working on DMT simulation using TMS320C5416 as my final project. I have a problem on making
output file. I build this small chunk of program using turbo C and I put it on 5416 "DSK
CCStudio v3.1". I can show the output on CCStudio, but the output file always returns
empty. The output file exists, but it's empty.
The program list is as the following:

----------------------------------------------------------------------------
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <time.h>

#define B 4
#define C 16
#define S 64
#define L 16
#define noise 0.0001
#define sN 0
#define N 16
#define F 32

int (*bits);
FILE *fp;

void a2d()
{
int i,j,k,sisa,hasil,bil,(*p)[B];
float (*z),max,min,temp,qinterval,bagi,(*q),(*x),(*mutlak);

x=malloc (S * sizeof(float));
if(!(fp = fopen("handel.txt", "r")))
    {
      exit(EXIT_FAILURE);
    }
else
	{
	for(i=0; i<S; i++)
		fscanf(fp,"%f", &x[i]);
	}
	fclose(fp);
z=malloc (S * sizeof(float));
mutlak=malloc (S * sizeof(float));
for(i=0;i<S;i++)
	{
	if (x[i]<0)
		mutlak[i]=(-1)*x[i];
	else
		mutlak[i]=x[i];
	z[i]=mutlak[i]/(16-1);
	}
max=z[0];
for(i=0;i<S;i++)
	{
	if(z[i]>max)
		max=z[i];
	}
qinterval=2*max;
q=malloc (S * sizeof(float));
bits=malloc (B* S * sizeof(int));
if(B<=1)
	{
	for (i=0;i<S;i++)
		{
		if (x[i]<=0)
		bits[i]=0;
		else
		bits[i]=1;
		}
	}
else
	{
	min=x[0];
	for(i=1;i<S;i++)
		{
		if(x[i]<min)
			min=x[i];
		}
	for(i=0;i<S;i++)
		{
		temp=x[i]-min;
		bagi=temp/qinterval;
		if (bagi-abs(bagi) <0.5)
			bagi=floor(bagi);
		else
			bagi=ceil(bagi);
		q[i]=bagi*qinterval;
		}
p=malloc (B*pow(2,B) * sizeof(int));
	for (k=0;k<pow(2,B);k++)
 		{
		bil=k;
		for (i=B-1;i>=0;i--)
			{
			hasil=bil/2;
			sisa=bil%2;
			p[k][i]=sisa;
			bil=hasil;
			}
		}
for (i=0;i<S;i++)
	for (k=0;k<pow(2,B);k++)
		if (floor(q[i]/qinterval)==k)
			for (j=0;j<B;j++)
			bits[B*i+j]=p[k][j];
	}

if(!(fp = fopen("p.txt", "w")))
	puts("error");
else
{
for(i=0; i<pow(2,B); i++)
    {
    fprintf(fp, "%d%d%d%d \n", p[i][0], p[i][1], p[i][2], p[i][3]);
    printf("%d%d%d%d \n", p[i][0], p[i][1], p[i][2], p[i][3]);
    }
fclose(fp);
}
free(p);
free(bits);
free(z);
free(q);
free(x);
free(mutlak);
}

main()
{
a2d();
}

--------------------------------------------------------------------------

It's working on turbo C and CCStudio, both result:

--------
0000 
0001 
0010 
0011 
0100 
0101 
0110 
0111 
1000 
1001 
1010 
1011 
1100 
1101 
1110 
1111 
--------

I suppose the problem maybe in include library or the 'fprintf' command, but it's just my
guess. Cab anyone help me to make an unempty output file?

Thank You very much.

Bayu P.

------------------------------------

Check Out Industry's First Single-Chip, Multi-Format, Real-Time HD Video Transcoding Solution
for Commercial & Consumer End Equipment: www.ti.com/dm6467



(You need to be a member of c54x -- send a blank email to c54x-subscribe@yahoogroups.com )