diff --git a/cores/nRF5/wiring_analog.h b/cores/nRF5/wiring_analog.h index f183b57a..146d4fb7 100644 --- a/cores/nRF5/wiring_analog.h +++ b/cores/nRF5/wiring_analog.h @@ -49,6 +49,42 @@ typedef enum _eAnalogReference } eAnalogReference ; #endif +#if defined(NRF52_SERIES) +/* + * \brief Acquisition time enumeration. To be used with \ref analogAcquisitionTime + */ +typedef enum _eAcquisitionTime +{ + AT_DEFAULT, + AT_3us, + AT_5us, + AT_10us, + AT_15us, + AT_20us, + AT_40us +} eAcquisitionTime ; + +/* + * \brief Set the acquisition time of the ADC. + * Default value: 3us. + * Acquision time should match the maximum source resistance of the signal. + * See the '37.9 Acquisition time' chapter of the datasheet for more details. + * + * + * + *
Acquisition Time
Acquisition TimeMaximum source resistance + *
3us 10kOhm + *
5us 40kOhm + *
10us 100kOhm + *
15us 200kOhm + *
20us 400kOhm + *
40us 800kOhm + *
+ * + * \param ulMmode + */ +extern void analogAcquisitionTime( eAcquisitionTime ulMode ); +#endif /* * \brief Configures the reference voltage used for analog input (i.e. the value used as the top of the input range). diff --git a/cores/nRF5/wiring_analog_nRF52.c b/cores/nRF5/wiring_analog_nRF52.c index e7db64a5..5e4efcb6 100644 --- a/cores/nRF5/wiring_analog_nRF52.c +++ b/cores/nRF5/wiring_analog_nRF52.c @@ -28,6 +28,7 @@ extern "C" { static uint32_t saadcReference = SAADC_CH_CONFIG_REFSEL_Internal; static uint32_t saadcGain = SAADC_CH_CONFIG_GAIN_Gain1_5; +static uint32_t saadcAcqTime = SAADC_CH_CONFIG_TACQ_3us; static NRF_PWM_Type* pwms[PWM_COUNT] = { NRF_PWM0, @@ -101,6 +102,37 @@ void analogReference( eAnalogReference ulMode ) } } +void analogAcquisitionTime( eAcquisitionTime ulMode ) +{ + switch ( ulMode ) { + case AT_DEFAULT: + case AT_3us: + saadcAcqTime = SAADC_CH_CONFIG_TACQ_3us; + break; + + case AT_5us: + saadcAcqTime = SAADC_CH_CONFIG_TACQ_5us; + break; + + case AT_10us: + saadcAcqTime = SAADC_CH_CONFIG_TACQ_10us; + break; + + case AT_15us: + saadcAcqTime = SAADC_CH_CONFIG_TACQ_15us; + break; + + case AT_20us: + saadcAcqTime = SAADC_CH_CONFIG_TACQ_20us; + break; + + case AT_40us: + default: + saadcAcqTime = SAADC_CH_CONFIG_TACQ_40us; + break; + } +} + uint32_t analogRead( uint32_t ulPin ) { uint32_t pin = SAADC_CH_PSELP_PSELP_NC; @@ -176,7 +208,7 @@ uint32_t analogRead( uint32_t ulPin ) | ((SAADC_CH_CONFIG_RESP_Bypass << SAADC_CH_CONFIG_RESN_Pos) & SAADC_CH_CONFIG_RESN_Msk) | ((saadcGain << 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) + | ((saadcAcqTime << 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); NRF_SAADC->CH[0].PSELN = pin; NRF_SAADC->CH[0].PSELP = pin;