Post Go back to editing

ADXL372 3200HZ odr can not get

Category: Software
Product Number: adxl372z

Hi everyone,

I am trying to measure acceleration in full bandwidth measurement mode with adxl372 and arduino nano ble 33 via SPI.

i set ODR to 3200 hz and BW to 1600 hz and spi speed to 2mhz, but i cant get every 50 ms 170 set acceleration values, i can only receive every 50 ms 30 set...

So I tried to check the sampling rate by measuring the acceleration of only one axis.. i can receive every 50 ms about75 values --> every 1 s around 1500 values -->1500 hz..

and i tried to change odr and bw and spi speed.. the speed of print in arduino ide had no change....i can still get every 50 ms 70 values, but some of them are 0.00...

i am newbie in this area...can anyone please help me? 

The Code is here:

#include "SPI.h"
#include "Communication.h" //That's where for some reason they defined the CS pin and INT pin
#include "adxl372.h"

//Constants
SPISettings spisettings(20000000, MSBFIRST, SPI_MODE0);
unsigned int const N_FIFO_SAMPLES = 501;//1 set =x,y,z data, max 170, min = 2
unsigned int const N_FIFO_BYTES_PER_SAMPLE = 2;//3 axes, 2 bytes per axis
unsigned int const N_FIFO_BYTES = N_FIFO_SAMPLES*N_FIFO_BYTES_PER_SAMPLE; 
unsigned char ACCEL_ODR_VAL = 0x60;//Output sample rate of the accel, register value. 0x60 is 3200Hz
#define ACCEL_BW BW_1600Hz
#define ACCEL_FILTER_SETTLE FILTER_SETTLE_16
#define ACCEL_OP_MODE_VAL 0x03 //MM and all filters enabled is 0x03
#define ACCEL_INT1_MODE_VAL 0x04 //0x04 is INT1 = FIFO full
#define POST_CONFIG_DELAY 400 //In ms

//Structures

struct XYZ
{
  float x;
  float y;
  float z;
};

float xoffset = -2.20;

//Globals
struct adxl372_device adxl372;
//Private functions
short twos_complement(unsigned short val,unsigned char bits)
{
    short value  = (short)val;
    if (value & (1 << (bits-1))){
       value -= 1 << bits;
    }
    return value;
}

void Set_configs(void)
{
  adxl372_Reset(&adxl372);
  
  adxl372_Set_BandWidth(&adxl372, ACCEL_BW); //1600

  adxl372_Set_Autosleep(&adxl372, false);

  adxl372_Set_LowNoise(&adxl372, true);
  
  adxl372_write_reg(&adxl372,ADI_ADXL372_TIMING, ACCEL_ODR_VAL);

  /* Set int1 to fifo full interrupt */
  adxl372_write_reg(&adxl372,ADI_ADXL372_INT1_MAP,ACCEL_INT1_MODE_VAL);
  
  /*Put fifo in Stream Mode */
  adxl372_Configure_FIFO(&adxl372, N_FIFO_SAMPLES, OLDEST_SAVED, X_FIFO); 

 
  /* Set operation mode to MM and HPF disabled */
  adxl372_write_reg(&adxl372,ADI_ADXL372_POWER_CTL,ACCEL_OP_MODE_VAL);

  adxl372_Set_hpf_corner(&adxl372, HPF_CORNER3); 
 
  delay(POST_CONFIG_DELAY);
}

bool CollectXYZFIFO(XYZ *xyz) //xyz must be an allocated array of N_FIFO_SAMPLES-1 at least
{
  static char FIFO_dump[N_FIFO_BYTES]; //Static to avoid losing time allocating
    //read all FIFO_samples_sets 
  adxl372_read_multi_reg(&adxl372,ADI_ADXL372_FIFO_DATA,(N_FIFO_SAMPLES-1)*N_FIFO_BYTES_PER_SAMPLE, (unsigned char*)FIFO_dump); //Always leave 1 sample set in the fifo.
    //Process data: convert to g's and print in serial port. M
  uint16_t aux = 0;
  for (int i = 0; i <= (N_FIFO_SAMPLES-1)*N_FIFO_BYTES_PER_SAMPLE; i= i+N_FIFO_BYTES_PER_SAMPLE) {
     uint16_t iSample = i/N_FIFO_BYTES_PER_SAMPLE;
      
      //The first byte contains the 8 most significant bits of the 12 bits value
      //the 4 most significant bits of the second byte contain the least significant bits of the value. Combine them.
      //And 0x0FFF (12 bits) is certainly redundant
     aux = ((uint16_t)(FIFO_dump[i] <<4) | (FIFO_dump[i+1]>>4))&0x0FFF;
     xyz[iSample].x = (float)twos_complement(aux,12)*0.1;
     Serial.print(iSample);
     Serial.print(",");
     Serial.println(xyz[iSample].x);

    }
  
}

//Initialisation
void setup() {
  Serial.begin(921600);
  SPI.begin();
  delay(1000);
  pinMode(CS_PIN, OUTPUT);
  digitalWrite(CS_PIN, HIGH);
  SPI.beginTransaction(spisettings);
  Set_configs();
  delay(1000);
}

//Main loop
void loop() {
  static XYZ fifoXYZ[N_FIFO_SAMPLES-1];
  SPI.beginTransaction(spisettings);
  //wait for fifo-full interrupt, because it is necessary to always leave 1 sample in the FIFO so it is simpler for now to just dump the content when it's full 
  //while(digitalRead(ADXL_INT1_PIN)==0); //Temp
  CollectXYZFIFO((XYZ*)(&fifoXYZ));
}

1A.zip

I have some more questions:

  1.  with odr 3200 hz for meassuring in 3 axes, i can get every 1 s 3200 set values or totally 3200 values in xyz? 
  2. i used my computer to get value for 3 axes, i can just get every 50 ms 11 set values, but i used my laptop i can get every 50 ms 30 set values with the same code... i cant understand this..

Thanks for your help and advices.