This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

C5535 HWAFFT问题

Other Parts Discussed in Thread: TMS320C5535

我使用C5535 自带的HWAFFT,首先是对一组数据进行fft变换,然后是进行IFFT变换,为什么得到的数不一样。代码插入如下:

fft_flag = FFT_FLAG;    
scale_flag = SCALE_FLAG;
hwafft_br(data, data_br, N);
data = data_br;
out_sel = hwafft_8pts(data,scratch,fft_flag, scale_flag);
if (out_sel == OUT_SEL_DATA) {
		result = data;
		}
		else {
			result = scratch;
			}
fft_flag = IFFT_FLAG; 
scale_flag = SCALE_FLAG; 
data = result;
hwafft_br(data, data_br, DATA_LEN_8);
data = data_br;
out_sel = hwafft_8pts(data, scratch, fft_flag, scale_flag);
if (out_sel == OUT_SEL_DATA) {
		result = data;
		}
		else {
			result = scratch;
			}

最后result里面的结果和开始的不一样,是怎么回事

  • 参考一下这个帖子。
    http://www.deyisupport.com/question_answer/dsp_arm/c5000/f/48/t/98875.aspx

     

  • 手册上那个bug是使用512点的fft时才需要改的,但我只用8个点fft,请问也需要改吗? 而且手册说用RAM上的HWAFFT函数,与ROM上的有什么区别吗?

  • 同样遇到该问题,能不能给个OK的代码看看

  • 终于自己找到原因了

    TMS320C5535/34/33/32 Fixed-Point DSP Silicon Errata 这个手册中的这句话:

    The data and scratch buffers can be located in word addresses greater than 0x10000, but the buffers must not cross 16-bit address boundaries (that is, address bits 22–16 must not change).

    很关键,说的是所用要到的buffers最好都在数据空间的同一页,即data_buf,data_br_buf,scratch_buf,均要设置在数据空间的同一页,最后FFT再IFFT计算出来的结果才基本一样

  •  你好,我也在这个问题困了好久,能不能把你的代码发我一份。谢谢

  • 首先是修改linker.cmd 文件代码如下:

    SECTIONS
    {
       .text     >> SARAM1|SARAM2|SARAM0  /* Code                        */
    
       /* Both stacks must be on same physical memory page               */
       .stack    >  DARAM0                /* Primary system stack        */
       .sysstack >  DARAM0                /* Secondary system stack      */
    
       .data     >> DARAM0|SARAM0|SARAM1  /* Initialized vars            */
       .bss      >> DARAM0|SARAM0|SARAM1  /* Global & static vars        */
       .const    >> DARAM0|SARAM0|SARAM1  /* Constant data               */
       .sysmem   >  DARAM0|SARAM0|SARAM1  /* Dynamic memory (malloc)     */
       
        data_br_buf : > DARAM0 /* hwafft Output–bit-reversed data memory allocation */ data_buf : > DARAM0 /* hwafft Input/output static memory allocation */ scratch_buf : > DARAM0 /* hwafft Intermediate/output static memory allocation */
    //上面三句为主要修改的
       
       .switch   >  SARAM2                /* Switch statement tables     */
       .cinit    >  SARAM2                /* Auto-initialization tables  */
       .pinit    >  SARAM2                /* Initialization fn tables    */
       .cio      >  SARAM2                /* C I/O buffers               */
       .args     >  SARAM2                /* Arguments to main()         */
        vectors  >  VECS                  /* Interrupt vectors           */
    
       .ioport   >  IOPORT PAGE 2         /* Global & static ioport vars */
       
    }
    
    /*** Add the following code to the linker command file to call HWAFFT Routines from ROM ***/
     /* HWAFFT Routines ROM Addresses */
       _hwafft_br = 0x00fefe9c;
       _hwafft_8pts = 0x00fefeb0;
       _hwafft_16pts = 0x00feff9f;
       _hwafft_32pts = 0x00ff00f5;
       _hwafft_64pts = 0x00ff03fe;
       _hwafft_128pts = 0x00ff0593;
       _hwafft_256pts = 0x00ff07a4;
       _hwafft_512pts = 0x00ff09a2;
       _hwafft_1024pts = 0x00ff0c1c;
  • 然后我做的是128点的FFT以及IFFT,代码如下:

    #include <stdio.h>
    #include "ezdsp5535.h"
    
    /*include the header file for hwafft*/
    #include "hwafft.h"
    /* Supplementary of Macro define */
    #define  N  (DATA_LEN_128)           /* Performs 64 points FFT or IFFT */
    #define ALIGNMENT 2*N               // ALIGNS data_br_buf to an address with log2(4*N) zeros 
                                        // in the least significant bits of the byte address
    #pragma DATA_SECTION(data_br_buf, "data_br_buf"); // Allocation to Section: 
    #pragma DATA_ALIGN (data_br_buf, ALIGNMENT);       //"data_br _buf : > DARAM" in Linker CMD File
    Int32 data_br_buf[N];
    #pragma DATA_SECTION(data_buf, "data_buf");  //Static Allocation to Section: 
    Int32 data_buf[N];              //"data_buf : > DARAM" in Linker CMD File
    #pragma DATA_SECTION(scratch_buf, "scratch_buf"); //Static Allocation to Section: 
    Int32 scratch_buf[N];               //"scratch_buf : > DARAM" in Linker CMD File
    
    void main(void) {
    	Int32 *data_br = data_br_buf;
    	Int32 *data = data_buf;
    	Int32 *scratch = scratch_buf;
    	Uint16 fft_flag;
    	Uint16 scale_flag;
    	Uint16 out_sel;
    	Int32 *result;
    	Int16 Real_Part;
    	Int16 Imaginary_Part;
    	Uint16 k;
    	FILE *fp;
    	/* 64-pt Complex Input Vector
    	 * Test data:sinewave 
    	 **/
    	Int32 invec_fft_128pts[] = {
            0x00000000, 0x10b40000, 0x21200000, 0x30fb0000, 0x3fff0000, 0x4dea0000, 0x5a810000, 0x658b0000,
            0x6ed80000, 0x763f0000, 0x7ba10000, 0x7ee50000, 0x7ffd0000, 0x7ee50000, 0x7ba10000, 0x76ef0000,
            0x6ed80000, 0x658b0000, 0x5a810000, 0x4dea0000, 0x3fff0000, 0x30fb0000, 0x21200000, 0x10b40000,
            0x00000000, 0xef4c0000, 0xdee00000, 0xcf060000, 0xc0020000, 0xb2160000, 0xa57f0000, 0x9a750000,
            0x91280000, 0x89c10000, 0x845f0000, 0x811b0000, 0x80020000, 0x811b0000, 0x845f0000, 0x89c10000,
            0x91280000, 0x9a760000, 0xa57f0000, 0xb2160000, 0xc0020000, 0xcf060000, 0xdee00000, 0xef4c0000,
            0x00000000, 0x10b40000, 0x21200000, 0x30fb0000, 0x3fff0000, 0x4dea0000, 0x5a810000, 0x658b0000,
            0x6ed80000, 0x763f0000, 0x7ba10000, 0x7ee50000, 0x7ffd0000, 0x7ee50000, 0x7ba10000, 0x76ef0000,
            0x00000000, 0x10b40000, 0x21200000, 0x30fb0000, 0x3fff0000, 0x4dea0000, 0x5a810000, 0x658b0000,
            0x6ed80000, 0x763f0000, 0x7ba10000, 0x7ee50000, 0x7ffd0000, 0x7ee50000, 0x7ba10000, 0x76ef0000,
            0x6ed80000, 0x658b0000, 0x5a810000, 0x4dea0000, 0x3fff0000, 0x30fb0000, 0x21200000, 0x10b40000,
            0x00000000, 0xef4c0000, 0xdee00000, 0xcf060000, 0xc0020000, 0xb2160000, 0xa57f0000, 0x9a750000,
            0x91280000, 0x89c10000, 0x845f0000, 0x811b0000, 0x80020000, 0x811b0000, 0x845f0000, 0x89c10000,
            0x91280000, 0x9a760000, 0xa57f0000, 0xb2160000, 0xc0020000, 0xcf060000, 0xdee00000, 0xef4c0000,
            0x00000000, 0x10b40000, 0x21200000, 0x30fb0000, 0x3fff0000, 0x4dea0000, 0x5a810000, 0x658b0000,
            0x6ed80000, 0x763f0000, 0x7ba10000, 0x7ee50000, 0x7ffd0000, 0x7ee50000, 0x7ba10000, 0x76ef0000
        };
        Int32 invec_fft_64pts[] = {
        	0x00000000,0x23FB0000,0x45100000,0x60930000,0x744B0000,0x7EA30000,0x7EC40000,0x74AC0000,
            0x612B0000,0x45D40000,0x24DB0000,0x00E90000,0x231B0000,0x444B0000,0x5FF90000,0x73E90000,
            0x7E800000,0x7EE40000,0x750B0000,0x61C30000,0x46970000,0x25BB0000,0x01D30000,0x223A0000,
            0x43850000,0x5F5E0000,0x73850000,0x7E5C0000,0x7F020000,0x75690000,0x62590000,0x475A0000,
            0x26990000,0x02BC0000,0x21590000,0x42BE0000,0x5EC10000,0x73200000,0x7E360000,0x7F1E0000,
            0x75C50000,0x62ED0000,0x481B0000,0x27780000,0x03A60000,0x20780000,0x41F70000,0x5E240000,
            0x72B90000,0x7E0E0000,0x7F380000,0x76200000,0x63810000,0x48DB0000,0x28550000,0x048F0000,
            0x1F960000,0x412E0000,0x5D850000,0x72510000,0x7DE50000,0x7F510000,0x76790000,0x64130000
        };
        Int32 invec_fft_8pts[] = {0x0,0x23fb0000,0x45100000,0x60930000,0x744b0000,0x7ea30000,0x7ec40000,0x74ac0000};
    	// Assign pointers to static memory allocations
    	data_br = data_br_buf;
    	data = data_buf;
    	scratch = scratch_buf;
    	data = invec_fft_128pts; // 128-pt Complex Input Vector
    //	printf("原始数据:\n");
    //	for ( k = 0;k < N; k++){
    //		Real_Part = (data[k]>>16); 
    //		Imaginary_Part = (data[k]&(0x0000FFFF));
    //		printf(" The %x real number is %x ",k,Real_Part);
    //		printf(" The %x imaginary number is %x\n",k,Imaginary_Part);
    //	}
    	
    	// HWAFFT flags:
    	fft_flag = FFT_FLAG;     // HWAFFT to perform FFT (not IFFT)
    	scale_flag = SCALE_FLAG; // HWAFFT to scale by 2 after each butterfly stage
    	
    	asm ("\tNOP");
    	/* Bit-Reverse N-point data, Store into data_br,
    	 *  data_br aligned to log2(4 * N)-least significant binary zeros*/
    	hwafft_br(data, data_br, N); /* bit-reverse input data,Destination buffer aligned */
    	asm ("\tNOP");
    	//data = data_br;
    	memcpy(data_buf,data_br,sizeof(data_br_buf));
    	data = data_buf;
    	asm ("\tNOP");
    //	printf("FFT位反转后数据:\n");
    //	for ( k = 0;k < N; k++){
    //		Real_Part = (data[k]>>16); 
    //		Imaginary_Part = (data[k]&(0x0000FFFF));
    //		printf(" The %x real number is %x ",k,Real_Part);
    //		printf(" The %x imaginary number is %x\n",k,Imaginary_Part);
    //	}
    	/* Compute 8-point FFT, scaling enabled. */
    	out_sel = hwafft_128pts(data,scratch,fft_flag, scale_flag);
    	asm ("\tNOP");
    	if (out_sel == OUT_SEL_DATA) {
    		result = data;
    		}
    	else 
    		{
    			result = scratch;
    		}
    //	printf("FFT变换结果:\n");
    //	for ( k = 0; k < N; k++)
    //	{
    //		Real_Part = result[k]>>16; 
    //		Imaginary_Part = result[k]&(0x0000FFFF);
    //		printf(" The %x real number is %x ",k,Real_Part);
    //		printf(" The %x imaginary number is %x\n",k,Imaginary_Part);
    //	}
    	// HWAFFT flags:
    	fft_flag = IFFT_FLAG; // HWAFFT to perform IFFT (not FFT)
    	scale_flag = SCALE_FLAG; // HWAFFT to scale by 2 after each butterfly stage
    	
    	data = result;
    	data_br = data_br_buf;
    	/* Bit-Reverse N-point data, Store into data_br */	
    	hwafft_br(data, data_br, N); /* bit-reverse input data,Destination buffer aligned */
        data = data_br;
    //    printf("IFFT变换前位反转数据\n");
    //	for ( k = 0;k < N; k++)
    //	{
    //	  Real_Part = (data[k]>>16); 
    //	  Imaginary_Part = (data[k]&(0x0000FFFF));
    //	  printf(" The %x real number is %x ",k,Real_Part);
    //	  printf(" The %x imaginary number is %x\n",k,Imaginary_Part);
    //    }
    	asm ("\tNOP");
    	/* Compute 128-point IFFT, scaling enabled. */
    	out_sel = hwafft_128pts(data, scratch, fft_flag, scale_flag);
    	asm ("\tNOP");
    	if (out_sel == OUT_SEL_DATA) {
    		result = data;
    		}
    		else {
    			result = scratch;
    			}
    	memcpy(data_buf,result,sizeof(data_buf));
    	printf("IFFT结果:\n");
    	for ( k = 0; k < N; k++){
    		Real_Part = (result[k]>>16)*N; 
    		Imaginary_Part = (result[k]&(0x0000FFFF))*N;
    		printf(" The %x real number is %x ",k,Real_Part);
    		printf(" The %x imaginary number is %x\n",k,Imaginary_Part);
    		printf(" The %d number is %x\n",k,data_buf);
    	}
    //	printf("Hello World!\n");
    }
    
  • 你好,问一下,我在做1024点FFT的时候  用汇编调用_hwafft_br函数时一切正常但是每次调用_hwafft_1024pts都会将我设置的data_buf和scratch_buf清零,这会是什么原因

  •  我是用的C语言调用HWAFFT_xxpts函数进行FFT变换的,没有直接用汇编语言调用。data_buf和scratch_buf清零是什么意思,是运行后没有结果吗?