A weird error

Hey all I have nearly succeeded in making an FFT program that runs on arduino. HOWEVER i get a weird error with the serial print function when I try to address a 2 dimensional array. The compile goes fine but no data comes back through the serial monitor.

int outpin=9;
int outpin2=10;
int m =0;
int N=64;
int x_n_re[63];
int inputpin=3;
int N_DIV_2_PLUS_1=33;

void setup()
{
Serial.begin(9600);
}

void loop()
{
int i=0;
int x_n_re={115,115,115,115,115,115,115,115,115,115,115,115,115,115,115,115,115,115,115,115,115,115,115,115,115,115,115,115,115,115,115,115,115,115,115,115,115,115,115,115,115,115,115,115,115,115,115,115,115,115,115,115,115,115,115,115,115,115,115,115,115,115,115};

int cosLUT={128,127,125,122,118,112,106,98,90,81,71,60,48,37,24,12,0,-12,-24,-37,-48,-60,-71,-81,-90,-98,-106,-112,-118,-122,-125,-127}; //Cosine LookupTable
int sinLUT={0,12,24,37,48,60,71,81,90,98,106,112,118,122,125,127,128,127,125,122,118,112,106,98,90,81,71,60,48,37,24,12}; //Sin LookupTable

byte magnLUT[16][16] =
{
{0,16,32,48,64,80,96,112,128,144,160,176,192,208,224,240},
{16,22,35,50,65,81,97,113,128,144,160,176,192,208,224,240},
{32,35,45,57,71,86,101,116,131,147,163,178,194,210,226,242},
{48,50,57,67,80,93,107,121,136,151,167,182,197,213,229,244},
{64,65,71,80,90,102,115,128,143,157,172,187,202,217,232,248},
{80,81,86,93,102,113,124,137,150,164,178,193,208,222,237,252},
{96,97,101,107,115,124,135,147,160,173,186,200,214,229,243,255},
{112,113,116,121,128,137,147,158,170,182,195,208,222,236,250,255},
{128,128,131,136,143,150,160,170,181,192,204,217,230,244,255,255},
{144,144,147,151,157,164,173,182,192,203,215,227,240,252,255,255},
{160,160,163,167,172,178,186,195,204,215,226,237,249,255,255,255},
{176,176,178,182,187,193,200,208,217,227,237,248,255,255,255,255},
{192,192,194,197,202,208,214,222,230,240,249,255,255,255,255,255},
{208,208,210,213,217,222,229,236,244,252,255,255,255,255,255,255},
{224,224,226,229,232,237,243,250,255,255,255,255,255,255,255,255},
{240,240,242,244,248,252,255,255,255,255,255,255,255,255,255,255}
};

//Bit Reversal Unrolled Loop Table
i=x_n_re[1];x_n_re[1]=x_n_re[32];x_n_re[32]=i;
i=x_n_re[2];x_n_re[2]=x_n_re[16];x_n_re[16]=i;
i=x_n_re[3];x_n_re[3]=x_n_re[48];x_n_re[48]=i;
i=x_n_re[4];x_n_re[4]=x_n_re[8];x_n_re[8]=i;
i=x_n_re[5];x_n_re[5]=x_n_re[40];x_n_re[40]=i;
i=x_n_re[6];x_n_re[6]=x_n_re[24];x_n_re[24]=i;
i=x_n_re[7];x_n_re[7]=x_n_re[56];x_n_re[56]=i;
i=x_n_re[9];x_n_re[9]=x_n_re[36];x_n_re[36]=i;
i=x_n_re[10];x_n_re[10]=x_n_re[20];x_n_re[20]=i;
i=x_n_re[11];x_n_re[11]=x_n_re[52];x_n_re[52]=i;
i=x_n_re[13];x_n_re[13]=x_n_re[44];x_n_re[44]=i;
i=x_n_re[14];x_n_re[14]=x_n_re[28];x_n_re[28]=i;
i=x_n_re[15];x_n_re[15]=x_n_re[60];x_n_re[60]=i;
i=x_n_re[17];x_n_re[17]=x_n_re[34];x_n_re[34]=i;
i=x_n_re[19];x_n_re[19]=x_n_re[50];x_n_re[50]=i;
i=x_n_re[21];x_n_re[21]=x_n_re[42];x_n_re[42]=i;
i=x_n_re[22];x_n_re[22]=x_n_re[26];x_n_re[26]=i;
i=x_n_re[23];x_n_re[23]=x_n_re[58];x_n_re[58]=i;
i=x_n_re[25];x_n_re[25]=x_n_re[38];x_n_re[38]=i;
i=x_n_re[27];x_n_re[27]=x_n_re[54];x_n_re[54]=i;
i=x_n_re[29];x_n_re[29]=x_n_re[46];x_n_re[46]=i;
i=x_n_re[31];x_n_re[31]=x_n_re[62];x_n_re[62]=i;
i=x_n_re[35];x_n_re[35]=x_n_re[49];x_n_re[49]=i;
i=x_n_re[37];x_n_re[37]=x_n_re[41];x_n_re[41]=i;
i=x_n_re[39];x_n_re[39]=x_n_re[57];x_n_re[57]=i;
i=x_n_re[43];x_n_re[43]=x_n_re[53];x_n_re[53]=i;
i=x_n_re[47];x_n_re[47]=x_n_re[61];x_n_re[61]=i;
i=x_n_re[55];x_n_re[55]=x_n_re[59];x_n_re[59]=i;

int stage=0;
int LOG_2_N = 6;
int n_of_b = 32; // Number of butterflies
int s_of_b = 1; // Size of butterflies
int a_index = 0; // fft data index
int a_index_ref = 0; // fft data index reference
int x_n_im[64] = {0x0000};

for(stage=0; stage<LOG_2_N; stage++)
{
for(int nb_index=0; nb_index<n_of_b; nb_index++)
{
int tf_index = 0; // The twiddle factor index
for(int sb_index=0; sb_index<s_of_b; sb_index++)
{
int resultMulReCos=0;
int resultMulImCos=0;
int resultMulReSin=0;
int resultMulImSin=0;
int b_index = a_index+s_of_b; // 2nd fft data index

resultMulReCos=x_n_re[b_index]*cosLUT[tf_index];
resultMulReSin=x_n_re[b_index]*sinLUT[tf_index];
resultMulImCos=x_n_im[b_index]*cosLUT[tf_index];
resultMulImSin=x_n_im[b_index]*sinLUT[tf_index];

x_n_re[b_index] = x_n_re[a_index]-resultMulReCos+resultMulImSin;
x_n_im[b_index] = x_n_im[a_index]-resultMulReSin-resultMulImCos;
x_n_re[a_index] = x_n_re[a_index]+resultMulReCos-resultMulImSin;
x_n_im[a_index] = x_n_im[a_index]+resultMulReSin+resultMulImCos;

if (((sb_index+1) & (s_of_b-1)) == 0)
a_index = a_index_ref;
else
a_index++;

tf_index += n_of_b;
}
a_index = ((s_of_b<<1) + a_index) & 63;
a_index_ref = a_index;
}
n_of_b >>= 1;
s_of_b <<= 1;
}

int mult =-1;
for(i=0; i<N_DIV_2_PLUS_1; i++)
{
// If Re{X(n)} is negative, multiply by -1
if ((x_n_re & 0x8000)!=0x0000)

  • {*
    x_n_re=x_n_re_mult;
    }
    // If Im{X(n)} is negative, multiply by -1*
    if ((x_n_im & 0x8000)!=0x0000)
    * {
    x_n_im=x_n_immult;
    }
    } _

    //Convert all X_N_RE values to their magnitudes

    int a=0;
    for (int i=0;i<32; i++)
    {
    a = x_n_re >> 11 ;
    x_n_re*=a;
    _}_
    //int g=magnLUT[x_n_re[
    m = magnLUT[2][4];
    _ //for(i=1; i<31; i++)_
    // x_n_re = magnLUT[x_n_re >> 11][x_n_im >> 11];
    //x_n_re[32] = magnLUT[x_n_re[32] >> 11][0];
    _//int m = magnLUT[12][0];
    Serial.print("Magnitude: ");
    for (int i=0;i<32; i++)
    {*_

* //Serial.print(a);*
//Serial.print(x_n_re*);
_ // Serial.print(“done”);
Serial.print(m);
Serial.print(",");*_

}
Serial.println();
}

if i directly address the array IE XXXX[1][3]; it works but if i use a variable to target a value IE XXXX[a][3] then I get no output
ANY ADVICE WOULD BE APPRECIATED!
THANKS!!!

If you want to print bytes as decimal values, not their corresponding ASCII, you'll need to do:

Serial.print(variable,DEC);

Thanks for the response, Il give that a run, it has had the same problem with the 2d array as int and char could this all potentially be fixed by doing this?

Thanks

I'd suggest trying to put the array into PROGMEM to remove the possibility of having a RAM issue.

--Phil.

That's a really good idea I thought it might be a memory issue b/c the program would essentially stop when I tried to address the array by a variable even if I had it print "test" after an array lookup it would hang and no longer execute code il run this when I get home from work

Thanks!!

Ok I havnt run the repair yet but I have very high hopes! The program that I used as a basis for this project was based around an 8bit adc in order to verify that I was core functional I simulated a signed 8bit input by using a simulated input with a positive value below 127. Step 2 is to uprade to use the 10bit adc on arduino. The problem is that if I want to preserve the good resolution il have to use a long type 64 place array to store the data after the mult stage I'm really worried this is going to overload the boards memory and I won't be able to run the program as intended. I only need about 24 bits not the whole 32 allowed by the long type can I declare a custom variable size or is this whole thing moot and the arduino won't have a problem holding that array?

Thanks

WARNING to anyone reading this thread, I tried to perform the repair to the code described above and after a few runs through I believe I managed to frag my bootloader on both my primary and spare units. Im now waiting on an avr isp to come in hopefully to the rescue. so dont be tempted to run this code!

Good warning. I've heard before of people's errant code wiping out the bootloader but haven't heard a mechanism for how that can happen. I thought the fuse settings 'locks' the bootloader. Is locking not that effective, is not like a read only permissive? Anyone shed light on how a bootloader can get clobbered when code goes bad or memory gets clobbered?

Lefty

I dont know for sure that it affected the bootloader, but from the very poorly documented stuff that I did find on the error it appeared that was the consensus. For sure it had to do with the sketch I was trying to upload, I still have it but dont want to upload it as it screwed up both my units. Im really hoping that I can fix it by reburning the bootloader or im out some money

I got the error by loading the 2d array into the progmem using that function. The original problem persisted but I found that if I reduced the array size to 8X16 it ran fine. Figuring I had overloaded the memory somewhere down the line I started at 16X16 and then went to 15X16 etc and on about 13X16 I got an output, all squares and then the pin 13 led started going nuts. since then I get an avrdude error.

btw i am using a dumilanove with atmega 168