LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Frequency Shift Issue with ADXL355/ESP32 S3 Setup

I’m facing a frequency shift problem while using the ADXL355 accelerometer with an ESP32 S3. Here’s the setup and issue:

  • Sensor: ADXL355

  • MCU: ESP32 S3

  • Interface: SPI

  • Output Data Rate (ODR): Tested at 1000 Hz and 2000 Hz

  • Observation:

    • When I set ODR = 1000 Hz, time step = 1 ms, and FFT Δt = 1 ms, the FFT shows the correct frequency.

    • When I increase the ODR (e.g., 2000 Hz), even after adjusting the timestamp and FFT Δt according to the ODR, the FFT shows an incorrect frequency.

  • Known vibration: The surface has a vibration of 50 Hz, but the sensor sometimes shows ~60 Hz depending on the ODR.

I suspect it might be related to aliasing, SPI timing issues, or internal filtering of the ADXL355.

I am mentioning the ESP32 code below, along with my LabVIEW backend, which processes the data and computes the FFT.

Questions:

  1. Has anyone seen a similar frequency shift issue with ADXL355 or ESP32?

  2. Could this be caused by timing/sampling inaccuracies at higher ODRs despite adjusting timestamps?

  3. Any suggestions on how to get accurate frequency readings for higher ODRs?

Thanks in advance!



CODE:

#include <WiFi.h>
#include <PL_ADXL355.h>

// ======== ADXL355 Settings ========
PL::ADXL355 adxl355;
float A ;
float B ;
float C ;

uint8_t spiCsPin = 44;
auto range = PL::ADXL355_Range::range4g;
auto outputDataRate = PL::ADXL355_OutputDataRate::odr2000; //
float timeStepMs = 0.5; //
const int numberOfPoints = 2000; // number of samples to send per batch

// ======== Wi-Fi Settings ========
const char* ssid     = "PTCL-BB";
const char* password = "40871ed0";
const int tcpPort    = 5000;  // TCP server port
WiFiServer tcpServer(tcpPort);
WiFiClient client;

void setup() {
  Serial.begin(115200);
  //while (!Serial);

  // ADXL355 setup
  adxl355.beginSPI(spiCsPin);
  adxl355.setRange(range);
  adxl355.setOutputDataRate(outputDataRate);
  adxl355.enableMeasurement();

  // Wi-Fi setup
  WiFi.begin(ssid, password);
  Serial.print("Connecting to Wi-Fi");
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("\nWi-Fi connected.");
  tcpServer.begin();

  Serial.println("===================================");
  Serial.println("ADXL355 TCP Server Ready");
  Serial.print("Connect in LabVIEW to IP: ");
  Serial.println(WiFi.localIP());
  Serial.print("Port: ");
  Serial.println(tcpPort);
  Serial.println("===================================");
}

void loop() {
  // Accept client connection
  if (!client || !client.connected()) {
    client = tcpServer.available();
    if (client) {
      Serial.print("Client connected from ");
      Serial.print(client.remoteIP());
      Serial.print(":");
      Serial.println(client.remotePort());
    }
  }

  // Only proceed if client is connected
  if (!client || !client.connected()) return;

  // Clear FIFO to start fresh
  //adxl355.clearFifo();

  int collected = 0;
  while (collected < numberOfPoints) {
    int fifoSamples = adxl355.getNumberOfFifoSamples() / 3; // full XYZ sets available
    while (fifoSamples-- > 0 && collected < numberOfPoints) {
      auto accel = adxl355.getAccelerationsFromFifo();

      // Format: X,Y,Z\n
      String dataLine = String(accel.x4) + "," + String(accel.y4) + ";" + String(accel.z4) + "\n";
      A=accel.x;
      B=accel.y;
      C=accel.z;
      client.print(dataLine);

      collected++;
    }
  }
  Serial.println(A);
  Serial.println(B);
  Serial.println(C);
  Serial.println("Batch of 1000 samples sent to LabVIEW.");
}

Download All
0 Kudos
Message 1 of 5
(114 Views)

Hi Muhammad,

 

could you please downconvert your VI for LV2019 and attach again?

 

While doing so: please make sure there is some useful default data in a string indicator connected to the TCP read string so we can simulate the calculations with your data! (The whole string conversion loop looks overly complicated.)

 

Can you verify the sample rates of your sensor device?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 5
(78 Views)

The File for Labview 2019 is attached below

 

0 Kudos
Message 3 of 5
(65 Views)

Hi Muhammad,

 


muhammadsauddar@gmail.com wrote:

The File for Labview 2019 is attached below

 


You forgot to set some useful default data!

Please provide some typical data as delivered from TCPRead…

 

Just a suggestion, based on assupmtions:

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 5
(57 Views)

Hi Muhammad,

Me me me! haha. I recently finished my project with ADXL 355. Are you polling for Data Ready? It can be done using SPI or IO pin. To fix my issue, I only read my data when it was signaled ready as ADXL can have +- 5% variation. Another mistake I was making was confusing my SPI's rate of read with ODR. I was polling information with SPI at Xkhz and used that as dt which was wrong. 

 

Final thing I  implemented to handle this +-5% drift was a "dt" counter, this counter packaged dt information between the two data ready signals. Later before processing data on PC side, I averaged dt of all (4096) samples and used that value as dt for waveform building. 


Edit: my ODR was 4khz for +-2g. Tip: I used a tone generator app on my phone to validate the frequencies up to higher 1900Hz. I discovered this by accident, my application also used a microphone and while calibrating frequencies for it, I realized that ADXL355 was also behaving ALMOST like a microphone (It was reacting to speech). It may not react the same way for +-4g or +-8g range.

Hope some of this helps you. 

0 Kudos
Message 5 of 5
(30 Views)