nrfcxx  0.1.0
C++-17 Framework for Nordic nRF5 Devices
Public Types | Static Public Member Functions | Static Public Attributes
nrfcxx::nrf5::series::ADC_Peripheral Struct Reference

Constants and function specific to the nRF51 ADC peripheral. More...

#include <nrfcxx/nrf51/impl.hpp>

Inheritance diagram for nrfcxx::nrf5::series::ADC_Peripheral:
nrfcxx::nrf5::series::ADC_Base nrfcxx::periph::ADC

Public Types

using mutex_type = mutex_irq< static_cast< IRQn_Type >(nrf5::ADC.IRQn)>
 

Static Public Member Functions

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 (int ain, unsigned int res, unsigned int prescale, unsigned int refsel, unsigned int extrefsel=ADC_CONFIG_EXTREFSEL_None)
 Helper to build up a ADC CONFIG. More...
 
static bool busy ()
 Return true iff the ADC has an in-progress conversion.
 
static void trigger ()
 Initiate an ADC sample with the current configuration. More...
 
static void enable_bi ()
 
static void disable_bi ()
 
static int calibrate_bi ()
 
static int start_bi ()
 
static void stopped_bi ()
 
- Static Public Member Functions inherited from nrfcxx::nrf5::series::ADC_Base
static void setup_result_bi (volatile uint16_t *ptr, uint16_t maxcnt=1)
 Record the destination address and count of ADC samples. More...
 

Static Public Attributes

static constexpr IRQn_Type IRQn = ADC_IRQn
 
static constexpr unsigned int VBG_mV = 1200
 nRF51 reference voltage is 1.2 V.
 
static constexpr uint16_t TOLERANCE_adc16 = (1U << 7)
 ADC offset error is documented +/- 2%, with a 1.5% error for VBG. More...
 
static constexpr uint32_t inten
 
static uint16_t result_idx_
 
- Static Public Attributes inherited from nrfcxx::nrf5::series::ADC_Base
static volatile uint16_t * result_ptr_
 
static uint16_t result_maxcnt_
 

Detailed Description

Constants and function specific to the nRF51 ADC peripheral.

Member Function Documentation

◆ make_config()

static constexpr unsigned int nrfcxx::nrf5::series::ADC_Peripheral::make_config ( int  ain,
unsigned int  res,
unsigned int  prescale,
unsigned int  refsel,
unsigned int  extrefsel = ADC_CONFIG_EXTREFSEL_None 
)
inlinestaticconstexpr

Helper to build up a ADC CONFIG.

Parameters
aina negative value to indicate the input is not from an analog pin, otherwise the ordinal of the AIN used as input. Non-negative values range from 0 through 7 inclusive. When a negative value is used the analog input may subsequently be selected by bitwise-adding the apppriate AIN selection:
ADC_CONFIG_PSEL_AnalogInput0 << (ADC_CONFIG_PSEL_Pos + ain)
resone of:
  • ADC_CONFIG_RES_8bit
  • ADC_CONFIG_RES_9bit
  • ADC_CONFIG_RES_10bit
prescaleone of:
  • ADC_CONFIG_INPSEL_AnalogInputNoPrescaling
  • ADC_CONFIG_INPSEL_AnalogInputTwoThirdsPrescaling
  • ADC_CONFIG_INPSEL_AnalogInputOneThirdPrescaling
  • ADC_CONFIG_INPSEL_SupplyTwoThirdsPrescaling
  • ADC_CONFIG_INPSEL_SupplyOneThirdPrescaling
refselone of:
  • ADC_CONFIG_REFSEL_VBG
  • ADC_CONFIG_REFSEL_External
  • ADC_CONFIG_REFSEL_SupplyOneHalfPrescaling
  • ADC_CONFIG_REFSEL_SupplyOneThirdPrescaling
extrefselone of:
  • ADC_CONFIG_EXTREFSEL_None (default)
  • ADC_CONFIG_EXTREFSEL_AnalogReference0
  • ADC_CONFIG_EXTREFSEL_AnalogReference1

◆ near_zero()

static constexpr bool nrfcxx::nrf5::series::ADC_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_adc16a normalized ADC result.
Returns
true iff the value is within TOLERANCE_adc16 of zero.

◆ trigger()

static void nrfcxx::nrf5::series::ADC_Peripheral::trigger ( )
inlinestatic

Initiate an ADC sample with the current configuration.

Warning
This function should only be invoked by or on account of the ADC instance that currently owns the ADC peripheral.

Field Documentation

◆ inten

constexpr uint32_t nrfcxx::nrf5::series::ADC_Peripheral::inten
staticconstexpr
Initial value:
= 0
| (ADC_INTENSET_END_Set << ADC_INTENSET_END_Pos)

◆ TOLERANCE_adc16

constexpr uint16_t nrfcxx::nrf5::series::ADC_Peripheral::TOLERANCE_adc16 = (1U << 7)
staticconstexpr

ADC offset error is documented +/- 2%, with a 1.5% error for VBG.

Worst case this would be around bit 5 for an 8-bit acquisition.

In practice SAADC has 9 bits of accuracy, and ADC does much better than SAADC (at least for repeatability). Make this the same as SAADC.


The documentation for this struct was generated from the following file: