Quantcast
Channel: C2000™︎ 微控制器论坛 - 最近的话题
Viewing all articles
Browse latest Browse all 12114

关于28335 ADC+FFT

$
0
0

您好,我对controsuite中的ti\controlSUITE\libs\dsp\FPU\v1_40_00_00\examples_ccsv5\2833x_rfft_adc_rt例程进行了一些修改,ad采样配置为单通道每次采样中断,在adc_isr中每次新采样的数据放在数组的最后一位,同时原来数组中的元素都向左移动一位,去掉第一个元素,当中断进行了128次后,FFTFLAG置1,进行fft,现在的问题是FFTFLAG始终保持1不变,无法清零,ADC可以正常运行,但fft无法运行,请各位高手帮我看看,代码如下:

//#include "DSP28x_Project.h"
#include "DSP2833x_Device.h"     //// DSP2833x Headers
#include "DSP2833x_Examples.h"   //// DSP2833x Examples
#include "fpu_rfft.h"
#include "AD9956.h"


#define RFFT_STAGES     10
#define RFFT_SIZE       (1 << RFFT_STAGES)

#define ADC_BUF_LEN         RFFT_SIZE   // ADC buffer length

RFFT_ADC_F32_STRUCT rfft_adc;
RFFT_F32_STRUCT rfft;


float RFFToutBuff[RFFT_SIZE];                //Calculated FFT result
float RFFTF32Coef[RFFT_SIZE];        //Coefficient table buffer
float RFFTmagBuff[RFFT_SIZE/2+1];      //Magnitude of frequency spectrum

//--- Global Variables
uint16_t AdcBuf[ADC_BUF_LEN];                   // ADC buffer allocation

volatile uint16_t FFTStartFlag = 0;         // One frame data ready flag


int counter = 0;                                        // ADC interrupt counter



/***************************************************************************/
// Prototype statements for functions found within this file.
interrupt void adc_isr(void);
/**********************************************************************
* Function: main()
*
* Description: Main function for C2833x Real-time RFFT
**********************************************************************/
void main(void)
{
    uint16_t i,j;


//--- CPU Initialization
    InitSysCtrl();                      // Initialize the CPU (FILE: SysCtrl.c)
//  InitPieCtrl();                      // Initialize and enable the PIE (FILE: PieCtrl.c)
//  InitCpuTimers();                    // Initialize CPU Timers



//--- 初始化FFT
    rfft_adc.Tail = &rfft.OutBuf;               //Link the RFFT_ADC_F32_STRUCT to
                                                //RFFT_F32_STRUCT. Tail pointer of
                                                //RFFT_ADC_F32_STRUCT is passed to
                                                //the OutBuf pointer of RFFT_F32_STRUCT
    rfft.FFTSize  = RFFT_SIZE;                  //Real FFT size
    rfft.FFTStages = RFFT_STAGES;               //Real FFT stages
    rfft_adc.InBuf = &AdcBuf[0];                //Input buffer
    rfft.OutBuf = &RFFToutBuff[0];              //Output buffer
    rfft.CosSinBuf = &RFFTF32Coef[0];           //Twiddle factor
    rfft.MagBuf = &RFFTmagBuff[0];              //Magnitude output buffer

    RFFT_f32_sincostable(&rfft);                //Calculate twiddle factor

    //Clean up output buffer
    for (i=0; i < RFFT_SIZE; i++)
    {
         RFFToutBuff[i] = 0;
         AdcBuf[i] = 0;
    }

    //Clean up magnitude buffer
    for (i=0; i < RFFT_SIZE/2; i++)
    {
         RFFTmagBuff[i] = 0;
    }

//--- 初始化中断
    InitPieCtrl();

//--- 初始化中断向量表
    InitPieVectTable();

//// ISR Functions
    EALLOW;
    PieVectTable.ADCINT = &adc_isr;
    EDIS;

//// Initialize the CPU Timers
    InitCpuTimers();



//--- 全局中断设定
    PieCtrlRegs.PIEIER1.bit.INTx6 = 1;
    PieCtrlRegs.PIEIER1.bit.INTx7 = 1;

//// Enable CPU INT1
    IER = 1;

//// Enable global Interrupts and higher priority real-time debug events
    EINT;   // Enable Global interrupt INTM
    ERTM;   // Enable Global RealTime interrupt DBGM

//// Specific ADC setup
    InitAdc();
    AdcRegs.ADCMAXCONV.all = 0x0000;            // Setup 1 ADCMAXCONV on SEQ1
    AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x02;     // Choose ADCINA2 to sample
    AdcRegs.ADCTRL1.bit.ACQ_PS = 7;
    AdcRegs.ADCTRL2.bit.EPWM_SOCA_SEQ1 = 1;     // Enable SOCA from ePWM to start SEQ1
    AdcRegs.ADCTRL2.bit.INT_ENA_SEQ1 = 1;       // Enable SEQ1 interrupt
    AdcRegs.ADCTRL3.bit.ADCCLKPS = 3;
//// Assumes ePWM1 clock is already enabled in InitSysCtrl()
    EPwm1Regs.ETSEL.bit.SOCAEN = 1;             // Enable SOC on A group
    EPwm1Regs.ETSEL.bit.SOCASEL = 4;            // Select SOC from CPMA on countup
    EPwm1Regs.ETPS.bit.SOCAPRD = 1;             // 第一次触发ADC
    EPwm1Regs.CMPA.half.CMPA = 0x003E;          // 比较直62
    EPwm1Regs.TBPRD = 0x0176;                   // 周期374 200kHz
    EPwm1Regs.TBCTL.bit.CTRMODE = 0;            // 向上计数

//--- Main Loop
    while(1)                            // endless loop - wait for an interrupt
    {
        if(FFTStartFlag)                // If one frame data ready, then do FFT
        {

            RFFT_adc_f32u(&rfft_adc);   // This version of FFT doesn't need buffer alignment
            RFFT_f32_mag(&rfft);        // Calculate spectrum amplitude

                FFTStartFlag = 0;               //Start collecting the next frame of data
        }

    }
} //end of main()



interrupt void  adc_isr(void)
{

    PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;             // Must acknowledge the PIE group

//--- Manage the ADC registers
    AdcRegs.ADCTRL2.bit.RST_SEQ1 = 1;                   // Reset SEQ1 to CONV00 state
    AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1;                 // Clear ADC SEQ1 interrupt flag

        int z;
//  读取数据和数据更新
    for(z=1;z<ADC_BUF_LEN;z++)
    {
        AdcBuf[z-1] = AdcBuf[z];
    }
    AdcBuf[ADC_BUF_LEN-1] = AdcMirror.ADCRESULT0;               // Read the result

    counter++;

    if(counter == 128)
    {
        counter = 0;
        FFTStartFlag = 1;                               // One frame data ready
    }
} //end of main()

//===========================================================================
// End of File
//===========================================================================


Viewing all articles
Browse latest Browse all 12114

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>