esp_adc: added adc digital filter feature
This commit is contained in:
committed by
Armando (Dou Yiwen)
parent
648b1a41c6
commit
3afa671069
@@ -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
|
||||
*/
|
||||
@@ -156,7 +156,7 @@ TEST_CASE("ADC oneshot fast work with ISR and Flash", "[adc_oneshot]")
|
||||
#endif
|
||||
|
||||
#define ADC_TEST_FREQ_HZ (50 * 1000)
|
||||
#define ADC_TEST_PKG_SIZE 100
|
||||
#define ADC_TEST_PKG_SIZE 512
|
||||
static bool IRAM_ATTR NOINLINE_ATTR s_conv_done_cb(adc_continuous_handle_t handle, const adc_continuous_evt_data_t *edata, void *user_data)
|
||||
{
|
||||
test_adc_iram_ctx_t *test_ctx = (test_adc_iram_ctx_t *)user_data;
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
@@ -15,19 +15,21 @@
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "esp_adc/adc_oneshot.h"
|
||||
#include "esp_adc/adc_continuous.h"
|
||||
#include "esp_adc/adc_filter.h"
|
||||
#include "test_common_adc.h"
|
||||
|
||||
#if CONFIG_IDF_TARGET_ESP32 || SOC_ADC_CALIBRATION_V1_SUPPORTED
|
||||
#include "idf_performance.h"
|
||||
|
||||
__attribute__((unused)) static const char *TAG = "TEST_ADC";
|
||||
|
||||
/*---------------------------------------------------------------
|
||||
ADC Oneshot Average / STD_Deviation Test
|
||||
---------------------------------------------------------------*/
|
||||
#define TEST_COUNT (1<<SOC_ADC_RTC_MAX_BITWIDTH)
|
||||
#define MAX_ARRAY_SIZE (1<<SOC_ADC_RTC_MAX_BITWIDTH)
|
||||
#if CONFIG_IDF_TARGET_ESP32
|
||||
#define TEST_STD_ADC1_CHANNEL0 ADC_CHANNEL_5
|
||||
#else
|
||||
#define TEST_STD_ADC1_CHANNEL0 ADC_CHANNEL_2
|
||||
#endif
|
||||
|
||||
static int s_adc_count[MAX_ARRAY_SIZE]={};
|
||||
static int s_adc_count_size;
|
||||
static int *s_p_adc_count;
|
||||
static int s_adc_offset = -1;
|
||||
|
||||
static int s_insert_point(uint32_t value)
|
||||
@@ -36,40 +38,50 @@ static int s_insert_point(uint32_t value)
|
||||
|
||||
if (s_adc_offset < 0) {
|
||||
if (fixed_size) {
|
||||
TEST_ASSERT_GREATER_OR_EQUAL(4096, MAX_ARRAY_SIZE);
|
||||
TEST_ASSERT_GREATER_OR_EQUAL(4096, s_adc_count_size);
|
||||
s_adc_offset = 0; //Fixed to 0 because the array can hold all the data in 12 bits
|
||||
} else {
|
||||
s_adc_offset = MAX((int)value - MAX_ARRAY_SIZE/2, 0);
|
||||
s_adc_offset = MAX((int)value - s_adc_count_size/2, 0);
|
||||
}
|
||||
}
|
||||
|
||||
if (!fixed_size && (value < s_adc_offset || value >= s_adc_offset + MAX_ARRAY_SIZE)) {
|
||||
if (!fixed_size && (value < s_adc_offset || value >= s_adc_offset + s_adc_count_size)) {
|
||||
TEST_ASSERT_GREATER_OR_EQUAL(s_adc_offset, value);
|
||||
TEST_ASSERT_LESS_THAN(s_adc_offset + MAX_ARRAY_SIZE, value);
|
||||
TEST_ASSERT_LESS_THAN(s_adc_offset + s_adc_count_size, value);
|
||||
}
|
||||
|
||||
s_adc_count[value - s_adc_offset] ++;
|
||||
s_p_adc_count[value - s_adc_offset] ++;
|
||||
return value - s_adc_offset;
|
||||
}
|
||||
|
||||
static void s_reset_array(void)
|
||||
static void s_reset_array(int array_size)
|
||||
{
|
||||
memset(s_adc_count, 0, sizeof(s_adc_count));
|
||||
s_adc_count_size = array_size;
|
||||
s_p_adc_count = (int *)heap_caps_calloc(1, s_adc_count_size * sizeof(int), MALLOC_CAP_INTERNAL);
|
||||
TEST_ASSERT(s_p_adc_count);
|
||||
s_adc_offset = -1;
|
||||
}
|
||||
|
||||
static void s_destroy_array(void)
|
||||
{
|
||||
free(s_p_adc_count);
|
||||
s_p_adc_count = NULL;
|
||||
s_adc_count_size = 0;
|
||||
}
|
||||
|
||||
__attribute__((unused))
|
||||
static uint32_t s_get_average(void)
|
||||
{
|
||||
uint32_t sum = 0;
|
||||
int count = 0;
|
||||
for (int i = 0; i < MAX_ARRAY_SIZE; i++) {
|
||||
sum += s_adc_count[i] * (s_adc_offset+i);
|
||||
count += s_adc_count[i];
|
||||
for (int i = 0; i < s_adc_count_size; i++) {
|
||||
sum += s_p_adc_count[i] * (s_adc_offset+i);
|
||||
count += s_p_adc_count[i];
|
||||
}
|
||||
return sum/count;
|
||||
}
|
||||
|
||||
static void s_print_summary(bool figure)
|
||||
static float s_print_summary(bool figure)
|
||||
{
|
||||
const int MAX_WIDTH=20;
|
||||
int max_count = 0;
|
||||
@@ -77,53 +89,220 @@ static void s_print_summary(bool figure)
|
||||
int end = -1;
|
||||
uint32_t sum = 0;
|
||||
int count = 0;
|
||||
for (int i = 0; i < MAX_ARRAY_SIZE; i++) {
|
||||
if (s_adc_count[i] > max_count) {
|
||||
max_count = s_adc_count[i];
|
||||
for (int i = 0; i < s_adc_count_size; i++) {
|
||||
if (s_p_adc_count[i] > max_count) {
|
||||
max_count = s_p_adc_count[i];
|
||||
}
|
||||
if (s_adc_count[i] > 0 && start < 0) {
|
||||
if (s_p_adc_count[i] > 0 && start < 0) {
|
||||
start = i;
|
||||
}
|
||||
if (s_adc_count[i] > 0) {
|
||||
if (s_p_adc_count[i] > 0) {
|
||||
end = i;
|
||||
}
|
||||
count += s_adc_count[i];
|
||||
sum += s_adc_count[i] * (s_adc_offset+i);
|
||||
count += s_p_adc_count[i];
|
||||
sum += s_p_adc_count[i] * (s_adc_offset+i);
|
||||
}
|
||||
|
||||
if (figure) {
|
||||
for (int i = start; i <= end; i++) {
|
||||
printf("%4d ", i+s_adc_offset);
|
||||
int count = s_adc_count[i] * MAX_WIDTH / max_count;
|
||||
int count = s_p_adc_count[i] * MAX_WIDTH / max_count;
|
||||
for (int j = 0; j < count; j++) {
|
||||
putchar('|');
|
||||
}
|
||||
printf(" %d\n", s_adc_count[i]);
|
||||
printf(" %d\n", s_p_adc_count[i]);
|
||||
}
|
||||
}
|
||||
float average = (float)sum/count;
|
||||
|
||||
float variation_square = 0;
|
||||
for (int i = start; i <= end; i ++) {
|
||||
if (s_adc_count[i] == 0) {
|
||||
if (s_p_adc_count[i] == 0) {
|
||||
continue;
|
||||
}
|
||||
float delta = i + s_adc_offset - average;
|
||||
variation_square += (delta * delta) * s_adc_count[i];
|
||||
variation_square += (delta * delta) * s_p_adc_count[i];
|
||||
}
|
||||
|
||||
printf("%d points.\n", count);
|
||||
printf("average: %.1f\n", (float)sum/count);
|
||||
printf("std: %.2f\n", sqrt(variation_square/count));
|
||||
|
||||
return sqrt(variation_square/count);
|
||||
}
|
||||
|
||||
#if CONFIG_IDF_TARGET_ESP32
|
||||
#define TEST_STD_ADC1_CHANNEL0 ADC_CHANNEL_6
|
||||
#if SOC_ADC_DMA_SUPPORTED
|
||||
/*---------------------------------------------------------------
|
||||
ADC Continuous Average / STD_Deviation Test
|
||||
---------------------------------------------------------------*/
|
||||
#if (SOC_ADC_DIGI_RESULT_BYTES == 2)
|
||||
#define ADC_TEST_OUTPUT_TYPE ADC_DIGI_OUTPUT_FORMAT_TYPE1
|
||||
#define EXAMPLE_ADC_GET_CHANNEL(result) ((result).type1.channel)
|
||||
#define EXAMPLE_ADC_GET_DATA(result) ((result).type1.data)
|
||||
#else
|
||||
#define TEST_STD_ADC1_CHANNEL0 ADC_CHANNEL_2
|
||||
#define ADC_TEST_OUTPUT_TYPE ADC_DIGI_OUTPUT_FORMAT_TYPE2
|
||||
#define EXAMPLE_ADC_GET_CHANNEL(result) ((result).type2.channel)
|
||||
#define EXAMPLE_ADC_GET_DATA(result) ((result).type2.data)
|
||||
#endif
|
||||
#define ADC_TEST_FREQ_HZ (50 * 1000)
|
||||
#define ADC_TEST_PKG_SIZE 512
|
||||
#define ADC_TEST_CNT 4096
|
||||
|
||||
|
||||
static bool IRAM_ATTR s_conv_done_cb(adc_continuous_handle_t handle, const adc_continuous_evt_data_t *edata, void *user_data)
|
||||
{
|
||||
BaseType_t mustYield = pdFALSE;
|
||||
TaskHandle_t task_handle = *(TaskHandle_t *)(user_data);
|
||||
//Notify that ADC continuous driver has done enough number of conversions
|
||||
vTaskNotifyGiveFromISR(task_handle, &mustYield);
|
||||
|
||||
return (mustYield == pdTRUE);
|
||||
}
|
||||
|
||||
static float test_adc_continuous_std(adc_atten_t atten, bool filter_en, int filter_coeff, bool is_performance_test)
|
||||
{
|
||||
uint8_t *result = heap_caps_calloc(1, ADC_TEST_CNT * SOC_ADC_DIGI_RESULT_BYTES, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT | MALLOC_CAP_32BIT);
|
||||
TEST_ASSERT(result);
|
||||
bool print_figure = false;
|
||||
TaskHandle_t task_handle = xTaskGetCurrentTaskHandle();
|
||||
|
||||
//-------------ADC Init---------------//
|
||||
adc_continuous_handle_t handle = NULL;
|
||||
adc_continuous_handle_cfg_t adc_config = {
|
||||
.max_store_buf_size = 4096,
|
||||
.conv_frame_size = ADC_TEST_PKG_SIZE,
|
||||
};
|
||||
TEST_ESP_OK(adc_continuous_new_handle(&adc_config, &handle));
|
||||
|
||||
adc_continuous_evt_cbs_t cbs = {
|
||||
.on_conv_done = s_conv_done_cb,
|
||||
};
|
||||
TEST_ESP_OK(adc_continuous_register_event_callbacks(handle, &cbs, &task_handle));
|
||||
|
||||
//-------------ADC Config---------------//
|
||||
adc_continuous_config_t dig_cfg = {
|
||||
.sample_freq_hz = ADC_TEST_FREQ_HZ,
|
||||
.conv_mode = ADC_CONV_SINGLE_UNIT_1,
|
||||
.format = ADC_TEST_OUTPUT_TYPE,
|
||||
};
|
||||
adc_digi_pattern_config_t adc_pattern[SOC_ADC_PATT_LEN_MAX] = {0};
|
||||
adc_pattern[0].atten = atten;
|
||||
adc_pattern[0].channel = TEST_STD_ADC1_CHANNEL0;
|
||||
adc_pattern[0].unit = ADC_UNIT_1;
|
||||
adc_pattern[0].bit_width = SOC_ADC_DIGI_MAX_BITWIDTH;
|
||||
dig_cfg.adc_pattern = adc_pattern;
|
||||
dig_cfg.pattern_num = 1;
|
||||
TEST_ESP_OK(adc_continuous_config(handle, &dig_cfg));
|
||||
|
||||
#if SOC_ADC_DIG_IIR_FILTER_SUPPORTED
|
||||
adc_iir_filter_handle_t filter_hdl = NULL;
|
||||
if (filter_en) {
|
||||
adc_continuous_iir_filter_config_t filter_config = {
|
||||
.unit = ADC_UNIT_1,
|
||||
.channel = TEST_STD_ADC1_CHANNEL0,
|
||||
.coeff = filter_coeff,
|
||||
};
|
||||
TEST_ESP_OK(adc_new_continuous_iir_filter(handle, &filter_config, &filter_hdl));
|
||||
TEST_ESP_OK(adc_continuous_iir_filter_enable(filter_hdl));
|
||||
}
|
||||
#endif
|
||||
|
||||
TEST_CASE("ADC1 oneshot raw average / std_deviation", "[adc_oneshot][ignore][manual]")
|
||||
if (is_performance_test) {
|
||||
test_adc_set_io_middle(ADC_UNIT_1, TEST_STD_ADC1_CHANNEL0);
|
||||
}
|
||||
|
||||
if (filter_en) {
|
||||
ESP_LOGI("TEST_ADC", "Test with atten: %d, filter coeff: %d", atten, filter_coeff);
|
||||
} else {
|
||||
ESP_LOGI("TEST_ADC", "Test with atten: %d, no filter", atten);
|
||||
}
|
||||
|
||||
s_reset_array((1 << SOC_ADC_DIGI_MAX_BITWIDTH));
|
||||
TEST_ESP_OK(adc_continuous_start(handle));
|
||||
|
||||
int remain_count = ADC_TEST_CNT;
|
||||
while (remain_count) {
|
||||
ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
|
||||
int already_got = ADC_TEST_CNT - remain_count;
|
||||
uint32_t ret_num = 0;
|
||||
TEST_ESP_OK(adc_continuous_read(handle, result + already_got * SOC_ADC_DIGI_RESULT_BYTES, ADC_TEST_PKG_SIZE, &ret_num, 0));
|
||||
remain_count -= ret_num / SOC_ADC_DIGI_RESULT_BYTES;
|
||||
}
|
||||
|
||||
adc_digi_output_data_t *p = (void*)result;
|
||||
for (int i = 0; i < ADC_TEST_CNT; i++) {
|
||||
TEST_ASSERT_EQUAL(TEST_STD_ADC1_CHANNEL0, EXAMPLE_ADC_GET_CHANNEL(p[i]));
|
||||
s_insert_point(EXAMPLE_ADC_GET_DATA(p[i]));
|
||||
}
|
||||
float std = s_print_summary(print_figure);
|
||||
|
||||
TEST_ESP_OK(adc_continuous_stop(handle));
|
||||
#if SOC_ADC_DIG_IIR_FILTER_SUPPORTED
|
||||
if (filter_en) {
|
||||
TEST_ESP_OK(adc_continuous_iir_filter_disable(filter_hdl));
|
||||
TEST_ESP_OK(adc_del_continuous_iir_filter(filter_hdl));
|
||||
}
|
||||
#endif
|
||||
TEST_ESP_OK(adc_continuous_deinit(handle));
|
||||
ulTaskNotifyTake(pdTRUE, 0);
|
||||
s_destroy_array();
|
||||
free(result);
|
||||
|
||||
return std;
|
||||
}
|
||||
|
||||
TEST_CASE("ADC1 continuous raw average and std_deviation", "[adc_continuous][manual]")
|
||||
{
|
||||
for (int i = 0; i < TEST_ATTEN_NUMS; i ++) {
|
||||
#if SOC_ADC_DIG_IIR_FILTER_SUPPORTED
|
||||
//filter disabled
|
||||
test_adc_continuous_std(g_test_atten[i], false, 0, false);
|
||||
//filter with different coeffs
|
||||
for (int j = 0; j < TEST_FILTER_COEFF_NUMS; j ++) {
|
||||
test_adc_continuous_std(g_test_atten[i], true, g_test_filter_coeff[j], false);
|
||||
}
|
||||
#else
|
||||
//filter disabled
|
||||
test_adc_continuous_std(g_test_atten[i], false, 0, false);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
TEST_PERFORMANCE_LESS_THAN(ADC_CONTINUOUS_STD_ATTEN3_FILTER_64, "%.2f", std);
|
||||
}
|
||||
#endif //#if SOC_ADC_DIG_IIR_FILTER_SUPPORTED
|
||||
#endif //#if SOC_ADC_DMA_SUPPORTED
|
||||
|
||||
#if CONFIG_IDF_TARGET_ESP32 || SOC_ADC_CALIBRATION_V1_SUPPORTED
|
||||
/*---------------------------------------------------------------
|
||||
ADC Oneshot Average / STD_Deviation Test
|
||||
---------------------------------------------------------------*/
|
||||
static float test_adc_oneshot_std(adc_atten_t atten, bool is_performance_test)
|
||||
{
|
||||
adc_channel_t channel = TEST_STD_ADC1_CHANNEL0;
|
||||
int raw = 0;
|
||||
@@ -144,50 +323,62 @@ TEST_CASE("ADC1 oneshot raw average / std_deviation", "[adc_oneshot][ignore][man
|
||||
|
||||
//-------------ADC Calibration Init---------------//
|
||||
bool do_calibration = false;
|
||||
adc_cali_handle_t cali_handle[TEST_ATTEN_NUMS] = {};
|
||||
for (int i = 0; i < TEST_ATTEN_NUMS; i++) {
|
||||
do_calibration = test_adc_calibration_init(ADC_UNIT_1, g_test_atten[i], ADC_BITWIDTH_DEFAULT, &cali_handle[i]);
|
||||
}
|
||||
adc_cali_handle_t cali_handle = NULL;
|
||||
do_calibration = test_adc_calibration_init(ADC_UNIT_1, atten, ADC_BITWIDTH_DEFAULT, &cali_handle);
|
||||
if (!do_calibration) {
|
||||
ESP_LOGW(TAG, "calibration fail, jump calibration\n");
|
||||
}
|
||||
|
||||
for (int i = 0; i < TEST_ATTEN_NUMS; i++) {
|
||||
//-------------ADC1 Channel Config---------------//
|
||||
config.atten = atten;
|
||||
TEST_ESP_OK(adc_oneshot_config_channel(adc1_handle, channel, &config));
|
||||
ESP_LOGI("TEST_ADC", "Test with atten: %d", atten);
|
||||
|
||||
//-------------ADC1 Channel Config---------------//
|
||||
config.atten = g_test_atten[i];
|
||||
TEST_ESP_OK(adc_oneshot_config_channel(adc1_handle, channel, &config));
|
||||
ESP_LOGI("TEST_ADC", "Test with atten: %d", g_test_atten[i]);
|
||||
s_reset_array((1 << SOC_ADC_RTC_MAX_BITWIDTH));
|
||||
|
||||
while (1) {
|
||||
|
||||
s_reset_array();
|
||||
|
||||
for (int i = 0; i < TEST_COUNT; i++) {
|
||||
TEST_ESP_OK(adc_oneshot_read(adc1_handle, channel, &raw));
|
||||
s_insert_point(raw);
|
||||
}
|
||||
s_print_summary(print_figure);
|
||||
break;
|
||||
}
|
||||
|
||||
if (do_calibration) {
|
||||
uint32_t raw = s_get_average();
|
||||
int voltage_mv = 0;
|
||||
TEST_ESP_OK(adc_cali_raw_to_voltage(cali_handle[i], raw, &voltage_mv));
|
||||
printf("Voltage = %d mV\n", voltage_mv);
|
||||
}
|
||||
if (is_performance_test) {
|
||||
test_adc_set_io_middle(ADC_UNIT_1, TEST_STD_ADC1_CHANNEL0);
|
||||
}
|
||||
|
||||
TEST_ESP_OK(adc_oneshot_del_unit(adc1_handle));
|
||||
for (int i = 0; i < TEST_ATTEN_NUMS; i++) {
|
||||
if (cali_handle[i]) {
|
||||
test_adc_calibration_deinit(cali_handle[i]);
|
||||
float std;
|
||||
while (1) {
|
||||
for (int i = 0; i < s_adc_count_size; i++) {
|
||||
TEST_ESP_OK(adc_oneshot_read(adc1_handle, channel, &raw));
|
||||
s_insert_point(raw);
|
||||
}
|
||||
std = s_print_summary(print_figure);
|
||||
break;
|
||||
}
|
||||
|
||||
if (do_calibration) {
|
||||
uint32_t raw = s_get_average();
|
||||
int voltage_mv = 0;
|
||||
TEST_ESP_OK(adc_cali_raw_to_voltage(cali_handle, raw, &voltage_mv));
|
||||
printf("Voltage = %d mV\n", voltage_mv);
|
||||
}
|
||||
|
||||
s_destroy_array();
|
||||
|
||||
TEST_ESP_OK(adc_oneshot_del_unit(adc1_handle));
|
||||
if (cali_handle) {
|
||||
test_adc_calibration_deinit(cali_handle);
|
||||
}
|
||||
|
||||
return std;
|
||||
}
|
||||
|
||||
TEST_CASE("ADC1 oneshot raw average and std_deviation", "[adc_oneshot][manual]")
|
||||
{
|
||||
for (int i = 0; i < TEST_ATTEN_NUMS; i++) {
|
||||
test_adc_oneshot_std(g_test_atten[i], false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("ADC1 oneshot std_deviation performance", "[adc_oneshot][performance]")
|
||||
{
|
||||
float std = test_adc_oneshot_std(ADC_ATTEN_DB_11, true);
|
||||
TEST_PERFORMANCE_LESS_THAN(ADC_ONESHOT_STD_ATTEN3, "%.2f", std);
|
||||
}
|
||||
/*---------------------------------------------------------------
|
||||
ADC Calibration Speed
|
||||
---------------------------------------------------------------*/
|
||||
@@ -277,14 +468,14 @@ static void s_adc_cali_speed(adc_unit_t unit_id, adc_channel_t channel)
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("ADC1 Calibration Speed", "[adc][ignore][manual]")
|
||||
TEST_CASE("ADC1 Calibration Speed", "[adc][manual]")
|
||||
{
|
||||
s_adc_cali_speed(ADC_UNIT_1, ADC1_CALI_SPEED_TEST_CHAN0);
|
||||
}
|
||||
|
||||
#if (SOC_ADC_PERIPH_NUM >= 2) && !CONFIG_IDF_TARGET_ESP32C3
|
||||
//ESP32C3 ADC2 oneshot mode is not supported anymore
|
||||
TEST_CASE("ADC2 Calibration Speed", "[adc][ignore][manual]")
|
||||
TEST_CASE("ADC2 Calibration Speed", "[adc][manual]")
|
||||
{
|
||||
s_adc_cali_speed(ADC_UNIT_2, ADC2_CALI_SPEED_TEST_CHAN0);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
*/
|
||||
@@ -7,6 +7,8 @@
|
||||
#include <stdlib.h>
|
||||
#include "unity.h"
|
||||
#include "esp_log.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "driver/rtc_io.h"
|
||||
#include "soc/adc_periph.h"
|
||||
@@ -23,6 +25,16 @@ 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_2_5, ADC_ATTEN_DB_6, ADC_ATTEN_DB_11};
|
||||
#endif
|
||||
|
||||
#if SOC_ADC_DIG_IIR_FILTER_SUPPORTED
|
||||
adc_digi_iir_filter_coeff_t g_test_filter_coeff[TEST_FILTER_COEFF_NUMS] = {
|
||||
ADC_DIGI_IIR_FILTER_COEFF_2,
|
||||
ADC_DIGI_IIR_FILTER_COEFF_4,
|
||||
ADC_DIGI_IIR_FILTER_COEFF_8,
|
||||
ADC_DIGI_IIR_FILTER_COEFF_16,
|
||||
ADC_DIGI_IIR_FILTER_COEFF_64,
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
/*---------------------------------------------------------------
|
||||
ADC Calibration
|
||||
@@ -102,3 +114,21 @@ void test_adc_set_io_level(adc_unit_t unit, adc_channel_t channel, bool level)
|
||||
TEST_ESP_OK(gpio_set_pull_mode(io_num, (level ? GPIO_PULLUP_ONLY: GPIO_PULLDOWN_ONLY)));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void test_adc_set_io_middle(adc_unit_t unit, adc_channel_t channel)
|
||||
{
|
||||
TEST_ASSERT(channel < SOC_ADC_CHANNEL_NUM(unit) && "invalid channel");
|
||||
|
||||
uint32_t io_num = ADC_GET_IO_NUM(unit, channel);
|
||||
|
||||
#if SOC_ADC_DIG_CTRL_SUPPORTED && !SOC_ADC_RTC_CTRL_SUPPORTED
|
||||
TEST_ESP_OK(gpio_set_pull_mode(io_num, GPIO_PULLUP_PULLDOWN));
|
||||
#else
|
||||
TEST_ESP_OK(rtc_gpio_init(io_num));
|
||||
TEST_ESP_OK(rtc_gpio_pullup_en(io_num));
|
||||
TEST_ESP_OK(rtc_gpio_pulldown_en(io_num));
|
||||
TEST_ESP_OK(rtc_gpio_set_direction(io_num, RTC_GPIO_MODE_DISABLED));
|
||||
#endif
|
||||
vTaskDelay(10 / portTICK_PERIOD_MS);
|
||||
}
|
||||
|
||||
@@ -92,6 +92,13 @@ extern adc_atten_t g_test_atten[TEST_ATTEN_NUMS];
|
||||
extern adc_atten_t g_test_atten[TEST_ATTEN_NUMS];
|
||||
#endif
|
||||
|
||||
/*---------------------------------------------------------------
|
||||
ADC Filter
|
||||
---------------------------------------------------------------*/
|
||||
#if SOC_ADC_DIG_IIR_FILTER_SUPPORTED
|
||||
#define TEST_FILTER_COEFF_NUMS 5
|
||||
extern adc_digi_iir_filter_coeff_t g_test_filter_coeff[TEST_FILTER_COEFF_NUMS];
|
||||
#endif
|
||||
|
||||
/*---------------------------------------------------------------
|
||||
ADC Calibration
|
||||
@@ -127,6 +134,17 @@ void test_adc_calibration_deinit(adc_cali_handle_t handle);
|
||||
*/
|
||||
void test_adc_set_io_level(adc_unit_t unit, adc_channel_t channel, bool level);
|
||||
|
||||
/**
|
||||
* @brief Set ADC IO to a middle level
|
||||
*
|
||||
* @note We don't expect this IO to have a fixed level among different chips.
|
||||
* We just need the IO to be stable at a certain level, which is neither 0 nor overflow.
|
||||
*
|
||||
* @param[in] unit ADC unit
|
||||
* @param[in] channel ADC channel
|
||||
*/
|
||||
void test_adc_set_io_middle(adc_unit_t unit, adc_channel_t channel);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user