DSP综合性实验——任意信号发生器实验
{
unsigned int i=0,j=0,k=0;
/*****************新增函数段*****************/
dt=2*pi*F0/Fs; for(j=1;j<=T;j++) {
for(t=0,i=N/T*(j-1);i<=N/T*j;i++,t-=dt) //若步进反号,则锯齿波方向改变 {
saw[i]=t;
saw[i+N/T]=0; } }
for(i=0;i { dacdata[i]=saw[i]*T; outbuffer[i]=amp*dacdata[i]+L; } // Initialize CSL library - This is REQUIRED !!! CSL_init(); // The main frequency of system is 240MHz // 该频率是为了设置IIC模块的需要设置的,为了使用I2C_setup函数 PLL_setFreq(1, 0xC, 0, 1, 3, 3, 0); //EMIF初始化 Emif_Config(); // 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); //I2C初始化 I2C_cofig(); //CODEC寄存器初始化 inti_AIC(); 第 16 页 共 42 页 DSP综合性实验——任意信号发生器实验 /*------------------------------------------------------------------------------------*/ // Receive the ADC output data of CODEC // Then output the received data to DAC of CODEC /*------------------------------------------------------------------------------------*/ while(1) { for(i=0;i j=j+1; MCBSP_write16(hMcbsp, outbuffer[i]); k=k+1; } for(i=0;i /******************************************************************************/ // No more /******************************************************************************/ 5.可调正弦波 添加Gel文件,使输入频率和幅度可调,便于观察 第 17 页 共 42 页 DSP综合性实验——任意信号发生器实验 #include #include #include //#include \#include \ #define pi 3.14159265 #define N 360 #define L 0 //调节直流分量 volatile int Amp; //调节幅度 volatile int Fre; //调节频率 #pragma DATA_SECTION(output1,\ //存放sin数据,浮点型 double output1[N]; #pragma DATA_SECTION(output,\ //存放sin数据,定点型 int output[N]; #undef CODEC_ADDR #define CODEC_ADDR 0x1A // 定义McBSP的句柄 MCBSP_Handle hMcbsp; /*------------------------------------------------------------------------------------*/ // // FUNCTION: MAIN // 第 18 页 共 42 页 DSP综合性实验——任意信号发生器实验 /*------------------------------------------------------------------------------------*/ void main(void) { Uint16 i,k=0; int amp=(int)Amp/pi; int Nx=(int)32000/Fre; //Fs为32000Hz,Nx为抽样点数 float input0=0,x1; float a,b,c,d,e,f,g,h,ii,step;//step为角度步长 step=360.0/Nx; // Nx为360度内取样点数 /*****************新增函数段****************/ for(i=0;i<=Nx-1;i++) { float angle,xx; angle=input0+step*i; x1=pi*angle/180; //角度转换为弧度 xx=x1*x1; a=1-xx/16/17;b=1-xx/14/15*a;c=1-xx/12/13*b;d=1-xx/10/11*c;e=1-xx/8/9*d;f=1-xx/6/7*e;g=1-xx/4/5*f;h=1-xx/2/3*g;ii=x1*h; // g=x1*(1-xx/2/3*(1-xx/4/5*(1-xx/6/7*(1-xx/8/9*(1-xx/10/11*(1-xx/12/13*(1-xx/14/15*(1-xx/16/17))))))));//数学总公式 // fprintf(stdout,\fprintf(stdout,\ \ //输出计算的正弦波的数值,x2=e output1[i]=amp*ii; //利用泰勒级数计算出正弦波的数值,存放到output1中 output[i]=output1[i]+L; //除以128为使输出不溢出 } // Initialize CSL library - This is REQUIRED !!! CSL_init(); // The main frequency of system is 240MHz // 该频率是为了设置IIC模块的需要设置的,为了使用I2C_setup函数 PLL_setFreq(1, 0xC, 0, 1, 3, 3, 0); //EMIF初始化 Emif_Config(); // 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 第 19 页 共 42 页 DSP综合性实验——任意信号发生器实验 Mcbsp_Config(hMcbsp); //I2C初始化 I2C_cofig(); //CODEC寄存器初始化 inti_AIC(); /*------------------------------------------------------------------------------------*/ // Receive the ADC output data of CODEC // Then output the received data to DAC of CODEC /*------------------------------------------------------------------------------------*/ while(1) { while(!MCBSP_xrdy(hMcbsp)) {}; MCBSP_write16(hMcbsp, output[k]); //左声道输出 while(!MCBSP_xrdy(hMcbsp)) {}; MCBSP_write16(hMcbsp, output[k]); //右声道输出 k=k+1; if (k>=Nx) k=k%Nx; } } /******************************************************************************/ // No more /******************************************************************************/ Gel文件: Amp.gel: menuitem \ slider gain(1,1000,1,1,gainparameter) //增益范围从1-1000 { Amp=gainparameter; } Fre.gel: 第 20 页 共 42 页