RA4M1: huge noise in ADC values

I tested the ADC in the RA4M1 module and found that there is a huge amount of noise in the values. This is my test circuit:


This is the test software:

//  Seeed XIAO RA4M1 ADC Test
//  Michael Koch, September 2024

double x, mean, sigma;
double sum_x, sum_xx;
int n;

// the setup function runs once when you press reset or power the board
void setup()
{  
  analogReadResolution(12); 

  Serial.begin(115200);
  while (!Serial)
    delay(10);  
}

// the loop function runs over and over again forever
void loop()
{
  n = 10000;
  sum_x = 0;
  sum_xx = 0;
  for(int i = 0; i < n; i++)
  {
    x = (double)analogRead(A1);
    sum_x += x;
    sum_xx += x*x;
  }

  mean = sum_x / n;
  sigma = (sum_xx - n * mean * mean) / n;
   
  Serial.print("Mean: ");
  Serial.print(mean);
  Serial.print("   Sigma: ");
  Serial.print(sigma);
  Serial.println();
  delay(500);
}

The mean value is as expected, but there is a standard deviation of about 135.
The same software with a SAMD21 module has a standard deviation of about 4 (in the same test circuit).
Why does the RA4M1 have more noise by a factor 30? The ADC is almost unusable.

I did already try to use an external reference instead of the 3.3V reference (after removing R5 from the module) but it didn’t help much.

Michael

I forgot the square root in the formula for the standard deviation:
sigma = sqrt((sum_xx - n * mean * mean) / n);
But the problem remains the same: RA4M1 has much more noise than SAMD21 in the ADC values.

Updated test software with more statistic values:

//  Seeed XIAO RA4M1 ADC Test
//  Michael Koch, September 2024

double x, mean, sigma;
double sum_x, sum_xx;
double minimum, maximum;
int n;

// the setup function runs once when you press reset or power the board
void setup()
{  
  analogReadResolution(12); 

  Serial.begin(115200);
  while (!Serial)
    delay(10);  
}

// the loop function runs over and over again forever
void loop()
{
  n = 10000;
  minimum = 65535;
  maximum = 0;
  sum_x = 0;
  sum_xx = 0;
  for(int i = 0; i < n; i++)
  {
    x = (double)analogRead(A1);
    if (x < minimum) minimum = x;
    if (x > maximum) maximum = x;
    sum_x += x;
    sum_xx += x*x;
  }

  mean = sum_x / n;
  sigma = sqrt((sum_xx - n * mean * mean) / n);
   
  Serial.print("Mean: ");
  Serial.print(mean);
  Serial.print("   Sigma: ");
  Serial.print(sigma);
  Serial.print("   Minimum: ");
  Serial.print(minimum);
  Serial.print("   Maximum: ");
  Serial.print(maximum);
  Serial.print("   Maximum-Minimum: ");
  Serial.print(maximum - minimum);
  Serial.print("   Mean-Minimum: ");
  Serial.print(mean - minimum);
  Serial.print("   Maximum-Mean: ");
  Serial.print(maximum - mean);
  Serial.println();
  delay(500);
}