Skip to content

Commit

Permalink
Merge pull request #21223 from crasbe/pr/adc_test
Browse files Browse the repository at this point in the history
tests/adc: always test all resolutions
  • Loading branch information
mguetschow authored Feb 20, 2025
2 parents 8bbeba1 + 1cb67ee commit 88f2e45
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
8 changes: 6 additions & 2 deletions tests/periph/adc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
23 changes: 13 additions & 10 deletions tests/periph/adc/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand All @@ -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);
}

Expand Down

0 comments on commit 88f2e45

Please sign in to comment.