mirror of
https://github.com/espressif/esp-idf.git
synced 2025-07-30 18:57:19 +02:00
Merge branch 'bugfix/fix_wrong_adc_attenuation_name_v5.0' into 'release/v5.0'
fix(adc): rename ADC_ATTEN_DB_11 to ADC_ATTEN_DB_12 (v5.0) See merge request espressif/esp-idf!26968
This commit is contained in:
@ -58,7 +58,7 @@ esp_pm_lock_handle_t adc_digi_arbiter_lock = NULL;
|
|||||||
ESP32 Depricated ADC APIs and functions
|
ESP32 Depricated ADC APIs and functions
|
||||||
---------------------------------------------------------------*/
|
---------------------------------------------------------------*/
|
||||||
#define DIG_ADC_OUTPUT_FORMAT_DEFUALT (ADC_DIGI_FORMAT_12BIT)
|
#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
|
#define DIG_ADC_BIT_WIDTH_DEFUALT (3) //3 for ADC_WIDTH_BIT_12
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -795,7 +795,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_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(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;
|
esp_err_t ret = ESP_OK;
|
||||||
s_atten2_single[channel] = atten;
|
s_atten2_single[channel] = atten;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
@ -30,7 +30,7 @@ static const char *TAG = "test_dac";
|
|||||||
#elif defined CONFIG_IDF_TARGET_ESP32S2
|
#elif defined CONFIG_IDF_TARGET_ESP32S2
|
||||||
#define ADC_TEST_WIDTH ADC_WIDTH_BIT_13 //ESP32S2 only support 13 bit width
|
#define ADC_TEST_WIDTH ADC_WIDTH_BIT_13 //ESP32S2 only support 13 bit width
|
||||||
#endif
|
#endif
|
||||||
#define ADC_TEST_ATTEN ADC_ATTEN_DB_11
|
#define ADC_TEST_ATTEN ADC_ATTEN_DB_12
|
||||||
|
|
||||||
#if CONFIG_IDF_TARGET_ESP32
|
#if CONFIG_IDF_TARGET_ESP32
|
||||||
#define ADC_TEST_CHANNEL_NUM ADC2_CHANNEL_8 // GPIO25
|
#define ADC_TEST_CHANNEL_NUM ADC2_CHANNEL_8 // GPIO25
|
||||||
@ -180,8 +180,8 @@ TEST_CASE("esp32s2 adc2-dac with adc2 calibration", "[adc-dac]")
|
|||||||
subtest_adc_dac(1250, &chars);
|
subtest_adc_dac(1250, &chars);
|
||||||
|
|
||||||
printf("Test 11dB atten...\n");
|
printf("Test 11dB atten...\n");
|
||||||
adc2_config_channel_atten((adc2_channel_t)ADC_TEST_CHANNEL_NUM, ADC_ATTEN_DB_11);
|
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_11, ADC_WIDTH_BIT_13, 0, &chars);
|
esp_adc_cal_characterize(ADC_UNIT_2, ADC_ATTEN_DB_12, ADC_WIDTH_BIT_13, 0, &chars);
|
||||||
printf("a %d, b %d\n", chars.coeff_a, chars.coeff_b);
|
printf("a %d, b %d\n", chars.coeff_a, chars.coeff_b);
|
||||||
subtest_adc_dac(1500, &chars);
|
subtest_adc_dac(1500, &chars);
|
||||||
subtest_adc_dac(2500, &chars);
|
subtest_adc_dac(2500, &chars);
|
||||||
|
@ -114,7 +114,7 @@ TEST_CASE("I2S_adc_test", "[i2s_legacy]")
|
|||||||
i2s_driver_install(I2S_NUM_0, &i2s_config, 0, NULL);
|
i2s_driver_install(I2S_NUM_0, &i2s_config, 0, NULL);
|
||||||
// init ADC pad
|
// init ADC pad
|
||||||
i2s_set_adc_mode(ADC_UNIT_1, ADC1_CHANNEL_4);
|
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);
|
i2s_adc_enable(I2S_NUM_0);
|
||||||
// init read buffer
|
// init read buffer
|
||||||
uint16_t *i2sReadBuffer = (uint16_t *)calloc(1024, sizeof(uint16_t));
|
uint16_t *i2sReadBuffer = (uint16_t *)calloc(1024, sizeof(uint16_t));
|
||||||
|
@ -96,10 +96,10 @@ TEST_CASE("Legacy ADC oneshot high/low test", "[legacy_adc_oneshot]")
|
|||||||
int adc_raw = 0;
|
int adc_raw = 0;
|
||||||
//ADC1 config
|
//ADC1 config
|
||||||
TEST_ESP_OK(adc1_config_width(ADC_WIDTH_BIT_DEFAULT));
|
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
|
#if ADC_TEST_ADC2
|
||||||
//ADC2 config
|
//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
|
#endif
|
||||||
|
|
||||||
test_adc_set_io_level(ADC_UNIT_1, (adc1_channel_t)ADC1_TEST_CHAN0, 0);
|
test_adc_set_io_level(ADC_UNIT_1, (adc1_channel_t)ADC1_TEST_CHAN0, 0);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2020-2022 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2020-2023 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
@ -28,12 +28,12 @@ int esp_efuse_rtc_calib_get_ver(void)
|
|||||||
uint32_t esp_efuse_rtc_calib_get_init_code(int version, uint32_t adc_unit, int atten)
|
uint32_t esp_efuse_rtc_calib_get_init_code(int version, uint32_t adc_unit, int atten)
|
||||||
{
|
{
|
||||||
assert(version == ESP_EFUSE_ADC_CALIB_VER);
|
assert(version == ESP_EFUSE_ADC_CALIB_VER);
|
||||||
assert(atten <= ADC_ATTEN_DB_11);
|
assert(atten <= ADC_ATTEN_DB_12);
|
||||||
(void) adc_unit;
|
(void) adc_unit;
|
||||||
|
|
||||||
if (atten == ADC_ATTEN_DB_2_5 || atten == ADC_ATTEN_DB_6) {
|
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.
|
* - For other attenuation, we just return default value, which is 0.
|
||||||
*/
|
*/
|
||||||
return 0;
|
return 0;
|
||||||
@ -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) {
|
if (atten == ADC_ATTEN_DB_0) {
|
||||||
init_code = adc_icode_diff_atten0 + 2160;
|
init_code = adc_icode_diff_atten0 + 2160;
|
||||||
} else {
|
} else {
|
||||||
//ADC_ATTEN_DB_11
|
//ADC_ATTEN_DB_12
|
||||||
init_code = adc_icode_diff_atten3 + adc_icode_diff_atten0 + 2160;
|
init_code = adc_icode_diff_atten3 + adc_icode_diff_atten0 + 2160;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,12 +66,12 @@ uint32_t esp_efuse_rtc_calib_get_init_code(int version, uint32_t adc_unit, int a
|
|||||||
esp_err_t esp_efuse_rtc_calib_get_cal_voltage(int version, uint32_t adc_unit, int atten, uint32_t *out_digi, uint32_t *out_vol_mv)
|
esp_err_t esp_efuse_rtc_calib_get_cal_voltage(int version, uint32_t adc_unit, int atten, uint32_t *out_digi, uint32_t *out_vol_mv)
|
||||||
{
|
{
|
||||||
assert(version == ESP_EFUSE_ADC_CALIB_VER);
|
assert(version == ESP_EFUSE_ADC_CALIB_VER);
|
||||||
assert(atten <= ADC_ATTEN_DB_11);
|
assert(atten <= ADC_ATTEN_DB_12);
|
||||||
(void) adc_unit;
|
(void) adc_unit;
|
||||||
|
|
||||||
if (atten == ADC_ATTEN_DB_2_5 || atten == ADC_ATTEN_DB_6) {
|
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
|
* - For other attenuation, we need to return an error, informing upper layer SW calibration driver
|
||||||
* to deal with the error.
|
* to deal with the error.
|
||||||
*/
|
*/
|
||||||
@ -96,7 +96,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_digi = adc_vol_diff_atten0 + 1540;
|
||||||
*out_vol_mv = 400;
|
*out_vol_mv = 400;
|
||||||
} else {
|
} else {
|
||||||
//ADC_ATTEN_DB_11
|
//ADC_ATTEN_DB_12
|
||||||
*out_digi = adc_vol_diff_atten0 + 1540 - adc_vol_diff_atten3 - 123;
|
*out_digi = adc_vol_diff_atten0 + 1540 - adc_vol_diff_atten3 - 123;
|
||||||
*out_vol_mv = 1370;
|
*out_vol_mv = 1370;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
@ -312,7 +312,7 @@ esp_adc_cal_value_t esp_adc_cal_characterize(adc_unit_t adc_num,
|
|||||||
chars->bit_width = bit_width;
|
chars->bit_width = bit_width;
|
||||||
chars->vref = (EFUSE_VREF_ENABLED && efuse_vref_present) ? read_efuse_vref() : default_vref;
|
chars->vref = (EFUSE_VREF_ENABLED && efuse_vref_present) ? read_efuse_vref() : default_vref;
|
||||||
//Initialize fields for lookup table if necessary
|
//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->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;
|
chars->high_curve = (adc_num == ADC_UNIT_1) ? lut_adc1_high : lut_adc2_high;
|
||||||
} else {
|
} else {
|
||||||
@ -332,8 +332,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
|
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
|
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_11
|
//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);
|
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
|
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
|
//Linearly interpolate between linear voltage and lut voltage
|
||||||
|
@ -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:
|
case ADC_ATTEN_DB_6:
|
||||||
parsed_data_storage->efuse_data.ver2.adc_calib_high_voltage = 1000;
|
parsed_data_storage->efuse_data.ver2.adc_calib_high_voltage = 1000;
|
||||||
break;
|
break;
|
||||||
case ADC_ATTEN_DB_11:
|
case ADC_ATTEN_DB_12:
|
||||||
parsed_data_storage->efuse_data.ver2.adc_calib_high_voltage = 2000;
|
parsed_data_storage->efuse_data.ver2.adc_calib_high_voltage = 2000;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -192,7 +192,7 @@ esp_err_t adc_cali_create_scheme_line_fitting(const adc_cali_line_fitting_config
|
|||||||
chars->atten = config->atten;
|
chars->atten = config->atten;
|
||||||
chars->bitwidth = (config->bitwidth == ADC_BITWIDTH_DEFAULT) ? ADC_BITWIDTH_12 : config->bitwidth;
|
chars->bitwidth = (config->bitwidth == ADC_BITWIDTH_DEFAULT) ? ADC_BITWIDTH_12 : config->bitwidth;
|
||||||
//Initialize fields for lookup table if necessary
|
//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->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;
|
chars->high_curve = (config->unit_id == ADC_UNIT_1) ? lut_adc1_high : lut_adc2_high;
|
||||||
} else {
|
} else {
|
||||||
@ -253,8 +253,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
|
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
|
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_11
|
//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);
|
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
|
if (raw <= LUT_HIGH_THRESH) { //If ADC is transitioning from linear region to non-linear region
|
||||||
//Linearly interpolate between linear voltage and lut voltage
|
//Linearly interpolate between linear voltage and lut voltage
|
||||||
|
@ -122,7 +122,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)
|
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->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");
|
||||||
|
|
||||||
bool available_oneshot_bitwidth = (config->bitwidth >= SOC_ADC_RTC_MIN_BITWIDTH && config->bitwidth <= SOC_ADC_RTC_MAX_BITWIDTH);
|
bool available_oneshot_bitwidth = (config->bitwidth >= SOC_ADC_RTC_MIN_BITWIDTH && config->bitwidth <= SOC_ADC_RTC_MAX_BITWIDTH);
|
||||||
bool available_dma_bitwidth = (config->bitwidth >= SOC_ADC_DIGI_MIN_BITWIDTH && config->bitwidth <= SOC_ADC_DIGI_MAX_BITWIDTH);
|
bool available_dma_bitwidth = (config->bitwidth >= SOC_ADC_DIGI_MIN_BITWIDTH && config->bitwidth <= SOC_ADC_DIGI_MAX_BITWIDTH);
|
||||||
|
@ -184,7 +184,7 @@ static bool prepare_calib_data_for(adc_unit_t unit_id, adc_atten_t atten, adc_ca
|
|||||||
case ADC_ATTEN_DB_6:
|
case ADC_ATTEN_DB_6:
|
||||||
parsed_data_storage->efuse_data.ver2.adc_calib_high_voltage = 1000;
|
parsed_data_storage->efuse_data.ver2.adc_calib_high_voltage = 1000;
|
||||||
break;
|
break;
|
||||||
case ADC_ATTEN_DB_11:
|
case ADC_ATTEN_DB_12:
|
||||||
parsed_data_storage->efuse_data.ver2.adc_calib_high_voltage = 2000;
|
parsed_data_storage->efuse_data.ver2.adc_calib_high_voltage = 2000;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -63,7 +63,7 @@ TEST_CASE("ADC oneshot high/low test", "[adc_oneshot]")
|
|||||||
//-------------ADC1 TEST Channel 0 Config---------------//
|
//-------------ADC1 TEST Channel 0 Config---------------//
|
||||||
adc_oneshot_chan_cfg_t config = {
|
adc_oneshot_chan_cfg_t config = {
|
||||||
.bitwidth = ADC_BITWIDTH_DEFAULT,
|
.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));
|
TEST_ESP_OK(adc_oneshot_config_channel(adc1_handle, ADC1_TEST_CHAN0, &config));
|
||||||
|
|
||||||
|
@ -151,7 +151,7 @@ TEST_CASE("adc2 work with wifi","[adc]")
|
|||||||
//-------------ADC2 TEST Channel 0 Config---------------//
|
//-------------ADC2 TEST Channel 0 Config---------------//
|
||||||
adc_oneshot_chan_cfg_t config = {
|
adc_oneshot_chan_cfg_t config = {
|
||||||
.bitwidth = ADC_BITWIDTH_DEFAULT,
|
.bitwidth = ADC_BITWIDTH_DEFAULT,
|
||||||
.atten = ADC_ATTEN_DB_11,
|
.atten = ADC_ATTEN_DB_12,
|
||||||
};
|
};
|
||||||
TEST_ESP_OK(adc_oneshot_config_channel(adc2_handle, TEST_ADC2_CHAN0, &config));
|
TEST_ESP_OK(adc_oneshot_config_channel(adc2_handle, TEST_ADC2_CHAN0, &config));
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ TEST_CASE("ADC oneshot fast work with ISR", "[adc_oneshot]")
|
|||||||
//-------------ADC1 TEST Channel 0 Config---------------//
|
//-------------ADC1 TEST Channel 0 Config---------------//
|
||||||
adc_oneshot_chan_cfg_t config = {
|
adc_oneshot_chan_cfg_t config = {
|
||||||
.bitwidth = ADC_BITWIDTH_DEFAULT,
|
.bitwidth = ADC_BITWIDTH_DEFAULT,
|
||||||
.atten = ADC_ATTEN_DB_11,
|
.atten = ADC_ATTEN_DB_12,
|
||||||
};
|
};
|
||||||
TEST_ESP_OK(adc_oneshot_config_channel(isr_test_ctx.adc_handle, ADC1_TEST_CHAN0, &config));
|
TEST_ESP_OK(adc_oneshot_config_channel(isr_test_ctx.adc_handle, ADC1_TEST_CHAN0, &config));
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ TEST_CASE("ADC oneshot fast work with ISR and Flash", "[adc_oneshot]")
|
|||||||
//-------------ADC1 TEST Channel 0 Config---------------//
|
//-------------ADC1 TEST Channel 0 Config---------------//
|
||||||
adc_oneshot_chan_cfg_t config = {
|
adc_oneshot_chan_cfg_t config = {
|
||||||
.bitwidth = ADC_BITWIDTH_DEFAULT,
|
.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));
|
TEST_ESP_OK(adc_oneshot_config_channel(oneshot_handle, ADC1_TEST_CHAN0, &config));
|
||||||
|
|
||||||
|
@ -18,9 +18,9 @@ __attribute__((unused)) static const char *TAG = "TEST_ADC";
|
|||||||
ADC Attenuation
|
ADC Attenuation
|
||||||
---------------------------------------------------------------*/
|
---------------------------------------------------------------*/
|
||||||
#if CONFIG_IDF_TARGET_ESP32C2
|
#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
|
#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
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
@ -22,9 +22,9 @@ extern portMUX_TYPE rtc_spinlock;
|
|||||||
static __attribute__((constructor)) void adc2_init_code_calibration(void)
|
static __attribute__((constructor)) void adc2_init_code_calibration(void)
|
||||||
{
|
{
|
||||||
adc_hal_calibration_init(ADC_UNIT_2);
|
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);
|
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);
|
portEXIT_CRITICAL(&rtc_spinlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,9 +22,9 @@ extern portMUX_TYPE rtc_spinlock;
|
|||||||
static __attribute__((constructor)) void adc2_init_code_calibration(void)
|
static __attribute__((constructor)) void adc2_init_code_calibration(void)
|
||||||
{
|
{
|
||||||
adc_hal_calibration_init(ADC_UNIT_2);
|
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);
|
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);
|
portEXIT_CRITICAL(&rtc_spinlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
@ -801,19 +801,19 @@ static inline void adc_ll_rtc_set_arbiter_stable_cycle(uint32_t cycle)
|
|||||||
* - 0dB attenuaton (ADC_ATTEN_DB_0) gives full-scale voltage 1.1V
|
* - 0dB attenuaton (ADC_ATTEN_DB_0) gives full-scale voltage 1.1V
|
||||||
* - 2.5dB attenuation (ADC_ATTEN_DB_2_5) gives full-scale voltage 1.5V
|
* - 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
|
* - 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
|
* @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.)
|
* 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:
|
* Due to ADC characteristics, most accurate results are obtained within the following approximate voltage ranges:
|
||||||
*
|
*
|
||||||
* - 0dB attenuaton (ADC_ATTEN_DB_0) between 100 and 950mV
|
* - 0dB attenuaton (ADC_ATTEN_DB_0) between 100 and 950mV
|
||||||
* - 2.5dB attenuation (ADC_ATTEN_DB_2_5) between 100 and 1250mV
|
* - 2.5dB attenuation (ADC_ATTEN_DB_2_5) between 100 and 1250mV
|
||||||
* - 6dB attenuation (ADC_ATTEN_DB_6) between 150 to 1750mV
|
* - 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.
|
* For maximum accuracy, use the ADC calibration APIs and measure voltages within these recommended ranges.
|
||||||
*
|
*
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
@ -1018,19 +1018,19 @@ static inline void adc_ll_rtc_set_arbiter_stable_cycle(uint32_t cycle)
|
|||||||
* - 0dB attenuaton (ADC_ATTEN_DB_0) gives full-scale voltage 1.1V
|
* - 0dB attenuaton (ADC_ATTEN_DB_0) gives full-scale voltage 1.1V
|
||||||
* - 2.5dB attenuation (ADC_ATTEN_DB_2_5) gives full-scale voltage 1.5V
|
* - 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
|
* - 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
|
* @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.)
|
* 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:
|
* Due to ADC characteristics, most accurate results are obtained within the following approximate voltage ranges:
|
||||||
*
|
*
|
||||||
* - 0dB attenuaton (ADC_ATTEN_DB_0) between 100 and 950mV
|
* - 0dB attenuaton (ADC_ATTEN_DB_0) between 100 and 950mV
|
||||||
* - 2.5dB attenuation (ADC_ATTEN_DB_2_5) between 100 and 1250mV
|
* - 2.5dB attenuation (ADC_ATTEN_DB_2_5) between 100 and 1250mV
|
||||||
* - 6dB attenuation (ADC_ATTEN_DB_6) between 150 to 1750mV
|
* - 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.
|
* For maximum accuracy, use the ADC calibration APIs and measure voltages within these recommended ranges.
|
||||||
*
|
*
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2020-2022 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2020-2023 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
@ -40,9 +40,10 @@ typedef enum {
|
|||||||
*/
|
*/
|
||||||
typedef enum {
|
typedef enum {
|
||||||
ADC_ATTEN_DB_0 = 0, ///<No input attenuation, ADC can measure up to approx.
|
ADC_ATTEN_DB_0 = 0, ///<No input attenuation, ADC can measure up to approx.
|
||||||
ADC_ATTEN_DB_2_5 = 1, ///<The input voltage of ADC will be attenuated extending the range of measurement by about 2.5 dB (1.33 x)
|
ADC_ATTEN_DB_2_5 = 1, ///<The input voltage of ADC will be attenuated extending the range of measurement by about 2.5 dB
|
||||||
ADC_ATTEN_DB_6 = 2, ///<The input voltage of ADC will be attenuated extending the range of measurement by about 6 dB (2 x)
|
ADC_ATTEN_DB_6 = 2, ///<The input voltage of ADC will be attenuated extending the range of measurement by about 6 dB
|
||||||
ADC_ATTEN_DB_11 = 3, ///<The input voltage of ADC will be attenuated extending the range of measurement by about 11 dB (3.55 x)
|
ADC_ATTEN_DB_12 = 3, ///<The input voltage of ADC will be attenuated extending the range of measurement by about 12 dB
|
||||||
|
ADC_ATTEN_DB_11 __attribute__((deprecated)) = ADC_ATTEN_DB_12, ///<This is deprecated, it behaves the same as `ADC_ATTEN_DB_12`
|
||||||
} adc_atten_t;
|
} adc_atten_t;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
@ -159,7 +159,7 @@ Other functions that take the :cpp:type:`adc_cali_handle_t` as the first positio
|
|||||||
|
|
||||||
- :ref:`CONFIG_ADC_CAL_EFUSE_TP_ENABLE`, disable this to decrease the code size, if you are aware of the calibration eFuse value :cpp:type:`ADC_CALI_LINE_FITTING_EFUSE_VAL_EFUSE_TP` isn't this one.
|
- :ref:`CONFIG_ADC_CAL_EFUSE_TP_ENABLE`, disable this to decrease the code size, if you are aware of the calibration eFuse value :cpp:type:`ADC_CALI_LINE_FITTING_EFUSE_VAL_EFUSE_TP` isn't this one.
|
||||||
- :ref:`CONFIG_ADC_CAL_EFUSE_VREF_ENABLE`, disable this to decrease the code size, if you are aware of the calibration eFuse value :cpp:type:`ADC_CALI_LINE_FITTING_EFUSE_VAL_EFUSE_VREF` isn't this one.
|
- :ref:`CONFIG_ADC_CAL_EFUSE_VREF_ENABLE`, disable this to decrease the code size, if you are aware of the calibration eFuse value :cpp:type:`ADC_CALI_LINE_FITTING_EFUSE_VAL_EFUSE_VREF` isn't this one.
|
||||||
- :ref:`CONFIG_ADC_CAL_LUT_ENABLE`, disable this to decrease the code size, if you don't calibrate the ADC raw results under :c:macro:`ADC_ATTEN_DB_11`.
|
- :ref:`CONFIG_ADC_CAL_LUT_ENABLE`, disable this to decrease the code size, if you don't calibrate the ADC raw results under :c:macro:`ADC_ATTEN_DB_12`.
|
||||||
|
|
||||||
|
|
||||||
Minimize Noise
|
Minimize Noise
|
||||||
|
@ -100,7 +100,7 @@ Configure Two ADC Channels
|
|||||||
adc_oneshot_chan_cfg_t config = {
|
adc_oneshot_chan_cfg_t config = {
|
||||||
.channel = EXAMPLE_ADC1_CHAN0,
|
.channel = EXAMPLE_ADC1_CHAN0,
|
||||||
.bitwidth = ADC_BITWIDTH_DEFAULT,
|
.bitwidth = ADC_BITWIDTH_DEFAULT,
|
||||||
.atten = ADC_ATTEN_DB_11,
|
.atten = ADC_ATTEN_DB_12,
|
||||||
};
|
};
|
||||||
ESP_ERROR_CHECK(adc_oneshot_config_channel(adc1_handle, &config));
|
ESP_ERROR_CHECK(adc_oneshot_config_channel(adc1_handle, &config));
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ const static char *TAG = "EXAMPLE";
|
|||||||
#endif
|
#endif
|
||||||
#endif //#if EXAMPLE_USE_ADC2
|
#endif //#if EXAMPLE_USE_ADC2
|
||||||
|
|
||||||
#define EXAMPLE_ADC_ATTEN ADC_ATTEN_DB_11
|
#define EXAMPLE_ADC_ATTEN ADC_ATTEN_DB_12
|
||||||
|
|
||||||
static int adc_raw[2][10];
|
static int adc_raw[2][10];
|
||||||
static int voltage[2][10];
|
static int voltage[2][10];
|
||||||
|
@ -281,9 +281,9 @@ void example_i2s_adc_dac(void*arg)
|
|||||||
void adc_read_task(void* arg)
|
void adc_read_task(void* arg)
|
||||||
{
|
{
|
||||||
adc1_config_width(ADC_WIDTH_BIT_12);
|
adc1_config_width(ADC_WIDTH_BIT_12);
|
||||||
adc1_config_channel_atten(ADC1_TEST_CHANNEL, ADC_ATTEN_DB_11);
|
adc1_config_channel_atten(ADC1_TEST_CHANNEL, ADC_ATTEN_DB_12);
|
||||||
esp_adc_cal_characteristics_t characteristics;
|
esp_adc_cal_characteristics_t characteristics;
|
||||||
esp_adc_cal_characterize(ADC_UNIT_1, ADC_ATTEN_DB_11, ADC_WIDTH_BIT_12, V_REF, &characteristics);
|
esp_adc_cal_characterize(ADC_UNIT_1, ADC_ATTEN_DB_12, ADC_WIDTH_BIT_12, V_REF, &characteristics);
|
||||||
while(1) {
|
while(1) {
|
||||||
uint32_t voltage;
|
uint32_t voltage;
|
||||||
vTaskDelay(200 / portTICK_PERIOD_MS);
|
vTaskDelay(200 / portTICK_PERIOD_MS);
|
||||||
|
@ -104,7 +104,7 @@ void app_main(void)
|
|||||||
//-------------ADC1 Channel Config---------------//
|
//-------------ADC1 Channel Config---------------//
|
||||||
adc_oneshot_chan_cfg_t config = {
|
adc_oneshot_chan_cfg_t config = {
|
||||||
.bitwidth = ADC_BITWIDTH_DEFAULT,
|
.bitwidth = ADC_BITWIDTH_DEFAULT,
|
||||||
.atten = ADC_ATTEN_DB_11,
|
.atten = ADC_ATTEN_DB_12,
|
||||||
};
|
};
|
||||||
ESP_ERROR_CHECK(adc_oneshot_config_channel(adc1_handle, ADC1_TEST_CHANNEL, &config));
|
ESP_ERROR_CHECK(adc_oneshot_config_channel(adc1_handle, ADC1_TEST_CHANNEL, &config));
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ static void init_ulp_program(void)
|
|||||||
//-------------ADC1 Channel Config---------------//
|
//-------------ADC1 Channel Config---------------//
|
||||||
// Note: when changing channel here, also change 'adc_channel' constant in adc.S
|
// Note: when changing channel here, also change 'adc_channel' constant in adc.S
|
||||||
adc_oneshot_chan_cfg_t config = {
|
adc_oneshot_chan_cfg_t config = {
|
||||||
.atten = ADC_ATTEN_DB_11,
|
.atten = ADC_ATTEN_DB_12,
|
||||||
.bitwidth = ADC_BITWIDTH_DEFAULT,
|
.bitwidth = ADC_BITWIDTH_DEFAULT,
|
||||||
};
|
};
|
||||||
ESP_ERROR_CHECK(adc_oneshot_config_channel(adc1_handle, ADC_CHANNEL_6, &config));
|
ESP_ERROR_CHECK(adc_oneshot_config_channel(adc1_handle, ADC_CHANNEL_6, &config));
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
#define EXAMPLE_ADC_CHANNEL ADC_CHANNEL_0
|
#define EXAMPLE_ADC_CHANNEL ADC_CHANNEL_0
|
||||||
#define EXAMPLE_ADC_UNIT ADC_UNIT_1
|
#define EXAMPLE_ADC_UNIT ADC_UNIT_1
|
||||||
#define EXAMPLE_ADC_ATTEN ADC_ATTEN_DB_11
|
#define EXAMPLE_ADC_ATTEN ADC_ATTEN_DB_12
|
||||||
#define EXAMPLE_ADC_WIDTH ADC_BITWIDTH_DEFAULT
|
#define EXAMPLE_ADC_WIDTH ADC_BITWIDTH_DEFAULT
|
||||||
|
|
||||||
/* Set high threshold, approx. 1.75V*/
|
/* Set high threshold, approx. 1.75V*/
|
||||||
|
Reference in New Issue
Block a user