Hi all
I’m using the esp32 wroom module and want to read out some analog values with the ADC2. But it doesn’t work correct.
I think the problem occours at configuration with “atten” flag. ADC1 works fine and gives me good results. but ADC2 is always to high and seems to be out of range.
As example I read a voltage of 1.563V:
ADC1 with ATTEN_DB_6 (max. 2.2V) gives me 2931 wich is fine for me.
ADC2 with ATTEN_DB_6 (max. 2.2V) gives me 4095 wich is not correct.
my config file looks like this:
static const adc_channel_t channel[8] = {ADC_CHANNEL_0, ADC_CHANNEL_3, ADC_CHANNEL_4, ADC_CHANNEL_5, ADC_CHANNEL_6, ADC_CHANNEL_7, ADC_CHANNEL_8, ADC_CHANNEL_9};
void configure_adc(void){
//Configure ADC
esp_adc_cal_value_t val_type[2];
adc1_config_width(ADC_WIDTH_BIT_12);
// Configure ADC1 Channel 0, 3-7
for(int i = 0; i<=7; i++){
adc1_config_channel_atten(channel[i], atten);
}
// Configure ADC2 Channel 7 - 9
for(int i = 5; i<=8){
adc2_config_channel_atten(channel[i], atten);
}
//Characterize ADC
adc_chars = calloc(1, sizeof(esp_adc_cal_characteristics_t));
for(int i = 0; i<=1; i++) {
val_type[i] = esp_adc_cal_characterize(unit[i], atten, ADC_WIDTH_BIT_12, DEFAULT_VREF, adc_chars);
print_char_val_type(val_type[i]);
}
}
Reading looks like this:
//Reading ADC2 Channel 7 to 9
for(int j = 7; j<=9; j++){
adc_reading[j] = 0;
for (int i = 0; i < NO_OF_SAMPLES; i++) {
int32_t raw;
adc2_get_raw((adc2_channel_t)channel[j], ADC_WIDTH_BIT_12, &raw);
adc_reading[j] += raw;
}
}
for(int j = ARR_CHANNEL_U2_MIN; j<=ARR_CHANNEL_U2_MAX; j++){
adc_reading[j] = adc_reading[j]/NO_OF_SAMPLES;
}
After this the value of adc_reading[X] is 4095 and this is wrong. Is there an issue while configuration or reading that I don’t see yet?