Skip to content

Commit

Permalink
Merge branch 'bugfix/fix_wrong_adc_attenuation_name_v5.2' into 'relea…
Browse files Browse the repository at this point in the history
…se/v5.2'

fix(adc): rename ADC_ATTEN_DB_11 to ADC_ATTEN_DB_12 (v5.2)

See merge request espressif/esp-idf!26966
  • Loading branch information
suda-morris committed Nov 8, 2023
2 parents f8268a2 + f01a40a commit 02cacc6
Show file tree
Hide file tree
Showing 33 changed files with 68 additions and 67 deletions.
2 changes: 1 addition & 1 deletion components/driver/deprecated/adc_i2s_deprecated.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ esp_pm_lock_handle_t adc_digi_arbiter_lock = NULL;
ESP32 Depricated ADC APIs and functions
---------------------------------------------------------------*/
#define DIG_ADC_OUTPUT_FORMAT_DEFUALT (ADC_DIGI_FORMAT_12BIT)
#define DIG_ADC_ATTEN_DEFUALT (ADC_ATTEN_DB_11)
#define DIG_ADC_ATTEN_DEFUALT (ADC_ATTEN_DB_12)
#define DIG_ADC_BIT_WIDTH_DEFUALT (3) //3 for ADC_WIDTH_BIT_12

/**
Expand Down
2 changes: 1 addition & 1 deletion components/driver/deprecated/adc_legacy.c
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ int adc1_get_raw(adc1_channel_t channel)
esp_err_t adc2_config_channel_atten(adc2_channel_t channel, adc_atten_t atten)
{
ESP_RETURN_ON_FALSE(channel < SOC_ADC_CHANNEL_NUM(ADC_UNIT_2), ESP_ERR_INVALID_ARG, ADC_TAG, "ADC2 channel error");
ESP_RETURN_ON_FALSE((atten <= ADC_ATTEN_DB_11), ESP_ERR_INVALID_ARG, ADC_TAG, "ADC2 Atten Err");
ESP_RETURN_ON_FALSE((atten <= ADC_ATTEN_DB_12), ESP_ERR_INVALID_ARG, ADC_TAG, "ADC2 Atten Err");

esp_err_t ret = ESP_OK;
s_atten2_single[channel] = atten;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#define ADC_TEST_WIDTH ADC_BITWIDTH_13
#endif

#define ADC_TEST_ATTEN ADC_ATTEN_DB_11
#define ADC_TEST_ATTEN ADC_ATTEN_DB_12

TEST_CASE("DAC_API_basic_logic_test", "[dac]")
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ static const char *TAG = "test_dac";
#elif defined CONFIG_IDF_TARGET_ESP32S2
#define ADC_TEST_WIDTH ADC_WIDTH_BIT_13 //ESP32S2 only support 13 bit width
#endif
#define ADC_TEST_ATTEN ADC_ATTEN_DB_11
#define ADC_TEST_ATTEN ADC_ATTEN_DB_12

#if CONFIG_IDF_TARGET_ESP32
#define ADC_TEST_CHANNEL_NUM ADC2_CHANNEL_8 // GPIO25
Expand Down Expand Up @@ -174,8 +174,8 @@ TEST_CASE("esp32s2_adc2-dac_with_adc2_calibration", "[dac_legacy]")
subtest_adc_dac(1250, &chars);

printf("Test 11dB atten...\n");
adc2_config_channel_atten((adc2_channel_t)ADC_TEST_CHANNEL_NUM, ADC_ATTEN_DB_11);
esp_adc_cal_characterize(ADC_UNIT_2, ADC_ATTEN_DB_11, ADC_WIDTH_BIT_13, 0, &chars);
adc2_config_channel_atten((adc2_channel_t)ADC_TEST_CHANNEL_NUM, ADC_ATTEN_DB_12);
esp_adc_cal_characterize(ADC_UNIT_2, ADC_ATTEN_DB_12, ADC_WIDTH_BIT_13, 0, &chars);
printf("a %"PRIu32", b %"PRIu32"\n", chars.coeff_a, chars.coeff_b);
subtest_adc_dac(1500, &chars);
subtest_adc_dac(2500, &chars);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ TEST_CASE("I2S_adc_test", "[i2s_legacy]")
i2s_driver_install(I2S_NUM_0, &i2s_config, 0, NULL);
// init ADC pad
i2s_set_adc_mode(ADC_UNIT_1, ADC1_CHANNEL_4);
// enable adc sampling, ADC_WIDTH_BIT_12, ADC_ATTEN_DB_11 hard-coded in adc_i2s_mode_init
// enable adc sampling, ADC_WIDTH_BIT_12, ADC_ATTEN_DB_12 hard-coded in adc_i2s_mode_init
i2s_adc_enable(I2S_NUM_0);
// init read buffer
uint16_t *i2sReadBuffer = (uint16_t *)calloc(1024, sizeof(uint16_t));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ TEST_CASE("Legacy ADC oneshot high/low test", "[legacy_adc_oneshot]")
int adc_raw = 0;
//ADC1 config
TEST_ESP_OK(adc1_config_width(ADC_WIDTH_BIT_DEFAULT));
TEST_ESP_OK(adc1_config_channel_atten(ADC1_TEST_CHAN0, ADC_ATTEN_DB_11));
TEST_ESP_OK(adc1_config_channel_atten(ADC1_TEST_CHAN0, ADC_ATTEN_DB_12));
#if ADC_TEST_ADC2
//ADC2 config
TEST_ESP_OK(adc2_config_channel_atten(ADC2_TEST_CHAN0, ADC_ATTEN_DB_11));
TEST_ESP_OK(adc2_config_channel_atten(ADC2_TEST_CHAN0, ADC_ATTEN_DB_12));
#endif

test_adc_set_io_level(ADC_UNIT_1, (adc1_channel_t)ADC1_TEST_CHAN0, 0);
Expand Down
10 changes: 5 additions & 5 deletions components/efuse/esp32c2/esp_efuse_rtc_calib.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ uint32_t esp_efuse_rtc_calib_get_init_code(int version, uint32_t adc_unit, int a
{
assert((version >= ESP_EFUSE_ADC_CALIB_VER_MIN) &&
(version <= ESP_EFUSE_ADC_CALIB_VER_MAX));
assert(atten <= ADC_ATTEN_DB_11);
assert(atten <= ADC_ATTEN_DB_12);
(void) adc_unit;

if (atten == ADC_ATTEN_DB_2_5 || atten == ADC_ATTEN_DB_6) {
/**
* - ESP32C2 only supports HW calibration on ADC_ATTEN_DB_0 and ADC_ATTEN_DB_11
* - ESP32C2 only supports HW calibration on ADC_ATTEN_DB_0 and ADC_ATTEN_DB_12
* - For other attenuation, we just return default value, which is 0.
*/
return 0;
Expand All @@ -56,7 +56,7 @@ uint32_t esp_efuse_rtc_calib_get_init_code(int version, uint32_t adc_unit, int a
if (atten == ADC_ATTEN_DB_0) {
init_code = adc_icode_diff_atten0 + 2160;
} else {
//ADC_ATTEN_DB_11
//ADC_ATTEN_DB_12
init_code = adc_icode_diff_atten3 + adc_icode_diff_atten0 + 2160;
}

Expand All @@ -76,7 +76,7 @@ esp_err_t esp_efuse_rtc_calib_get_cal_voltage(int version, uint32_t adc_unit, in

if (atten == ADC_ATTEN_DB_2_5 || atten == ADC_ATTEN_DB_6) {
/**
* - ESP32C2 only supports SW calibration on ADC_ATTEN_DB_0 and ADC_ATTEN_DB_11
* - ESP32C2 only supports SW calibration on ADC_ATTEN_DB_0 and ADC_ATTEN_DB_12
* - For other attenuation, we need to return an error, informing upper layer SW calibration driver
* to deal with the error.
*/
Expand All @@ -101,7 +101,7 @@ esp_err_t esp_efuse_rtc_calib_get_cal_voltage(int version, uint32_t adc_unit, in
*out_digi = adc_vol_diff_atten0 + 1540;
*out_vol_mv = 400;
} else {
//ADC_ATTEN_DB_11
//ADC_ATTEN_DB_12
*out_digi = adc_vol_diff_atten0 + 1540 - adc_vol_diff_atten3 - 123;
*out_vol_mv = 1370;
}
Expand Down
6 changes: 3 additions & 3 deletions components/esp_adc/deprecated/esp32/esp_adc_cal_legacy.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ esp_adc_cal_value_t esp_adc_cal_characterize(adc_unit_t adc_num,
chars->bit_width = bit_width;
chars->vref = (EFUSE_VREF_ENABLED && efuse_vref_present) ? read_efuse_vref() : default_vref;
//Initialize fields for lookup table if necessary
if (LUT_ENABLED && atten == ADC_ATTEN_DB_11) {
if (LUT_ENABLED && atten == ADC_ATTEN_DB_12) {
chars->low_curve = (adc_num == ADC_UNIT_1) ? lut_adc1_low : lut_adc2_low;
chars->high_curve = (adc_num == ADC_UNIT_1) ? lut_adc1_high : lut_adc2_high;
} else {
Expand All @@ -336,8 +336,8 @@ uint32_t esp_adc_cal_raw_to_voltage(uint32_t adc_reading, const esp_adc_cal_char
adc_reading = ADC_12_BIT_RES - 1; //Set to 12bit res max
}

if (LUT_ENABLED && (chars->atten == ADC_ATTEN_DB_11) && (adc_reading >= LUT_LOW_THRESH)) { //Check if in non-linear region
//Use lookup table to get voltage in non linear portion of ADC_ATTEN_DB_11
if (LUT_ENABLED && (chars->atten == ADC_ATTEN_DB_12) && (adc_reading >= LUT_LOW_THRESH)) { //Check if in non-linear region
//Use lookup table to get voltage in non linear portion of ADC_ATTEN_DB_12
uint32_t lut_voltage = calculate_voltage_lut(adc_reading, chars->vref, chars->low_curve, chars->high_curve);
if (adc_reading <= LUT_HIGH_THRESH) { //If ADC is transitioning from linear region to non-linear region
//Linearly interpolate between linear voltage and lut voltage
Expand Down
2 changes: 1 addition & 1 deletion components/esp_adc/deprecated/esp32s2/esp_adc_cal_legacy.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ static bool prepare_calib_data_for(adc_unit_t adc_num, adc_atten_t atten, adc_ca
case ADC_ATTEN_DB_6:
parsed_data_storage->efuse_data.ver2.adc_calib_high_voltage = 1000;
break;
case ADC_ATTEN_DB_11:
case ADC_ATTEN_DB_12:
parsed_data_storage->efuse_data.ver2.adc_calib_high_voltage = 2000;
break;
default:
Expand Down
6 changes: 3 additions & 3 deletions components/esp_adc/esp32/adc_cali_line_fitting.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ esp_err_t adc_cali_create_scheme_line_fitting(const adc_cali_line_fitting_config
chars->atten = config->atten;
chars->bitwidth = (config->bitwidth == ADC_BITWIDTH_DEFAULT) ? ADC_BITWIDTH_12 : config->bitwidth;
//Initialize fields for lookup table if necessary
if (LUT_ENABLED && config->atten == ADC_ATTEN_DB_11) {
if (LUT_ENABLED && config->atten == ADC_ATTEN_DB_12) {
chars->low_curve = (config->unit_id == ADC_UNIT_1) ? lut_adc1_low : lut_adc2_low;
chars->high_curve = (config->unit_id == ADC_UNIT_1) ? lut_adc1_high : lut_adc2_high;
} else {
Expand Down Expand Up @@ -251,8 +251,8 @@ static esp_err_t cali_raw_to_voltage(void *arg, int raw, int *voltage)
raw = ADC_12_BIT_RES - 1; //Set to 12bit res max
}

if (LUT_ENABLED && (ctx->atten == ADC_ATTEN_DB_11) && (raw >= LUT_LOW_THRESH)) { //Check if in non-linear region
//Use lookup table to get voltage in non linear portion of ADC_ATTEN_DB_11
if (LUT_ENABLED && (ctx->atten == ADC_ATTEN_DB_12) && (raw >= LUT_LOW_THRESH)) { //Check if in non-linear region
//Use lookup table to get voltage in non linear portion of ADC_ATTEN_DB_12
uint32_t lut_voltage = calculate_voltage_lut(raw, ctx->vref, ctx->low_curve, ctx->high_curve);
if (raw <= LUT_HIGH_THRESH) { //If ADC is transitioning from linear region to non-linear region
//Linearly interpolate between linear voltage and lut voltage
Expand Down
2 changes: 1 addition & 1 deletion components/esp_adc/esp32c2/adc_cali_line_fitting.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ static esp_err_t cali_raw_to_voltage(void *arg, int raw, int *voltage)
static esp_err_t check_valid(const adc_cali_line_fitting_config_t *config)
{
ESP_RETURN_ON_FALSE(config->unit_id < SOC_ADC_PERIPH_NUM, ESP_ERR_INVALID_ARG, TAG, "invalid ADC unit");
ESP_RETURN_ON_FALSE((config->atten == ADC_ATTEN_DB_0 || config->atten == ADC_ATTEN_DB_11), ESP_ERR_NOT_SUPPORTED, TAG, "only ADC_ATTEN_DB_0 and ADC_ATTEN_DB_11 are supported");
ESP_RETURN_ON_FALSE((config->atten == ADC_ATTEN_DB_0 || config->atten == ADC_ATTEN_DB_12), ESP_ERR_NOT_SUPPORTED, TAG, "only ADC_ATTEN_DB_0 and ADC_ATTEN_DB_12 are supported");
if (config->atten == ADC_ATTEN_DB_0) {
ESP_LOGW(TAG, "Experimental: ADC Atten 0 calibration can now only used for inputs lower than 950mV. Calibration Scheme may get updated, DON'T USE FOR MASS PRODUCTION!");
}
Expand Down
2 changes: 1 addition & 1 deletion components/esp_adc/esp32s2/adc_cali_line_fitting.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ static bool prepare_calib_data_for(adc_unit_t unit_id, adc_atten_t atten, adc_ca
case ADC_ATTEN_DB_6:
parsed_data_storage->efuse_data.ver2.adc_calib_high_voltage = 1000;
break;
case ADC_ATTEN_DB_11:
case ADC_ATTEN_DB_12:
parsed_data_storage->efuse_data.ver2.adc_calib_high_voltage = 2000;
break;
default:
Expand Down
6 changes: 3 additions & 3 deletions components/esp_adc/test_apps/adc/main/test_adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ TEST_CASE("ADC oneshot high/low test", "[adc_oneshot]")
//-------------ADC1 TEST Channel 0 Config---------------//
adc_oneshot_chan_cfg_t config = {
.bitwidth = ADC_BITWIDTH_DEFAULT,
.atten = ADC_ATTEN_DB_11,
.atten = ADC_ATTEN_DB_12,
};
TEST_ESP_OK(adc_oneshot_config_channel(adc1_handle, ADC1_TEST_CHAN0, &config));

Expand Down Expand Up @@ -283,7 +283,7 @@ TEST_CASE("ADC continuous monitor init_deinit", "[adc]")

adc_digi_pattern_config_t adc_pattern[SOC_ADC_PATT_LEN_MAX] = {0};
for (int i = 0; i < 1; i++) {
adc_pattern[i].atten = ADC_ATTEN_DB_11;
adc_pattern[i].atten = ADC_ATTEN_DB_12;
adc_pattern[i].channel = i;
adc_pattern[i].unit = ADC_UNIT_1;
adc_pattern[i].bit_width = SOC_ADC_DIGI_MAX_BITWIDTH;
Expand Down Expand Up @@ -401,7 +401,7 @@ TEST_CASE("ADC continuous monitor functionary", "[adc][manual][ignore]")

adc_digi_pattern_config_t adc_pattern[SOC_ADC_PATT_LEN_MAX] = {0};
for (int i = 0; i < 2; i++) {
adc_pattern[i].atten = ADC_ATTEN_DB_11;
adc_pattern[i].atten = ADC_ATTEN_DB_12;
adc_pattern[i].channel = TEST_ADC_CHANNEL;
adc_pattern[i].unit = ADC_UNIT_1;
adc_pattern[i].bit_width = SOC_ADC_DIGI_MAX_BITWIDTH;
Expand Down
6 changes: 3 additions & 3 deletions components/esp_adc/test_apps/adc/main/test_adc_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ TEST_CASE("ADC oneshot fast work with ISR", "[adc_oneshot]")
//-------------ADC1 TEST Channel 0 Config---------------//
adc_oneshot_chan_cfg_t config = {
.bitwidth = ADC_BITWIDTH_DEFAULT,
.atten = ADC_ATTEN_DB_11,
.atten = ADC_ATTEN_DB_12,
};
TEST_ESP_OK(adc_oneshot_config_channel(isr_test_ctx.oneshot_handle, ADC1_TEST_CHAN0, &config));

Expand Down Expand Up @@ -171,7 +171,7 @@ TEST_CASE("ADC continuous big conv_frame_size test", "[adc_continuous]")
.format = ADC_DRIVER_TEST_OUTPUT_TYPE,
};
adc_digi_pattern_config_t adc_pattern[SOC_ADC_PATT_LEN_MAX] = {0};
adc_pattern[0].atten = ADC_ATTEN_DB_11;
adc_pattern[0].atten = ADC_ATTEN_DB_12;
adc_pattern[0].channel = ADC1_TEST_CHAN0;
adc_pattern[0].unit = ADC_UNIT_1;
adc_pattern[0].bit_width = SOC_ADC_DIGI_MAX_BITWIDTH;
Expand Down Expand Up @@ -229,7 +229,7 @@ TEST_CASE("ADC continuous flush internal pool", "[adc_continuous][mannual][ignor
.format = ADC_DRIVER_TEST_OUTPUT_TYPE,
};
adc_digi_pattern_config_t adc_pattern[SOC_ADC_PATT_LEN_MAX] = {0};
adc_pattern[0].atten = ADC_ATTEN_DB_11;
adc_pattern[0].atten = ADC_ATTEN_DB_12;
adc_pattern[0].channel = ADC1_TEST_CHAN0;
adc_pattern[0].unit = ADC_UNIT_1;
adc_pattern[0].bit_width = SOC_ADC_DIGI_MAX_BITWIDTH;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ TEST_CASE("ADC oneshot fast work with ISR and Flash", "[adc_oneshot]")
//-------------ADC1 TEST Channel 0 Config---------------//
adc_oneshot_chan_cfg_t config = {
.bitwidth = ADC_BITWIDTH_DEFAULT,
.atten = ADC_ATTEN_DB_11,
.atten = ADC_ATTEN_DB_12,
};
TEST_ESP_OK(adc_oneshot_config_channel(oneshot_handle, ADC1_TEST_CHAN0, &config));

Expand Down
16 changes: 8 additions & 8 deletions components/esp_adc/test_apps/adc/main/test_adc_performance.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,29 +269,29 @@ TEST_CASE("ADC1 continuous raw average and std_deviation", "[adc_continuous][man

TEST_CASE("ADC1 continuous std deviation performance, no filter", "[adc_continuous][performance]")
{
float std = test_adc_continuous_std(ADC_ATTEN_DB_11, false, 0, true);
float std = test_adc_continuous_std(ADC_ATTEN_DB_12, false, 0, true);
TEST_PERFORMANCE_LESS_THAN(ADC_CONTINUOUS_STD_ATTEN3_NO_FILTER, "%.2f", std);
}

#if SOC_ADC_DIG_IIR_FILTER_SUPPORTED
TEST_CASE("ADC1 continuous std deviation performance, with filter", "[adc_continuous][performance]")
{
float std = test_adc_continuous_std(ADC_ATTEN_DB_11, false, 0, true);
float std = test_adc_continuous_std(ADC_ATTEN_DB_12, false, 0, true);
TEST_PERFORMANCE_LESS_THAN(ADC_CONTINUOUS_STD_ATTEN3_NO_FILTER, "%.2f", std);

std = test_adc_continuous_std(ADC_ATTEN_DB_11, true, ADC_DIGI_IIR_FILTER_COEFF_2, true);
std = test_adc_continuous_std(ADC_ATTEN_DB_12, true, ADC_DIGI_IIR_FILTER_COEFF_2, true);
TEST_PERFORMANCE_LESS_THAN(ADC_CONTINUOUS_STD_ATTEN3_FILTER_2, "%.2f", std);

std = test_adc_continuous_std(ADC_ATTEN_DB_11, true, ADC_DIGI_IIR_FILTER_COEFF_4, true);
std = test_adc_continuous_std(ADC_ATTEN_DB_12, true, ADC_DIGI_IIR_FILTER_COEFF_4, true);
TEST_PERFORMANCE_LESS_THAN(ADC_CONTINUOUS_STD_ATTEN3_FILTER_4, "%.2f", std);

std = test_adc_continuous_std(ADC_ATTEN_DB_11, true, ADC_DIGI_IIR_FILTER_COEFF_8, true);
std = test_adc_continuous_std(ADC_ATTEN_DB_12, true, ADC_DIGI_IIR_FILTER_COEFF_8, true);
TEST_PERFORMANCE_LESS_THAN(ADC_CONTINUOUS_STD_ATTEN3_FILTER_8, "%.2f", std);

std = test_adc_continuous_std(ADC_ATTEN_DB_11, true, ADC_DIGI_IIR_FILTER_COEFF_16, true);
std = test_adc_continuous_std(ADC_ATTEN_DB_12, true, ADC_DIGI_IIR_FILTER_COEFF_16, true);
TEST_PERFORMANCE_LESS_THAN(ADC_CONTINUOUS_STD_ATTEN3_FILTER_16, "%.2f", std);

std = test_adc_continuous_std(ADC_ATTEN_DB_11, true, ADC_DIGI_IIR_FILTER_COEFF_64, true);
std = test_adc_continuous_std(ADC_ATTEN_DB_12, true, ADC_DIGI_IIR_FILTER_COEFF_64, true);
TEST_PERFORMANCE_LESS_THAN(ADC_CONTINUOUS_STD_ATTEN3_FILTER_64, "%.2f", std);
}
#endif //#if SOC_ADC_DIG_IIR_FILTER_SUPPORTED
Expand Down Expand Up @@ -375,7 +375,7 @@ TEST_CASE("ADC1 oneshot raw average and std_deviation", "[adc_oneshot][manual]")

TEST_CASE("ADC1 oneshot std_deviation performance", "[adc_oneshot][performance]")
{
float std = test_adc_oneshot_std(ADC_ATTEN_DB_11, true);
float std = test_adc_oneshot_std(ADC_ATTEN_DB_12, true);
TEST_PERFORMANCE_LESS_THAN(ADC_ONESHOT_STD_ATTEN3, "%.2f", std);
}
/*---------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion components/esp_adc/test_apps/adc/main/test_adc_wifi.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ __attribute__((unused)) static void adc_work_with_wifi(adc_unit_t unit_id, adc_c
//-------------ADC TEST Channel Config---------------//
adc_oneshot_chan_cfg_t config = {
.bitwidth = ADC_BITWIDTH_DEFAULT,
.atten = ADC_ATTEN_DB_11,
.atten = ADC_ATTEN_DB_12,
};
TEST_ESP_OK(adc_oneshot_config_channel(adc_handle, channel, &config));

Expand Down
4 changes: 2 additions & 2 deletions components/esp_adc/test_apps/adc/main/test_common_adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ __attribute__((unused)) static const char *TAG = "TEST_ADC";
ADC Attenuation
---------------------------------------------------------------*/
#if CONFIG_IDF_TARGET_ESP32C2
adc_atten_t g_test_atten[TEST_ATTEN_NUMS] = {ADC_ATTEN_DB_0, ADC_ATTEN_DB_11};
adc_atten_t g_test_atten[TEST_ATTEN_NUMS] = {ADC_ATTEN_DB_0, ADC_ATTEN_DB_12};
#else
adc_atten_t g_test_atten[TEST_ATTEN_NUMS] = {ADC_ATTEN_DB_0, ADC_ATTEN_DB_2_5, ADC_ATTEN_DB_6, ADC_ATTEN_DB_11};
adc_atten_t g_test_atten[TEST_ATTEN_NUMS] = {ADC_ATTEN_DB_0, ADC_ATTEN_DB_2_5, ADC_ATTEN_DB_6, ADC_ATTEN_DB_12};
#endif

#if SOC_ADC_DIG_IIR_FILTER_SUPPORTED
Expand Down
4 changes: 2 additions & 2 deletions components/esp_hw_support/port/esp32c3/adc2_init_cal.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ extern portMUX_TYPE rtc_spinlock;
static __attribute__((constructor)) void adc2_init_code_calibration(void)
{
adc_hal_calibration_init(ADC_UNIT_2);
adc_calc_hw_calibration_code(ADC_UNIT_2, ADC_ATTEN_DB_11);
adc_calc_hw_calibration_code(ADC_UNIT_2, ADC_ATTEN_DB_12);
portENTER_CRITICAL(&rtc_spinlock);
adc_set_hw_calibration_code(ADC_UNIT_2, ADC_ATTEN_DB_11);
adc_set_hw_calibration_code(ADC_UNIT_2, ADC_ATTEN_DB_12);
portEXIT_CRITICAL(&rtc_spinlock);
}

Expand Down
4 changes: 2 additions & 2 deletions components/esp_hw_support/port/esp32s2/adc2_init_cal.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ extern portMUX_TYPE rtc_spinlock;
static __attribute__((constructor)) void adc2_init_code_calibration(void)
{
adc_hal_calibration_init(ADC_UNIT_2);
adc_calc_hw_calibration_code(ADC_UNIT_2, ADC_ATTEN_DB_11);
adc_calc_hw_calibration_code(ADC_UNIT_2, ADC_ATTEN_DB_12);
portENTER_CRITICAL(&rtc_spinlock);
adc_set_hw_calibration_code(ADC_UNIT_2, ADC_ATTEN_DB_11);
adc_set_hw_calibration_code(ADC_UNIT_2, ADC_ATTEN_DB_12);
portEXIT_CRITICAL(&rtc_spinlock);
}

Expand Down
6 changes: 3 additions & 3 deletions components/hal/esp32s2/include/hal/adc_ll.h
Original file line number Diff line number Diff line change
Expand Up @@ -848,19 +848,19 @@ static inline void adc_ll_rtc_set_arbiter_stable_cycle(uint32_t cycle)
* - 0dB attenuation (ADC_ATTEN_DB_0) gives full-scale voltage 1.1V
* - 2.5dB attenuation (ADC_ATTEN_DB_2_5) gives full-scale voltage 1.5V
* - 6dB attenuation (ADC_ATTEN_DB_6) gives full-scale voltage 2.2V
* - 11dB attenuation (ADC_ATTEN_DB_11) gives full-scale voltage 3.9V (see note below)
* - 12dB attenuation (ADC_ATTEN_DB_12) gives full-scale voltage 3.9V (see note below)
*
* @note The full-scale voltage is the voltage corresponding to a maximum reading (depending on ADC1 configured
* bit width, this value is: 4095 for 12-bits, 2047 for 11-bits, 1023 for 10-bits, 511 for 9 bits.)
*
* @note At 11dB attenuation the maximum voltage is limited by VDD_A, not the full scale voltage.
* @note At 12dB attenuation the maximum voltage is limited by VDD_A, not the full scale voltage.
*
* Due to ADC characteristics, most accurate results are obtained within the following approximate voltage ranges:
*
* - 0dB attenuation (ADC_ATTEN_DB_0) between 100 and 950mV
* - 2.5dB attenuation (ADC_ATTEN_DB_2_5) between 100 and 1250mV
* - 6dB attenuation (ADC_ATTEN_DB_6) between 150 to 1750mV
* - 11dB attenuation (ADC_ATTEN_DB_11) between 150 to 2450mV
* - 12dB attenuation (ADC_ATTEN_DB_12) between 150 to 2450mV
*
* For maximum accuracy, use the ADC calibration APIs and measure voltages within these recommended ranges.
*
Expand Down
Loading

0 comments on commit 02cacc6

Please sign in to comment.