久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 3895|回復: 1
收起左側

串口向28335發送數據DSP數字信號FFT實現

[復制鏈接]
ID:237028 發表于 2017-10-25 14:55 | 顯示全部樓層 |閱讀模式

//###########################################################################
//
// FILE:    Example_2833x_FFT.c
//
// TITLE:   FFT
//
// ASSUMPTIONS:
//
//    This program requires the DSP2833x header files.
//
//    Two different examples are included. Select the example
//    to execute before compiling using the #define statements
//    found at the top of the code.
//
//    As supplied, this project is configured for "boot to SARAM"
//    operation.  The 2833x Boot Mode table is shown below.
//    For information on configuring the boot mode of an eZdsp,
//    please refer to the documentation included with the eZdsp,
//
//       $Boot_Table:
//
//         GPIO87   GPIO86     GPIO85   GPIO84
//          XA15     XA14       XA13     XA12
//           PU       PU         PU       PU
//        ==========================================
//            1        1          1        1    Jump to Flash
//            1        1          1        0    SCI-A boot
//            1        1          0        1    SPI-A boot
//            1        1          0        0    I2C-A boot
//            1        0          1        1    eCAN-A boot
//            1        0          1        0    McBSP-A boot
//            1        0          0        1    Jump to XINTF x16
//            1        0          0        0    Jump to XINTF x32
//            0        1          1        1    Jump to OTP
//            0        1          1        0    Parallel GPIO I/O boot
//            0        1          0        1    Parallel XINTF boot
//            0        1          0        0    Jump to SARAM            <- "boot to SARAM"
//            0        0          1        1    Branch to check boot mode
//            0        0          1        0    Boot to flash, bypass ADC cal
//            0        0          0        1    Boot to SARAM, bypass ADC cal
//            0        0          0        0    Boot to SCI-A, bypass ADC cal
//                                              Boot_Table_End$
//
// DESCRIPTION:
//   FFT變換  數字信號處理
//
//
//
//###########################################################################
// $TI Release: DSP2833x/DSP2823x Header Files V1.20 $
// $Release Date: August 1, 2008 $
//###########################################################################

#include "DSP28x_Project.h"     // Device Headerfile and Examples Include File
#include"math.h"

#define PI 3.1415926
#define SAMPLENUMBER 512
Uint16    *ExRamStart = (Uint16 *)0x100000;
#define FIRNUMBER 25
int16 INPUT[SAMPLENUMBER];
// Prototype statements for functions found within this file.
void scib_echoback_init(void);
void scib_fifo_init(void);
void scib_xmit(int a);
void scib_msg(char *msg);

// Global counts used in this example
Uint16 LoopCount;
Uint16 ErrorCount;

  int16 InputWave[SAMPLENUMBER];

void InitForFFT();
void FFT(float dataR[SAMPLENUMBER],float dataI[SAMPLENUMBER]);

void MakeWave();
//void FFT(float dataR[SAMPLENUMBER],float dataI[SAMPLENUMBER]);
//#pragma DATA_SECTION(INPUT, ".INPUT")
int INPUT[SAMPLENUMBER];
int DATA[SAMPLENUMBER];
int16 DATA2[SAMPLENUMBER];
//int INPUT[SAMPLENUMBER],DATA[SAMPLENUMBER];
float fWaveR[SAMPLENUMBER],fWaveI[SAMPLENUMBER],w[SAMPLENUMBER];
float sin_tab[SAMPLENUMBER],cos_tab[SAMPLENUMBER];




void MakeWave()
{
        int i;
       
        for ( i=0;i<SAMPLENUMBER;i++ )
        {
                INPUT[i]=sin(PI*2*i/SAMPLENUMBER*3)*1024;//+sin(PI*2*i/SAMPLENUMBER*8)*100+sin(PI*2*i/SAMPLENUMBER*60)*1024;// ---1024
        }
}


void main(void)
{


   int i;
    Uint16 ReceivedChar[10];
            Uint16 cnt;
                        Uint16 cntf;
                        int16 sendchar;
                        int n;

// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the DSP2833x_SysCtrl.c file.
   InitSysCtrl();
   InitScibGpio();

// Step 2. Initalize GPIO:
// This example function is found in the DSP2833x_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
   // InitGpio(); Skipped for this example

// Step 3. Clear all interrupts and initialize PIE vector table:
// Disable CPU interrupts
   DINT;

// Initialize PIE control registers to their default state.
// The default state is all PIE interrupts disabled and flags
// are cleared.
// This function is found in the DSP2833x_PieCtrl.c file.
   InitPieCtrl();

// Disable CPU interrupts and clear all CPU interrupt flags:
   IER = 0x0000;
   IFR = 0x0000;

// Initialize the PIE vector table with pointers to the shell Interrupt
// Service Routines (ISR).
// This will populate the entire table, even if the interrupt
// is not used in this example.  This is useful for debug purposes.
// The shell ISR routines are found in DSP2833x_DefaultIsr.c.
// This function is found in DSP2833x_PieVect.c.
   InitPieVectTable();

//*ExRamStart=0x1111;
// Step 4.

    LoopCount = 0;
    ErrorCount = 0;
    cnt=0;
         cntf=0;
        n=0;
//        flag=0;
    scib_fifo_init();           // Initialize the SCI FIFO
    scib_echoback_init();  // Initalize SCI for
     InitForFFT();

    ScibRegs.SCIFFRX.bit.RXFFOVRCLR=1;

for(;;)
{  
   if(cnt==SAMPLENUMBER)
      {   cntf=1;}
    else
           { cntf=0; }

   while(ScibRegs.SCIFFRX.bit.RXFFST !=1) { } // wait for XRDY =1 for empty state


      sendchar= ScibRegs.SCIRXBUF.all;
if(cntf==1)
{        //MakeWave();
        for ( i=0;i<SAMPLENUMBER;i++ )
        {   
                fWaveR[i]=InputWave[i];//INPUT[i];//
                fWaveI[i]=0.0f;
                w[i]=0.0f;
        }
        FFT(fWaveR,fWaveI);
        for ( i=0;i<SAMPLENUMBER;i++ )
        {
                DATA[i]=w[i];
      //  sendchar=DATA[i];
        //        scib_xmit( DATA[i]);
        }
cnt=0;
      for(i=0;i<SAMPLENUMBER;i++)
           { InputWave[i]=0;
                           //DATA[i]=0;
                  }     

}
else
{
  if(sendchar==0x002C)
  {
    if (ReceivedChar[0]==0x002D)
         {
           for(i=1;i<n;i++)
            InputWave[cnt]+=((ReceivedChar[i]-48)*pow(10,n-i-1));
          InputWave[cnt]=0x10000-InputWave[cnt];
          }
     else
        {for(i=0;i<n;i++)
        InputWave[cnt]+=((ReceivedChar[i]-48)*pow(10,n-i-1));
        }
  n=0;
  for(i=0;i<10;i++)
         { ReceivedChar[i]=0;
         }
   cnt++;
        }
  else
  {ReceivedChar[n]=  sendchar;
   n++;

   }

}

scib_xmit(sendchar);  
      LoopCount++;


}

}


/////////////////////////////////////////////////////
void FFT(float dataR[SAMPLENUMBER],float dataI[SAMPLENUMBER])
{
        int x0,x1,x2,x3,x4,x5,x6,x7,xx;  
        int i,j,k,b,r,m,L;  
        float TR,TI,temp;
       
        /********** following code invert sequence ************/
        /********** 實現倒序 ************/   
        for ( i=0;i<SAMPLENUMBER;i++ )
         {   x7=SAMPLENUMBER;   
             x0=x1=x2=x3=x4=x5=x6=0;
         x0=i&0x01;
         x1=(i/2)&0x01;
         x2=(i/4)&0x01;
         x3=(i/8)&0x01;
         x4=(i/16)&0x01;
         x5=(i/32)&0x01;
         x6=(i/64)&0x01;
         xx=x0*x7/2+x1*x7/4+x2*x7/8+x3*x7/16+x4*x7/32+x5*x7/64+x6;   
         dataI[xx]=dataR[i];/*虛部此時暫時沒用,暫時做緩存數組*/  
         }
        for ( i=0;i<SAMPLENUMBER;i++ )
        {
                dataR[i]=dataI[i]; dataI[i]=0;
        }
   /**************計算*SAMPLENUMBER=2^(m)中的m******************/
    m=0;
    for (j=SAMPLENUMBER;j>1;j=j/2)
    {m=m+1;}
    //printf("%d\n",m);
  /************** following code FFT *******************/
        for ( L=1;L<=m;L++ )
        { /* for(1) */
                b=1; i=L-1;
                while ( i>0 )
                {
                        b=b*2; i--;
                } /* b= 2^(L-1) */
                for ( j=0;j<=b-1;j++ ) /* for (2) */
                {   r=1; i=m-L;     
                    while ( i>0 )      /* r=2^(m-L)*j,用于計算Wr */   
                     {r=r*2; i--;}   
                      r=r*j;

                        for ( k=j;k<SAMPLENUMBER;k=k+2*b ) /* for (3) */
                        {
                                TR=dataR[k]; TI=dataI[k]; temp=dataR[k+b];
                                dataR[k]=dataR[k]+dataR[k+b]*cos_tab[r]+dataI[k+b]*sin_tab[r];
                                dataI[k]=dataI[k]-dataR[k+b]*sin_tab[r]+dataI[k+b]*cos_tab[r];
                                dataR[k+b]=TR-dataR[k+b]*cos_tab[r]-dataI[k+b]*sin_tab[r];
                                dataI[k+b]=TI+temp*sin_tab[r]-dataI[k+b]*cos_tab[r];
                        } /* END for (3) */
                } /* END for (2) */
        } /* END for (1) */
        for ( i=0;i<SAMPLENUMBER/2;i++ )
        {
                w[i]=sqrt(dataR[i]*dataR[i]+dataI[i]*dataI[i]);
        }   
} /* END FFT */




void InitForFFT()
{
        int i;
       
        for ( i=0;i<SAMPLENUMBER;i++ )
        {
                sin_tab[i]=sin(PI*2*i/SAMPLENUMBER);
                cos_tab[i]=cos(PI*2*i/SAMPLENUMBER);
        }
}


////////////////////////////////////////////////////



void scib_echoback_init()
{
    // Note: Clocks were turned on to the Scib peripheral
    // in the InitSysCtrl() function

        ScibRegs.SCICCR.all =0x0007;   // 1 stop bit,  No loopback
                                   // No parity,8 char bits,
                                   // async mode, idle-line protocol
        ScibRegs.SCICTL1.all =0x0003;  // enable TX, RX, internal SCICLK,
                                   // Disable RX ERR, SLEEP, TXWAKE
        ScibRegs.SCICTL2.all =0x0003;
        ScibRegs.SCICTL2.bit.TXINTENA =1;
        ScibRegs.SCICTL2.bit.RXBKINTENA =1;
        #if (CPU_FRQ_150MHZ)
              ScibRegs.SCIHBAUD    =0x0001;  // 9600 baud @LSPCLK = 37.5MHz.
              ScibRegs.SCILBAUD    =0x00E7;
        #endif
        #if (CPU_FRQ_100MHZ)
      ScibRegs.SCIHBAUD    =0x0001;  // 9600 baud @LSPCLK = 20MHz.
      ScibRegs.SCILBAUD    =0x0044;
        #endif
        ScibRegs.SCICTL1.all =0x0023;  // Relinquish SCI from Reset
}

// Transmit a character from the SCI
void scib_xmit(int a)
{
    while (ScibRegs.SCIFFTX.bit.TXFFST != 0) {}
    ScibRegs.SCITXBUF=a;

}

void scib_msg(char * msg)
{
    int i;
    i = 0;
    while(msg[i] != '\0')
    {
        scib_xmit(msg[i]);
        i++;
    }
}

// Initalize the SCI FIFO
void scib_fifo_init()
{
    ScibRegs.SCIFFTX.all=0xE040;
    ScibRegs.SCIFFRX.all=0x204f;
    ScibRegs.SCIFFCT.all=0x0;

}




//===========================================================================
// No more.
//===========================================================================


serialFFT.rar

3.37 MB, 下載次數: 27, 下載積分: 黑幣 -5

回復

使用道具 舉報

ID:380348 發表于 2018-7-28 22:33 | 顯示全部樓層
樓主這個是驗證過的?
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 啪啪毛片| 久久久激情 | 国产精品美女久久久久久久网站 | 国产精品自产拍在线观看蜜 | 国产精品久久av | 亚洲aⅴ | 久久网站黄 | 亚洲人成人一区二区在线观看 | 精品九九| 国产高清久久久 | 中文字幕av在线 | 天天澡天天操 | 欧美男人天堂 | 日本一区二区不卡 | 国产黄色大片 | 日韩高清中文字幕 | 中文字幕在线一区二区三区 | 久久久区 | 中文字幕一区在线观看视频 | 精品国产精品三级精品av网址 | 香蕉一区二区 | 黑人精品 | h视频在线观看免费 | 麻豆国产一区二区三区四区 | 久久久久国产精品 | 天天操夜夜操 | 精品亚洲一区二区三区 | 天天拍天天色 | 亚洲国产高清在线观看 | 国产在线一区二区三区 | 国产成人免费视频网站高清观看视频 | 久久九九网站 | 欧美视频三区 | 日韩视频在线免费观看 | 亚洲精品电影 | 亚洲精品一区二区三区四区高清 | 久久免费高清视频 | 日本免费在线观看视频 | 天天干狠狠干 | 免费xxxx大片国产在线 | 精品亚洲一区二区三区四区五区 |