mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-12-15 09:33:50 +01:00
Merge pull request #21223 from crasbe/pr/adc_test
tests/adc: always test all resolutions
This commit is contained in:
commit
88f2e451ca
@ -6,8 +6,12 @@ continuously streamed to std-out.
|
|||||||
Background
|
Background
|
||||||
==========
|
==========
|
||||||
This test application will initialize each configured ADC lines to sample with
|
This test application will initialize each configured ADC lines to sample with
|
||||||
10-bit accuracy. Once configured the application will continuously convert each
|
6 to 16-bit accuracy. Once configured the application will continuously convert
|
||||||
available channel and print the conversion results to std-out.
|
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
|
For verification of the output connect the ADC pins to known voltage levels
|
||||||
and compare the output.
|
and compare the output.
|
||||||
|
|||||||
@ -23,16 +23,15 @@
|
|||||||
#include "ztimer.h"
|
#include "ztimer.h"
|
||||||
#include "periph/adc.h"
|
#include "periph/adc.h"
|
||||||
|
|
||||||
#define RES ADC_RES_10BIT
|
|
||||||
#define DELAY_MS 100U
|
#define DELAY_MS 100U
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
int sample = 0;
|
|
||||||
|
|
||||||
puts("\nRIOT ADC peripheral driver test\n");
|
puts("\nRIOT ADC peripheral driver test\n");
|
||||||
puts("This test will sample all available ADC lines once every 100ms with\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 */
|
/* initialize all available ADC lines */
|
||||||
for (unsigned i = 0; i < ADC_NUMOF; i++) {
|
for (unsigned i = 0; i < ADC_NUMOF; i++) {
|
||||||
@ -46,13 +45,17 @@ int main(void)
|
|||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
for (unsigned i = 0; i < ADC_NUMOF; i++) {
|
for (unsigned i = 0; i < ADC_NUMOF; i++) {
|
||||||
sample = adc_sample(ADC_LINE(i), RES);
|
int sample6 = adc_sample(ADC_LINE(i), ADC_RES_6BIT);
|
||||||
if (sample < 0) {
|
int sample8 = adc_sample(ADC_LINE(i), ADC_RES_8BIT);
|
||||||
printf("ADC_LINE(%u): selected resolution not applicable\n", i);
|
int sample10 = adc_sample(ADC_LINE(i), ADC_RES_10BIT);
|
||||||
} else {
|
int sample12 = adc_sample(ADC_LINE(i), ADC_RES_12BIT);
|
||||||
printf("ADC_LINE(%u): %i\n", i, sample);
|
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);
|
ztimer_sleep(ZTIMER_MSEC, DELAY_MS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user