From 1cb67eedbaf6e43343696967f628961e4cedb159 Mon Sep 17 00:00:00 2001 From: crasbe Date: Tue, 18 Feb 2025 10:47:45 +0100 Subject: [PATCH] tests/adc: always test all resolutions --- tests/periph/adc/README.md | 8 ++++++-- tests/periph/adc/main.c | 23 +++++++++++++---------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/tests/periph/adc/README.md b/tests/periph/adc/README.md index 7ad2990acf2f..b10cdad381e0 100644 --- a/tests/periph/adc/README.md +++ b/tests/periph/adc/README.md @@ -6,8 +6,12 @@ continuously streamed to std-out. Background ========== This test application will initialize each configured ADC lines to sample with -10-bit accuracy. Once configured the application will continuously convert each -available channel and print the conversion results to std-out. +6 to 16-bit accuracy. Once configured the application will continuously convert +each available channel with each available resolution and print the conversion +results to std-out. + +Not all MCUs support all resolutions and unsupported resolutions should be +printed as -1. For verification of the output connect the ADC pins to known voltage levels and compare the output. diff --git a/tests/periph/adc/main.c b/tests/periph/adc/main.c index 6ff1742b2372..3b0b80ee7f5a 100644 --- a/tests/periph/adc/main.c +++ b/tests/periph/adc/main.c @@ -23,16 +23,15 @@ #include "ztimer.h" #include "periph/adc.h" -#define RES ADC_RES_10BIT #define DELAY_MS 100U int main(void) { - int sample = 0; - puts("\nRIOT ADC peripheral driver test\n"); puts("This test will sample all available ADC lines once every 100ms with\n" - "a 10-bit resolution and print the sampled results to STDIO\n\n"); + "6 to 16-bit resolution and print the sampled results to STDOUT.\n" + "Not all MCUs support all resolutions, unsupported resolutions\n" + "are printed as -1.\n"); /* initialize all available ADC lines */ for (unsigned i = 0; i < ADC_NUMOF; i++) { @@ -46,13 +45,17 @@ int main(void) while (1) { for (unsigned i = 0; i < ADC_NUMOF; i++) { - sample = adc_sample(ADC_LINE(i), RES); - if (sample < 0) { - printf("ADC_LINE(%u): selected resolution not applicable\n", i); - } else { - printf("ADC_LINE(%u): %i\n", i, sample); - } + int sample6 = adc_sample(ADC_LINE(i), ADC_RES_6BIT); + int sample8 = adc_sample(ADC_LINE(i), ADC_RES_8BIT); + int sample10 = adc_sample(ADC_LINE(i), ADC_RES_10BIT); + int sample12 = adc_sample(ADC_LINE(i), ADC_RES_12BIT); + int sample14 = adc_sample(ADC_LINE(i), ADC_RES_14BIT); + int sample16 = adc_sample(ADC_LINE(i), ADC_RES_16BIT); + + printf("ADC_LINE(%u): %2i %3i %4i %4i %5i %5i\n", i, sample6, sample8, sample10, + sample12, sample14, sample16); } + putchar('\n'); ztimer_sleep(ZTIMER_MSEC, DELAY_MS); }