From a9e05081405d820c307af0b1821fbcb10ecc4bda Mon Sep 17 00:00:00 2001 From: microbuilder Date: Wed, 8 Feb 2017 19:47:36 +0100 Subject: [PATCH] Set ADC defaults to internal (0.6V) ref and 1/6 gain (GND..3.6V) --- cores/nRF5/wiring_analog_nRF52.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/cores/nRF5/wiring_analog_nRF52.c b/cores/nRF5/wiring_analog_nRF52.c index bf975f48..a799cb7e 100644 --- a/cores/nRF5/wiring_analog_nRF52.c +++ b/cores/nRF5/wiring_analog_nRF52.c @@ -76,8 +76,13 @@ static inline uint32_t mapResolution( uint32_t value, uint32_t from, uint32_t to } /* - * Internal Reference is at 1.0v - * External Reference should be between 1v and VDDANA-0.6v=2.7v + * Internal Reference is +/-0.6V, with an adjustable gain of 1/6, 1/5, 1/4, + * 1/3, 1/2 or 1, meaning 3.6, 3.0, 2.4, 1.8, 1.2 or 0.6V for the ADC levels. + * + * External Reference is VDD/4, with an adjustable gain of 1, 2 or 4, meaning + * VDD/4, VDD/2 or VDD for the ADC levels. + * + * Default settings are internal reference with 1/6 gain (GND..3.6V ADC range) * * Warning : On Arduino Zero board the input/output voltage for SAMD21G18 is 3.3 volts maximum */ @@ -167,9 +172,9 @@ uint32_t analogRead( uint32_t ulPin ) NRF_SAADC->CH[i].PSELN = SAADC_CH_PSELP_PSELP_NC; NRF_SAADC->CH[i].PSELP = SAADC_CH_PSELP_PSELP_NC; } - NRF_SAADC->CH[0].CONFIG = ((SAADC_CH_CONFIG_RESP_Bypass << SAADC_CH_CONFIG_RESP_Pos) & SAADC_CH_CONFIG_RESP_Msk) + NRF_SAADC->CH[0].CONFIG = ((SAADC_CH_CONFIG_RESP_Bypass << SAADC_CH_CONFIG_RESP_Pos) & SAADC_CH_CONFIG_RESP_Msk) | ((SAADC_CH_CONFIG_RESP_Bypass << SAADC_CH_CONFIG_RESN_Pos) & SAADC_CH_CONFIG_RESN_Msk) - | ((SAADC_CH_CONFIG_GAIN_Gain1 << SAADC_CH_CONFIG_GAIN_Pos) & SAADC_CH_CONFIG_GAIN_Msk) + | ((SAADC_CH_CONFIG_GAIN_Gain1_6 << SAADC_CH_CONFIG_GAIN_Pos) & SAADC_CH_CONFIG_GAIN_Msk) | ((saadcReference << SAADC_CH_CONFIG_REFSEL_Pos) & SAADC_CH_CONFIG_REFSEL_Msk) | ((SAADC_CH_CONFIG_TACQ_3us << SAADC_CH_CONFIG_TACQ_Pos) & SAADC_CH_CONFIG_TACQ_Msk) | ((SAADC_CH_CONFIG_MODE_SE << SAADC_CH_CONFIG_MODE_Pos) & SAADC_CH_CONFIG_MODE_Msk);