Bad readings from ADC

Archibald
Posts: 110
Joined: Mon Mar 05, 2018 12:44 am

Bad readings from ADC

Postby Archibald » Fri Oct 05, 2018 10:10 am

Having noticed a few ADC readings outside the well-known 'noise', I decided to plot a histogram of readings . . .
ADC-histogram1.png
ADC-histogram1.png (8.08 KiB) Viewed 19555 times
The x-axis is for readings from 1960 to 2070, not as labelled. The mode (most frequent reading) is at a 2015 so is close to middle of the ADC's range (0 to 4095).

The ADC was set to 12 bit resolution and 11dB attenuation. The input was 1.76V (from a potentiometer with capacitive decoupling).

Of the 1000 readings taken, the histogram shows about 30 bad readings.

Here's the Arduino-ESP32 code used . . . .

Code: Select all

#include <driver/adc.h>  
uint16_t reading,histogram[400];

void setup() {
  adc1_config_width(ADC_WIDTH_BIT_12);
  adc1_config_channel_atten(ADC1_CHANNEL_6,ADC_ATTEN_DB_11);
  Serial.begin(115200);
  delay(1000);

  for(int z=0 ; z<400 ; z++)
  {
     histogram[z]=0;  //ensure array is initialised to zero
  }

  for(int z=0 ; z<1000 ; z++)
  {
      reading = adc1_get_raw(ADC1_CHANNEL_6);   // GPIO34
      histogram[reading-1850]++;
  }

  for(int z=0 ; z<400 ; z++)
  {
    Serial.print(z+1850); Serial.print(" "); Serial.println(histogram[z]);
  }
}

void loop() {

}

User avatar
fly135
Posts: 606
Joined: Wed Jan 03, 2018 8:33 pm
Location: Orlando, FL

Re: Bad readings from ADC

Postby fly135 » Fri Oct 05, 2018 4:11 pm

Try putting a delay between readings.

Archibald
Posts: 110
Joined: Mon Mar 05, 2018 12:44 am

Re: Bad readings from ADC

Postby Archibald » Fri Oct 05, 2018 4:47 pm

fly135 wrote:Try putting a delay between readings.
Thanks for the suggestion. With 10ms in the loop, I still get a similar spread of rogue readings.

User avatar
fly135
Posts: 606
Joined: Wed Jan 03, 2018 8:33 pm
Location: Orlando, FL

Re: Bad readings from ADC

Postby fly135 » Fri Oct 05, 2018 5:03 pm

How are you powering the pot? Are you using a separate regulated supply? I also see a lot of noise on the ADC. So what you are seeing (<3%) isn't that bad compared to what I'm seeing. Although I'm reading a sensor with a lot of amplification.

Archibald
Posts: 110
Joined: Mon Mar 05, 2018 12:44 am

Re: Bad readings from ADC

Postby Archibald » Fri Oct 05, 2018 6:14 pm

fly135 wrote:How are you powering the pot? Are you using a separate regulated supply? I also see a lot of noise on the ADC. So what you are seeing (<3%) isn't that bad compared to what I'm seeing. Although I'm reading a sensor with a lot of amplification.
I'm powering the development board and pot by a 5V switch-mode supply adaptor (with care!). Powering the pot from the 3.3V rail seems to make no difference. The pot is 10kΩ with its wiper decoupled with 100µF. I also have 100µF across the 5V supply.

With the distribution's mode at digital value 2015, the 'noise' evidently extends from about 2006 to 2021. I do not regard the readings outside this approximate range as being 'noise'. I am regarding them, or at least most of them, as erroneous readings. Some are far too far away from the mode to be noise of a Guassian nature.

Setting ADC attenuation to 0dB results in a similar spread of 'erroneous' readings but, as you may expect, the 'noise' is greater (in terms of spread of digital values).

Have you worked out how much of the noise that you are seeing is due to the sensor with its amplifier and how much is due to the ADC? [Edit] If you are using 0dB or 6dB ADC attenuation, you may be able to reduce the effect of ADC noise by increasing your amplification and using 11dB attenuation. However, beware of non-linearity for inputs greater than about 2.6V.

User avatar
fly135
Posts: 606
Joined: Wed Jan 03, 2018 8:33 pm
Location: Orlando, FL

Re: Bad readings from ADC

Postby fly135 » Fri Oct 05, 2018 7:57 pm

I haven't tried measuring the ADC noise as you have. We had a lot of noisy ADC reading on one prototype because of the noise on the power being amplified with the sensor signal. I attached a voltage regulated sensor breakout board from the sensor manufacturer and was able to achieve much better readings, which confirmed we had a design issue. But for sensors purposes we could live with a < +/- 3% noise reading. The bottom line is that I don't know what to expect for noise with a measurement like you are doing.

John A

Archibald
Posts: 110
Joined: Mon Mar 05, 2018 12:44 am

Re: Bad readings from ADC

Postby Archibald » Sat Oct 06, 2018 9:53 am

fly135 wrote:The bottom line is that I don't know what to expect for noise with a measurement like you are doing.
For a good ADC with constant input voltage we should expect successive digital readings to either remain constant or to waver between two adjacent digital values. The digital readings can reasonably be expected to waver between adjacent values if the input voltage is close to the threshold between the two. The design of PCM audio systems takes into account the audio noise generated by such wavering.

The readings that I am calling "erroneous" are potentially more serious for developers than readings that are said vary due to noise within the ESP32. The histogram shows that the erroneous readings can be a long way from the correct reading.

Here's a histogram with ADC attenuation set to 0dB. Input voltage is 0.550V and the distribution's mode is at digital reading of 1979. As before, ignore the x-axis labelling: it's from 1880 to 2120. Note this range is over twice the range of values of the histogram in my original post.
Attachments
ADC-histogram-0dB.png
ADC-histogram-0dB.png (7.62 KiB) Viewed 19453 times

User avatar
loboris
Posts: 514
Joined: Wed Dec 21, 2016 7:40 pm

Re: Bad readings from ADC

Postby loboris » Sat Oct 06, 2018 3:42 pm

For realy serious ADC performance analyzes you should use some precision voltage reference source, not the potentiometer which can introduce errors by itself.

Archibald
Posts: 110
Joined: Mon Mar 05, 2018 12:44 am

Re: Bad readings from ADC

Postby Archibald » Sat Oct 06, 2018 4:48 pm

loboris wrote:For realy serious ADC performance analyzes you should use some precision voltage reference source, not the potentiometer which can introduce errors by itself.
Thanks for your comment. Voltmeter readings indicate that the ADC input voltage is stable to within 1mV over several hours. With no delay in the measurement loop, the 1000 readings are taken within 40ms. I have no reason to believe there is any issue with the potentiometer's wiper contact especially as there is a 100µF decoupling capacitor.

A potentiometer connected to the ADC of an Arduino Micro (without decoupling capacitor) does not result in a spread of readings attributed to noise nor does it give erroneous readings.

Pibbotley
Posts: 45
Joined: Fri Feb 16, 2018 7:06 pm

Re: Bad readings from ADC

Postby Pibbotley » Mon Oct 08, 2018 5:05 pm

Could be induced voltage on the connection between pot and pin. Put a 100nF cap as close as possible to pin and ground and use exponential filtering in software.

Who is online

Users browsing this forum: Baidu [Spider], Google [Bot] and 64 guests