⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dec5502_fft.c

📁 TMS320VC5502的FFT算法程序验证
💻 C
字号:
/******************************************************************************/
/*  Copyright 2004 by SEED Electronic Technology LTD.                         */
/*  All rights reserved. SEED Electronic Technology LTD.                      */
/*  Restricted rights to use, duplicate or disclose this code are             */
/*  granted through contract.                                                 */
/*                                                                            */
/*  MODULE NAME... IIC and Mcbsp											  */
/*  FILENAME...... 5502_CODEC.c   											  */
/*  DESCRIPTION:  															  */
/*  This is an audio signal sample and play example for CODEC of C5502		  */
/*  This example is that the codec is controled by the IIC and Mcbsp 		  */
/*                                                                            */
/******************************************************************************/

#include <csl.h>
#include <csl_chip.h>
#include <csl_i2c.h>
#include <csl_pll.h>
#include <csl_mcbsp.h>
#include <csl_emif.h>
#include <csl_emifBhal.h>
#include <csl_std.h>

#include "E2PROM_Function.h"
#include "CODEC.h"
#include "i_cmplx.h"
#include <math.h>

#undef  CODEC_ADDR
#define CODEC_ADDR 0x1A
short DataBuffer[1024]={0};
COMPLEX DDataBuffer[512]={0};
Uint32 mod[512];

#define SAMPLELONG 2
Uint16 SampleLong;

// 定义McBSP的句柄
MCBSP_Handle hMcbsp;

				  

/*------------------------------------------------------------------------------------*/
//
// FUNCTION: MAIN
//
/*------------------------------------------------------------------------------------*/
                  
void main(void)
{
    short  DataTemp = 0;		// 暂存采样数据
    Uint16  i = 0;
    Uint16 m=0;
    long n;
    short p,q;
// Initialize CSL library - This is REQUIRED !!! 
    CSL_init();

#if SAMPLELONG==1
	SampleLong =256;
#endif
#if SAMPLELONG==2
	SampleLong =512;
#endif
#if SAMPLELONG==3
	SampleLong =1024;
#endif		
	
// The main frequency of system is 240MHz
// 该频率是为了设置IIC模块的需要设置的,为了使用I2C_setup函数
    PLL_setFreq(1, 0xC, 0, 1, 3, 3, 0);
  
// Initialize I2C, Using parameters in I2C_Setup structure
	I2c_Setup();

// Open McBSP port 1 and get a McBSP type handle
	hMcbsp = MCBSP_open(MCBSP_PORT1,MCBSP_OPEN_RESET);

// Config McBSP	port 1 by use previously defined structure
	Mcbsp_Config(hMcbsp);

// Start McBSP1 
	MCBSP_start(hMcbsp, 
                MCBSP_RCV_START | MCBSP_XMIT_START, 
                0);
    
    inti_AIC();

	    	   
/*------------------------------------------------------------------------------------*/	    	        	   
// Receive the ADC output data of CODEC  
// Then output the received data to DAC of CODEC 
/*------------------------------------------------------------------------------------*/
	/*AD采样*/
	for(i=0;i<SampleLong;i++)
   	{
   		DataBuffer[i] = 0;
   	}
 	for(i=0;i<SampleLong;i++)
   	{
		while(!MCBSP_rrdy(hMcbsp)){};
		DataTemp = MCBSP_read16(hMcbsp);
   		DataBuffer[i] = DataTemp;
   	}
	/*FFT变换*/
	for(i=0;i<(SampleLong/2);i++)
	{
		DDataBuffer[i].real=DataBuffer[2*i];  //short int
    	DDataBuffer[i].imag=DataBuffer[2*i+1];  //short int
	}	
        
	switch(SampleLong)
	{
		case 256:
	    	/*256 point*/
	    	fft256(DDataBuffer,256);
	    	m=0;
       		for(i=0;i<128;i++)
    		{  
           		p=DDataBuffer[i].real;
            	q=DDataBuffer[i].imag;     
             	n=(long)p*(long)p+(long)q*(long)q;
            	mod[m]=sqrt(n); 
            	m++;                           
        	}
            break;
        case 512: 
            /*512 point*/  
            fft512(DDataBuffer,512);
            m=0;
      		for(i=0;i<256;i++)
   			{  
       			p=DDataBuffer[i].real;
       			q=DDataBuffer[i].imag;     
       			n=(long)p*(long)p+(long)q*(long)q;
       			//n=(Uint32)(p*p+q*q);
       			mod[m]=sqrt(n); 
       			m++;                           
   			}
            break;
        case 1024:  
            /*1024 point*/  
            fft1024(DDataBuffer,1024);
            m=0;
        	for(i=0;i<512;i++)
        	{  
            	p=DDataBuffer[i].real;
            	q=DDataBuffer[i].imag;     
            	n=(long)p*(long)p+(long)q*(long)q;
            	//n=(Uint32)(p*p+q*q);
            	mod[m]=sqrt(n);
            	m++;                           
        	}
            break;
	}      
		
    for(;;){}
    /*fft计算结束*/
}

/******************************************************************************/
//	No more
/******************************************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -