Arduino 33 ble sampling frequency

#define PZT_PIN_1 A0
#define PZT_PIN_2 A1
#define PZT_PIN_3 A2
#define PZT_PIN_4 A3
#define PZT_PIN_5 A4
#define PZT_PIN_6 A5
#define IMPACT_THRESHOLD 5

int sensor_values[6];
int previous_values[6] = {0, 0, 0, 0, 0, 0};
volatile int total_samples = 0; // 'volatile' ensures the variable can be updated from an interrupt
volatile bool adcFlag = false; // Flag to indicate an ADC sample is ready
volatile uint32_t sampleCounter = 0; // Counter for the number of samples taken

void setup() {
Serial.begin(115200); // Changed baud rate to 115200
while (!Serial);

pinMode(PZT_PIN_1, INPUT);
pinMode(PZT_PIN_2, INPUT);
pinMode(PZT_PIN_3, INPUT);
pinMode(PZT_PIN_4, INPUT);
pinMode(PZT_PIN_5, INPUT);
pinMode(PZT_PIN_6, INPUT);

// Enable interrupt for the custom SAADC handler
NVIC_SetPriority(SAADC_IRQn, 1UL);
NVIC_EnableIRQ(SAADC_IRQn);
}

void loop() {
// Read sensor values
sensor_values[0] = analogRead(PZT_PIN_1);
sensor_values[1] = analogRead(PZT_PIN_2);
sensor_values[2] = analogRead(PZT_PIN_3);
sensor_values[3] = analogRead(PZT_PIN_4);
sensor_values[4] = analogRead(PZT_PIN_5);
sensor_values[5] = analogRead(PZT_PIN_6);

int change[6];
for (int i = 0; i < 6; i++) {
change[i] = sensor_values[i] - previous_values[i];
}

bool impact_detected = false;
for (int i = 0; i < 6; i++) {
if (abs(change[i]) > IMPACT_THRESHOLD) {
impact_detected = true;
break;
}
}

if (impact_detected) {
total_samples++;
Serial.print(total_samples);
Serial.print("\t");
for (int i = 0; i < 6; i++) {
Serial.print(change[i]);
if (i < 5) Serial.print("\t");
}
Serial.println();
}

// Update previous values
for (int i = 0; i < 6; i++) {
previous_values[i] = sensor_values[i];
}
}

// Renamed interrupt handler to avoid conflict
extern "C" void custom_SAADC_IRQHandler(void) {
if (NRF_SAADC->EVENTS_END != 0) {
NRF_SAADC->EVENTS_END = 0;
adcFlag = true; // Set the flag when a sample is ready
sampleCounter++; // Increment the sample counter
}
}

THis is my code it read data from PZT sensor. I want to increase the sampling frequency. I tried more method but those are not working. im using arduino 33 ble.

@amitabhabu
Your code is NOT formatted correctly.
In the Arduino IDE, click on Edit, then on Copy for Forum, that will copy your code for the Forum.
Then come back here a do a simple paste.

#define PZT_PIN_1 A0
#define PZT_PIN_2 A1
#define PZT_PIN_3 A2
#define PZT_PIN_4 A3
#define PZT_PIN_5 A4
#define PZT_PIN_6 A5
#define IMPACT_THRESHOLD 5

int sensor_values[6];
int previous_values[6] = {0, 0, 0, 0, 0, 0};
volatile int total_samples = 0;   // 'volatile' ensures the variable can be updated from an interrupt
volatile bool adcFlag = false;    // Flag to indicate an ADC sample is ready
volatile uint32_t sampleCounter = 0;  // Counter for the number of samples taken

void setup() {
  Serial.begin(115200); // Changed baud rate to 115200
  while (!Serial);

  pinMode(PZT_PIN_1, INPUT);
  pinMode(PZT_PIN_2, INPUT);
  pinMode(PZT_PIN_3, INPUT);
  pinMode(PZT_PIN_4, INPUT);
  pinMode(PZT_PIN_5, INPUT);
  pinMode(PZT_PIN_6, INPUT);

  // Enable interrupt for the custom SAADC handler
  NVIC_SetPriority(SAADC_IRQn, 1UL);
  NVIC_EnableIRQ(SAADC_IRQn);
}

void loop() {
  // Read sensor values
  sensor_values[0] = analogRead(PZT_PIN_1);
  sensor_values[1] = analogRead(PZT_PIN_2);
  sensor_values[2] = analogRead(PZT_PIN_3);
  sensor_values[3] = analogRead(PZT_PIN_4);
  sensor_values[4] = analogRead(PZT_PIN_5);
  sensor_values[5] = analogRead(PZT_PIN_6);

  int change[6];
  for (int i = 0; i < 6; i++) {
    change[i] = sensor_values[i] - previous_values[i];
  }

  bool impact_detected = false;
  for (int i = 0; i < 6; i++) {
    if (abs(change[i]) > IMPACT_THRESHOLD) {
      impact_detected = true;
      break;
    }
  }

  if (impact_detected) {
    total_samples++;
    Serial.print(total_samples);
    Serial.print("\t");
    for (int i = 0; i < 6; i++) {
      Serial.print(change[i]);
      if (i < 5) Serial.print("\t");
    }
    Serial.println();
  }

  // Update previous values
  for (int i = 0; i < 6; i++) {
    previous_values[i] = sensor_values[i];
  }
}

// Renamed interrupt handler to avoid conflict
extern "C" void custom_SAADC_IRQHandler(void) {
  if (NRF_SAADC->EVENTS_END != 0) {
    NRF_SAADC->EVENTS_END = 0;
    adcFlag = true;        // Set the flag when a sample is ready
    sampleCounter++;       // Increment the sample counter
  }
}

is that ok?

Much bettor and I'm sure you noticed a big difference.

yes. Do you know any way to increase sampling frequency?

Unfortunately I'm not familiar with the operation of the nRF ADC

ok!!