From 905978e8c9261c60b9d6318c589d058534809314 Mon Sep 17 00:00:00 2001 From: Jan-Henrik Bruhn Date: Wed, 14 Feb 2024 11:59:14 +0100 Subject: [PATCH] Only read positive voltages in adc.c The ADC sometimes responds with negative voltages read on the ADC input due to noise. This can lead to very high illuminance readings at night (4095 << 4 to be exact due to two's complement :) ). This commit caps ADC readings at 0. --- code/nrf-connect/prstlib/src/adc.c | 1 + 1 file changed, 1 insertion(+) diff --git a/code/nrf-connect/prstlib/src/adc.c b/code/nrf-connect/prstlib/src/adc.c index 20d69f9..33c1df6 100644 --- a/code/nrf-connect/prstlib/src/adc.c +++ b/code/nrf-connect/prstlib/src/adc.c @@ -108,6 +108,7 @@ static int read_adc_spec(const struct adc_dt_spec* spec, prst_adc_read_t* out) { int32_t val_mv = buf; RET_IF_ERR(adc_raw_to_millivolts_dt(spec, &val_mv)); + val_mv = MAX(0, val_mv); out->raw = buf; out->millivolts = val_mv;