Hello every one,
i have a Problem "see Topic"...
my Programm works for FFT lenght up to 1024 when i increase the size to 2048,4096,8192.... then i get a realtime Problemm see in Picture for N = 32768
Im using 2 Chanels Left and Right (Stereo).
When i use 1 Channel i get no problems up to N = 32K
Im using "Welch, Wright, & Morrow, Real-time Digital Signal Processing, 2005"
"Main Programm"
#include "..\..\..\Common_Code\DSK_Config.h"
#include "frames.h"
int main()
{
// initialize all buffers to 0
ZeroBuffers();
// initialize EDMA controller
EDMA_Init();
// initialize DSK for selected codec using EDMA
DSK_Init_EDMA(CodecType, TimerDivider);
// main loop here, process buffer when ready
while(1) {
if(IsBufferReady()==1 && IsOverRun()==0){ // process buffers in background
ProcessBuffer();
}
}
}
"ISR"
// Welch, Wright, & Morrow,
// Real-time Digital Signal Processing, 2005
// modified by B.Fuchs
///////////////////////////////////////////////////////////////////////
// Filename: ISRs.c
//
// Synopsis: Interrupt service routines for EDMA service
//
///////////////////////////////////////////////////////////////////////
#include "..\..\..\Common_Code\DSK_Config.h"
#include "math.h"
#include "frames.h"
// frame buffer declarations
#define BUFFER_COUNT 32768 // buffer length in McBSP samples (L+R) //MAX 32768 //warum? wegen datentypen
#define BUFFER_LENGTH BUFFER_COUNT*2 // two shorts read from McBSP each time
#define NUM_BUFFERS 3 // don't change this!
#pragma DATA_SECTION (buffer, "CE0"); // allocate buffers in SDRAM
short int buffer[NUM_BUFFERS][BUFFER_LENGTH];
// there are 3 buffers in use at all times, one being filled from the McBSP,
// one being operated on, and one being emptied to the McBSP
// ready_index --> buffer ready for processing
short buffer_ready = 0, over_run = 0, ready_index = 0;
// fft defines
#include "fft.h"
#define N BUFFER_COUNT
//new fft-assambler
#define RADIX 2 //radix or base
#define Tw N/RADIX
#pragma DATA_SECTION (xR, "CE0");
#pragma DATA_SECTION (xL, "CE0");
#pragma DATA_SECTION (WxFFT, "CE0");
#pragma DATA_SECTION (WxIFFT, "CE0");
COMPLEX xR[N], xL[N]; //für eingang
COMPLEX WxFFT[Tw],WxIFFT[Tw]; //twiddle factor
#pragma DATA_SECTION (iData, "CE0");
#pragma DATA_SECTION (iTwid, "CE0");
short iData[N]; //index for bitrev X
short iTwid[N/2]; //index for twiddle constants W
void ProcessBuffer()
///////////////////////////////////////////////////////////////////////
// Purpose: Processes the data in buffer[ready_index] and produces
// the Fourier transform of the data in
// Data is packed into the buffer, alternating right/left
//
// Input: None
//
// Returns: Nothing
//
// Calls: Nothing
//
// Notes: None
///////////////////////////////////////////////////////////////////////
{
short int *pBuf = buffer[ready_index];
int i;
*(volatile int *)IO_PORT = 0; // set STS0/1 low - for time measurement
//***Lade daten in xR und xL ***\\
//erst rechts dann links immer achten
for(i=0; i < BUFFER_COUNT; i++){
xR[i].real = *pBuf++;
xR[i].imag = 0.0;
xL[i].real = *pBuf++;
xL[i].imag = 0.0;
// *pBuf++;
}
// TI_FFTrd2-CODE_ASSAMBLER
cfftr2_dit(xR, WxFFT, N ) ; //TI floating-pt complex FFT
bitrev(xR, iData, N); //freq scrambled->bit-reverse x
cfftr2_dit(xR, WxIFFT, N ) ; //TI floating-pt complex FFT
bitrev(xR, iData, N); //freq scrambled->bit-reverse x
cfftr2_dit(xL, WxFFT, N ) ; //TI floating-pt complex FFT
bitrev(xL, iData, N); //freq scrambled->bit-reverse x
cfftr2_dit(xL, WxIFFT, N ) ; //TI floating-pt complex FFT
bitrev(xL, iData, N);
pBuf = buffer[ready_index];
for(i = 0;i < BUFFER_COUNT;i++) { // pack into buffer
xR[i].real = xR[i].real / N;
xL[i].real = 0;//xL[i].real / N;
*pBuf++ = xR[i].real;
*pBuf++ = xL[i].real;
}
*(volatile int *)IO_PORT = -1; // set STS0/1 high - for time measurement
buffer_ready = 0; // signal we are done
over_run = 0;
}
void EDMA_Init()
////////////////////////////////////////////////////////////////////////
// Purpose: Configure EDMA controller to perform all McBSP servicing.
// EDMA is setup so buffer[2] is outbound to McBSP, buffer[0] is
// available for processing, and buffer[1] is being loaded.
// Conditional statement ensure that the correct EDMA events are
// used based on the McBSP that is being used.
// Both the EDMA transmit and receive events are set to automatically
// reload upon completion, cycling through the 3 buffers.
// The EDMA completion interrupt occurs when a buffer has been filled
// by the EDMA from the McBSP.
// The EDMA interrupt service routine updates the ready buffer index,
// and sets the buffer ready flag which is being polled by the main
// program loop
//
// Input: None
//
// Returns: Nothing
//
// Calls: Nothing
//
// Notes: None
///////////////////////////////////////////////////////////////////////
{
EDMA_params* param;
// McBSP tx event params
param = (EDMA_params*)(EVENTE_PARAMS);
param->options = 0x211E0002;
param->source = (unsigned int)(&buffer[2][0]);
param->count = (0 << 16) + (BUFFER_COUNT);
param->dest = 0x34000000;
param->reload_link = (unsigned int)(BUFFER_COUNT << 16) + (EVENTN_PARAMS & 0xFFFF);
// set up first tx link param
param = (EDMA_params*)EVENTN_PARAMS;
param->options = 0x211E0002;
param->source = (unsigned int)(&buffer[0][0]);
param->count = (0 << 16) + (BUFFER_COUNT);
param->dest = 0x34000000;
param->reload_link = (unsigned int)(BUFFER_COUNT << 16) + (EVENTO_PARAMS & 0xFFFF);
// set up second tx link param
param = (EDMA_params*)EVENTO_PARAMS;
param->options = 0x211E0002;
param->source = (unsigned int)(&buffer[1][0]);
param->count = (0 << 16) + (BUFFER_COUNT);
param->dest = 0x34000000;
param->reload_link = (unsigned int)(BUFFER_COUNT << 16) + (EVENTP_PARAMS & 0xFFFF);
// set up third tx link param
param = (EDMA_params*)EVENTP_PARAMS;
param->options = 0x211E0002;
param->source = (unsigned int)(&buffer[2][0]);
param->count = (0 << 16) + (BUFFER_COUNT);
param->dest = 0x34000000;
param->reload_link = (unsigned int)(BUFFER_COUNT << 16) + (EVENTN_PARAMS & 0xFFFF);
// McBSP rx event params
param = (EDMA_params*)(EVENTF_PARAMS);
param->options = 0x203F0002;
param->source = 0x34000000;
param->count = (0 << 16) + (BUFFER_COUNT);
param->dest = (unsigned int)(&buffer[1][0]);
param->reload_link = (unsigned int)(BUFFER_COUNT << 16) + (EVENTQ_PARAMS & 0xFFFF);
// set up first rx link param
param = (EDMA_params*)EVENTQ_PARAMS;
param->options = 0x203F0002;
param->source = 0x34000000;
param->count = (0 << 16) + (BUFFER_COUNT);
param->dest = (unsigned int)(&buffer[2][0]);
param->reload_link = (unsigned int)(BUFFER_COUNT << 16) + (EVENTR_PARAMS & 0xFFFF);
// set up second rx link param
param = (EDMA_params*)EVENTR_PARAMS;
param->options = 0x203F0002;
param->source = 0x34000000;
param->count = (0 << 16) + (BUFFER_COUNT);
param->dest = (unsigned int)(&buffer[0][0]);
param->reload_link = (unsigned int)(BUFFER_COUNT << 16) + (EVENTS_PARAMS & 0xFFFF);
// set up third rx link param
param = (EDMA_params*)EVENTS_PARAMS;
param->options = 0x203F0002;
param->source = 0x34000000;
param->count = (0 << 16) + (BUFFER_COUNT);
param->dest = (unsigned int)(&buffer[1][0]);
param->reload_link = (unsigned int)(BUFFER_COUNT << 16) + (EVENTQ_PARAMS & 0xFFFF);
*(unsigned volatile int *)ECR = 0xf000; // clear all McBSP events
*(unsigned volatile int *)EER = 0xC000;
*(unsigned volatile int *)CIER = 0x8000; // interrupt on rx reload only
}
void ZeroBuffers()
////////////////////////////////////////////////////////////////////////
// Purpose: Sets all buffer locations to 0
//
// Input: None
//
// Returns: Nothing
//
// Calls: Nothing
//
// Notes: None
///////////////////////////////////////////////////////////////////////
{
int ip0 = BUFFER_COUNT * NUM_BUFFERS;
int *p0 = (int *)buffer;
while(ip0--)
*p0++ = 0;
// twiddle faktoren initalisieren
twiddle_factor_rd2(N, WxFFT);
twiddle_factor_ird2(N, WxIFFT);
digitrev_index(iTwid, N/RADIX, RADIX); //produces index for bitrev() W
bitrev(WxFFT, iTwid, N/RADIX); //bit reverse W
bitrev(WxIFFT, iTwid, N/RADIX); //bit reverse W
// für FFT/IFFT in Process
digitrev_index(iData, N, RADIX); //produces index for bitrev() X
}
///////////////////////////////////////////////////////////////////////
// Purpose: Access function for buffer ready flag
//
// Input: None
//
// Returns: Non-zero when a buffer is ready for processing
//
// Calls: Nothing
//
// Notes: None
///////////////////////////////////////////////////////////////////////
int IsBufferReady()
{
return buffer_ready;
}
///////////////////////////////////////////////////////////////////////
// Purpose: Access function for buffer overrun flag
//
// Input: None
//
// Returns: Non-zero if a buffer overrun has occurred
//
// Calls: Nothing
//
// Notes: None
///////////////////////////////////////////////////////////////////////
int IsOverRun()
{
return over_run;
}
interrupt void EDMA_ISR()
///////////////////////////////////////////////////////////////////////
// Purpose: EDMA interrupt service routine. Invoked on every buffer
// completion
//
// Input: None
//
// Returns: Nothing
//
// Calls: Nothing
//
// Notes: None
///////////////////////////////////////////////////////////////////////
{
*(unsigned volatile int *)CIPR = 0xf000; // clear all McBSP events
if(++ready_index >= NUM_BUFFERS) // update buffer index
ready_index = 0;
if(buffer_ready == 1) // set a flag if buffer isn't processed in time
over_run = 1;
buffer_ready = 1; // mark buffer as ready for processing
}
maybe anyone can help me.
Thank too all