adafruit / Adafruit_ZeroFFT

simple FFT for cortex m0
BSD 3-Clause "New" or "Revised" License
42 stars 18 forks source link

ZeroFFT() function no response #1

Closed wzdiyb closed 6 years ago

wzdiyb commented 6 years ago

Hello, first of all i wanna thank you guys for your contribution and sharing this so useful library for us all.

Today i've got a problem/issue about the ZeroFFT() function.

Purpose of my code: Sample the acceleration data on x, y, z-Axes with LIS3DH and then use FFT-Library to calculate the result.

Here's my code:

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_LIS3DH.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_ZeroFFT.h"

#define SAMPLING_FREQUENCY 100                                  // Unit: Hz () 
#define SAMPLES 256

Adafruit_LIS3DH lis = Adafruit_LIS3DH();                        // Create an instance of sensor LIS3DH

unsigned long start_time = 0;                                   
unsigned long current_time = 0;                                
int16_t x_a[SAMPLES];                                       
int16_t y_a[SAMPLES];                                       
int16_t z_a[SAMPLES]; 

int i;

void setup() {
  while(!Serial); 
  Serial.begin(9600); 

  while (!lis.begin()) {
    // sensor could not start
  }

  lis.setRange(LIS3DH_RANGE_2_G); 

  /* Set the sensor data/sampling rate */
  lis.setDataRate(LIS3DH_DATARATE_100_HZ); 

  delay(100);

  for (i=0; i<SAMPLES; i++) {
    x_a[i] = 0; 
    y_a[i] = 0; 
    z_a[i] = 0; 
  }

  start_time = millis();
}

void loop() {
  /*
   * Sampling
   */
  for(i=0;i<SAMPLES;i++) {
    while (1) {
      current_time = millis(); 
      if ((current_time - start_time) >= sampling_period) { 
        start_time = current_time; 
        lis.read(); 
        x_a[i] = lis.x;
        y_a[i] = lis.y;
        z_a[i] = lis.z;
        break;       
      }
    }
  }

Serial.println("1=====");
 ZeroFFT(x_a, SAMPLES); 
Serial.println("2=====");
ZeroFFT(y_a, SAMPLES); 
ZeroFFT(z_a, SAMPLES);
}

It seems like the program enters into a Infinite loop and on the console it will not display the message "2=====", it only printed the line "1====="

I can not figure where the problem is, so i come here trying to get some help from you guys.

Thank you!

Best Wishes wzd