Error Message: Fault exception

Hello,

I remember this discussion about Mbed error decoder. But I usually place few printfs across the program and I am trying determine where the code crash.

However I see potential issue (lines 38-54)

            //read pin and store in FFT_inputBuffer
            FFT_inputBuffer[bufferPtr] = signal.read(); //range 0-1

            //once all samples have been taken, pass to FFT()
            if(bufferPtr > SAMPLES){
                FFT();

                //display frequency values on lcd
                drawWaveform();

                //reset buffer pointer
                bufferPtr = 0;

            }else{
                //increment buffer pointer
                bufferPtr++;
            }

The value of macro SAMPLES = 2048, but your if condition become true with number 2049. It means the last index of array, where last data was stored, was 2048 and that is out of size of your array because the size 2048 is range of 0-2047.

Similar it can be for line 80.

Result of the for condition below is 012345678910

for(int i = 0;i <= 10; i++) cout << i;

So it seems again your for statement hit 2048 instead of 2047 only.

BR, Jan

1 Like