Constants and function specific to the nRF52 SAADC peripheral.
More...
#include <nrfcxx/nrf52/impl.hpp>
|
using | mutex_type = mutex_irq< static_cast< IRQn_Type >(nrf5::SAADC.IRQn)> |
|
|
static constexpr bool | near_zero (uint16_t v_adc16) |
| Test whether a value appears to be indistinguishable from zero. More...
|
|
static constexpr unsigned int | make_config (unsigned int refsel=SAADC_CH_CONFIG_REFSEL_Internal, unsigned int gain=SAADC_CH_CONFIG_GAIN_Gain1_6, unsigned int tacq=SAADC_CH_CONFIG_TACQ_10us, bool burst=true, unsigned int resp=SAADC_CH_CONFIG_RESP_Bypass, bool differential=false, unsigned int resn=SAADC_CH_CONFIG_RESN_Bypass) |
| Helper to build up a ADC channel-specific CONFIG value. More...
|
|
static bool | busy () |
|
static void | enable_bi () |
|
static void | disable_bi () |
|
static int | calibrate_bi () |
|
static int | start_bi () |
|
static void | stopped_bi () |
|
static unsigned int | normalize_bi () |
| Post-process the ADC results so they're normalized as if from a 16-bit ADC. More...
|
|
static void | setup_result_bi (volatile uint16_t *ptr, uint16_t maxcnt=1) |
| Record the destination address and count of ADC samples. More...
|
|
|
static constexpr IRQn_Type | IRQn = SAADC_IRQn |
|
static constexpr unsigned int | VBG_mV = 600 |
| nRF52 reference voltage is 0.6 V.
|
|
static constexpr uint16_t | TOLERANCE_adc16 = (1U << 7) |
| The value corresponding to the 9th bit of a normalized acquisition. More...
|
|
static constexpr uint32_t | inten |
|
static bool | calibrating_bi_ |
|
static volatile uint16_t * | result_ptr_ |
|
static uint16_t | result_maxcnt_ |
|
Constants and function specific to the nRF52 SAADC peripheral.
- Note
- The SAADC peripheral has much higher noise than the ADC peripheral of nRF51. Significant oversampling is required for reasonable results, and it's likely the low bits should simply be discarded.
-
SAADC has a +/- 2 LSB (0.19%) error tolerance for offset at 10 bit resolution. This can cause voltages near ground to be negative, which appears as extremely high voltages. There is also a +/- 3% error due to gain (+4% for gain >= 0.5).
-
So, basically, assume you only get 9 bits out of this thing.
- See also
- https://devzone.nordicsemi.com/f/nordic-q-a/12287/nrf52-saadc-noise
◆ make_config()
static constexpr unsigned int nrfcxx::nrf5::series::SAADC_Peripheral::make_config |
( |
unsigned int |
refsel = SAADC_CH_CONFIG_REFSEL_Internal , |
|
|
unsigned int |
gain = SAADC_CH_CONFIG_GAIN_Gain1_6 , |
|
|
unsigned int |
tacq = SAADC_CH_CONFIG_TACQ_10us , |
|
|
bool |
burst = true , |
|
|
unsigned int |
resp = SAADC_CH_CONFIG_RESP_Bypass , |
|
|
bool |
differential = false , |
|
|
unsigned int |
resn = SAADC_CH_CONFIG_RESN_Bypass |
|
) |
| |
|
inlinestaticconstexpr |
Helper to build up a ADC channel-specific CONFIG
value.
- Parameters
-
refsel | one of:
SAADC_CH_CONFIG_REFSEL_Internal for internal 600 mV reference default;
SAADC_CH_CONFIG_REFSEL_VDD1_4 for VDD/4 as reference;
|
gain | one of:
SAADC_CH_CONFIG_GAIN_Gain1_6 for a gain of 1/6 default;
SAADC_CH_CONFIG_GAIN_Gain1_5 for a gain of 1/5;
SAADC_CH_CONFIG_GAIN_Gain1_4 for a gain of 1/4;
SAADC_CH_CONFIG_GAIN_Gain1_3 for a gain of 1/3;
SAADC_CH_CONFIG_GAIN_Gain1_2 for a gain of 1/2;
SAADC_CH_CONFIG_GAIN_Gain1 for a gain of 1;
SAADC_CH_CONFIG_GAIN_Gain2 for a gain of 2;
SAADC_CH_CONFIG_GAIN_Gain4 for a gain of 4.
|
tacq | one of:
SAADC_CH_CONFIG_TACQ_3us for 3 us;
SAADC_CH_CONFIG_TACQ_5us for 5 us;
SAADC_CH_CONFIG_TACQ_10us for 10 us default;
SAADC_CH_CONFIG_TACQ_15us for 15 us;
SAADC_CH_CONFIG_TACQ_20us for 20 us;
SAADC_CH_CONFIG_TACQ_40us for 40 us.
|
burst | one of:
true for burst mode operation non-standard default (this is default enabled to support non-zero OVERSAMPLING with the simplified one-shot periph::ADCClient API.)
false for normal operation;
|
resp | one of:
SAADC_CH_CONFIG_RESP_Bypass to bypass the resistor ladder default;
SAADC_CH_CONFIG_RESP_Pulldown to pull-down to GND;
SAADC_CH_CONFIG_RESP_Pullup to pull-up to VDD;
SAADC_CH_CONFIG_RESP_VDD1_2 to set input at VDD/2.
|
differential | one of:
false for single ended default;
true for differential.
|
resn | one of:
SAADC_CH_CONFIG_RESN_Bypass to bypass the resistor ladder default;
SAADC_CH_CONFIG_RESN_Pulldown to pull-down to GND;
SAADC_CH_CONFIG_RESN_Pullup to pull-up to VDD;
SAADC_CH_CONFIG_RESN_VDD1_2 to set input at VDD/2.
|
◆ near_zero()
static constexpr bool nrfcxx::nrf5::series::SAADC_Peripheral::near_zero |
( |
uint16_t |
v_adc16 | ) |
|
|
inlinestaticconstexpr |
Test whether a value appears to be indistinguishable from zero.
This tests whether a normalized ADC result is within TOLERANCE_adc16 of zero, handling the case where the SAADC result was a small negative that appears as a large unsigned measurement.
- Parameters
-
v_adc16 | a normalized ADC result. |
- Returns
- true iff the value is within TOLERANCE_adc16 of zero.
◆ normalize_bi()
static unsigned int nrfcxx::nrf5::series::SAADC_Peripheral::normalize_bi |
( |
| ) |
|
|
inlinestatic |
Post-process the ADC results so they're normalized as if from a 16-bit ADC.
This is done in-place in the memory to which the results were DMAd.
◆ inten
constexpr uint32_t nrfcxx::nrf5::series::SAADC_Peripheral::inten |
|
staticconstexpr |
Initial value:= 0
| (SAADC_INTENSET_CALIBRATEDONE_Set << SAADC_INTENSET_CALIBRATEDONE_Pos)
| (SAADC_INTENSET_STARTED_Set << SAADC_INTENSET_STARTED_Pos)
| (SAADC_INTENSET_DONE_Set << SAADC_INTENSET_DONE_Pos)
| (SAADC_INTENSET_RESULTDONE_Set << SAADC_INTENSET_RESULTDONE_Pos)
| (SAADC_INTENSET_END_Set << SAADC_INTENSET_END_Pos)
| (SAADC_INTENSET_STOPPED_Set << SAADC_INTENSET_STOPPED_Pos)
◆ TOLERANCE_adc16
constexpr uint16_t nrfcxx::nrf5::series::SAADC_Peripheral::TOLERANCE_adc16 = (1U << 7) |
|
staticconstexpr |
The value corresponding to the 9th bit of a normalized acquisition.
See above for discussion of SAADC error bounds.
The documentation for this struct was generated from the following file: