From f51ca593ba8c497bdfe8128c63a9509f7b23aa35 Mon Sep 17 00:00:00 2001 From: Marian Buschsieweke Date: Mon, 13 Nov 2023 16:11:22 +0100 Subject: [PATCH] tests/periph/selftest_shield: re-enable ADC test The R-2R resistor ladder dac --> ADC test was disabled due to a bug in the v0.1 version of the shield. Since this has been fixed in v0.2 and v0.3 of the shield, it can be re-enabled. The comment regarding the high accuracy of the resistor is dropped, as v0.3 has been ordered with cost efficient resistors rather than with accurate ones. As a result, the tolerance for error has been increased to 10%. This quite a bit more lax than I have hoped for, but false positives would be something to avoid. --- tests/periph/selftest_shield/main.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/tests/periph/selftest_shield/main.c b/tests/periph/selftest_shield/main.c index 84e192e2f7..94ea7fa1fb 100644 --- a/tests/periph/selftest_shield/main.c +++ b/tests/periph/selftest_shield/main.c @@ -93,10 +93,9 @@ * - periph_adc support (so that we have something to test) * - Arduino I/O mapping for ADC (so that we know which line to test) * - The PCF857x driver (so that we can control the R-2R resistor ladder - * connected to the GPIO expander. + * connected to the GPIO expander). */ -#if defined(MODULE_PERIPH_ADC) && defined(ARDUINO_A0) && defined(MODULE_PCF857X) && 0 -// TODO: Re-anble when PCB is fixed +#if defined(MODULE_PERIPH_ADC) && defined(ARDUINO_A0) && defined(MODULE_PCF857X) # define ENABLE_ADC_TEST 1 #else # define ENABLE_ADC_TEST 0 @@ -979,9 +978,9 @@ static bool periph_adc_test(void) uint16_t sample = adc_sample(ARDUINO_A0, ADC_RES_10BIT); uint16_t expected = i << 6; - /* the resistors are said to be rather accurate, so lets be a bit - * more strict here */ - const uint16_t delta = 16; + /* The resistors on board v0.3 are not that accurate, so allow for 10% + * error margin */ + const uint16_t delta = 1024 / 10; uint16_t lower = expected <= delta ? 0 : expected - delta; uint16_t upper = MIN(1023, expected + delta); bool test_failed = TEST((lower <= sample) && (upper >= sample));