ESP32 ADC_VREF does not affect ADC readings
Posted: Wed Jan 18, 2023 1:56 pm
Hello. I am learning about ADC. My initialization funcion is as following:
As you can see I pass DEFAULT_VREF to function esp_adc_cal_characterize.
After that, I am taking measurements using the function below:
And I am getting the following printed to serial terminal:
My question is:
I tried to change the variable DEFAULT_VREF to different values (I tried 1000, 1100, 1200) and the measurements always remain the same. Why does this not affect the adc measurements? Am I doing something wrong? The function description says that this VREF is only taken if calibration from efuse is not available. Does that mean that I should not be overwriting the factory calibration as I might make it even worse? (The reason why I try to do this because I am getting horrible ADC error). sometimes even up to 50mV difference. This vary from different boards that I test on.
Code: Select all
void ADC_Init(void)
{
// ADC config
adc1_config_width(ADC_WIDTH_BIT_12);
//adc1_config_channel_atten(ADC1_CHANNEL_5,ADC_ATTEN_DB_11); //GPIO33
adc1_config_channel_atten(ADC1_CHANNEL_0,ADC_ATTEN_DB_11);
adc1_config_channel_atten(ADC1_CHANNEL_3,ADC_ATTEN_DB_11);
adc1_config_channel_atten(ADC1_CHANNEL_6,ADC_ATTEN_DB_11);
adc_chars = (esp_adc_cal_characteristics_t *)calloc(1, sizeof(esp_adc_cal_characteristics_t));
esp_adc_cal_value_t val_type = esp_adc_cal_characterize(unit, atten, width, DEFAULT_VREF, adc_chars);
print_char_val_type(val_type);
}
After that, I am taking measurements using the function below:
Code: Select all
uint32_t app_temp_average_raw = 0;
int counter = 0;
for(int i = 0;i <20;i++){ //take 20 samples and average the result for better estimate
uint32_t app_reading = adc1_get_raw(ADC1_CHANNEL_0); //adc in 5
uint32_t app_voltage = esp_adc_cal_raw_to_voltage(app_reading, adc_chars);
app_temp_average_raw = app_temp_average_raw + app_voltage;
counter ++;
vTaskDelay(10/portTICK_PERIOD_MS);
}
app_temp_average_raw = (double)app_temp_average_raw/(double)counter;
printf("%u\n",app_temp_average_raw);
return true;
Code: Select all
app_adc_raw
1013
app_adc_raw
1014
app_adc_raw
1011
app_adc_raw
1013
My question is:
I tried to change the variable DEFAULT_VREF to different values (I tried 1000, 1100, 1200) and the measurements always remain the same. Why does this not affect the adc measurements? Am I doing something wrong? The function description says that this VREF is only taken if calibration from efuse is not available. Does that mean that I should not be overwriting the factory calibration as I might make it even worse? (The reason why I try to do this because I am getting horrible ADC error). sometimes even up to 50mV difference. This vary from different boards that I test on.