Bad readings from ADC
Posted: 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 . . .
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 . . . .
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() {
}