nrfcxx  0.1.0
C++-17 Framework for Nordic nRF5 Devices
Public Member Functions | Data Fields | Static Public Attributes
nrfcxx::sensor::adc::ntcThermistor Class Reference

Class supporting thermistor measurements. More...

#include <nrfcxx/sensor/adc.hpp>

Inheritance diagram for nrfcxx::sensor::adc::ntcThermistor:
nrfcxx::sensor::adc::voltage_divider nrfcxx::periph::ADCClient

Public Member Functions

template<typename Iterator >
 ntcThermistor (Iterator ains_begin, Iterator ains_end, volatile uint16_t *raw=nullptr, const SteinhartHart *coeff=&steinhartHart::adafruit372fullScale, unsigned int ref_Ohm=10000)
 Generic constructor for an iterable set of thermistor channels and optional external storage. More...
 
 ntcThermistor (std::initializer_list< uint8_t > ains, volatile uint16_t *raw=nullptr, const SteinhartHart *coeff=&steinhartHart::adafruit372fullScale, unsigned int ref_Ohm=10000)
 Constructor for an explicit list of channels.
 
int convert_adc16_cCel (unsigned int therm_adc16)
 Convert a measured voltage to a temperature. More...
 
int temperature_cCel (size_t ci=0)
 Convert the stored measured voltage to a thermisor. More...
 
unsigned int therm_adc16 (size_t ci=0) const
 Return the last raw 16-bit ADC thermistor reading.
 
unsigned int therm_Ohm (size_t ci=0) const
 Return the estimated thermistor resistance, in Ohms.
 
- Public Member Functions inherited from nrfcxx::sensor::adc::voltage_divider
template<typename Iterator >
 voltage_divider (unsigned int r1_Ohm, unsigned int r2_Ohm, Iterator ains_begin, Iterator ains_end, volatile uint16_t *raw=nullptr)
 Generic constructor for an iterable set of channels and optional external storage. More...
 
 voltage_divider (unsigned int r1_Ohm, unsigned int r2_Ohm, uint8_t ain)
 Constructor for common case of a single channel with internal storage.
 
 voltage_divider (unsigned int r1_Ohm, unsigned int r2_Ohm, std::initializer_list< uint8_t > ains, volatile uint16_t *raw=nullptr)
 Constructor for an explicit list of channels.
 
size_t count () const
 The number of channels used by this client.
 
int channel_ain (size_t ci) const
 Extract the channel associated with the provided index. More...
 
int sample_adc16 (size_t ci=0) const
 Retrieve the latest raw measurement for a channel. More...
 
int sample_mV (size_t ci=0, bool truncate=false) const
 Retrieve the latest output voltage measurement for a channel. More...
 
int input_mV (size_t ci=0) const
 Retrieve the latest input voltage measurement for a channel. More...
 
virtual int measurement_mV (uint16_t m16) const
 Convert a raw ADC measurement to mV. More...
 
int measurement_Ohm (uint16_t m16) const
 Convert a raw ADC measurement to the estimated resistance. More...
 
int sample_Ohm (size_t ci=0, bool filter_high_negative=false) const
 Retrieve the latest estimated resistance for a channel. More...
 
- Public Member Functions inherited from nrfcxx::periph::ADCClient
virtual ~ADCClient ()
 Release the peripheral when the client is destructed.
 
int claim ()
 Attempt to claim exclusive use of the ADC peripheral. More...
 
int release ()
 Release the ADC peripheral. More...
 
int calibrate (const notifier_type &notify={})
 Calibrate the ADC. More...
 
virtual int sample_setup ()
 Overridable function to set up for an ADC measurement. More...
 
virtual void sample_teardown ()
 Reverse the effects of sample_setup_(). More...
 
int sample (const notifier_type &notify={})
 Trigger a client-specific collection. More...
 
int queue (const notifier_type &notify, const queued_callback_type &qnotify={}, bool calibrate=false)
 Queue an operation to be initiated as soon as the ADC becomes available. More...
 
int queue (bool calibrate=false)
 Overload when no notifications are required. More...
 

Data Fields

const SteinhartHart *const steinhartHart
 The Steinhart-Hart coefficients and extreme values for the thermistor in the circuit.
 
- Data Fields inherited from nrfcxx::sensor::adc::voltage_divider
const unsigned int r1_Ohm
 The resistance of the upper leg of the voltage divider, connected to the input voltage. More...
 
const unsigned int r2_Ohm
 The resistance of the lower leg of the voltage divider, connected to ground. More...
 
volatile uint16_t * ptr
 
uint16_t volatile val [MAX_INTERNAL]
 

Static Public Attributes

static constexpr int ABSOLUTE_ZERO_cCel = -27315
 Constant used to convert between Kelvin and Celsius.
 
static constexpr int INVALID_cCel = 30000
 An flag value for invalid temperatures. More...
 
static constexpr int SHORT_cCel = INVALID_cCel + 1
 Measurement returned by temperature_cCel() for a shorted thermistor. More...
 
static constexpr int OPEN_cCel = - SHORT_cCel
 Measurement returned by temperature_cCel() for an open thermistor. More...
 

Additional Inherited Members

- Public Types inherited from nrfcxx::periph::ADCClient
using flags_type = unsigned int
 Type for client-specific flags.
 
using queued_callback_type = std::function< void(int rc)>
 Signature for application notification of completed queue operation. More...
 
using peripheral = ADC::peripheral
 
using mutex_type = peripheral::mutex_type
 Mutex required to inhibit ADC interrupts.
 
- Protected Types inherited from nrfcxx::periph::ADCClient
enum  flags_e : flags_type { FL_QUEUED_SAMPLE = 0x0001, FL_QUEUED_CALIBRATE = 0x0002, FL_QUEUED_Msk = FL_QUEUED_SAMPLE | FL_QUEUED_CALIBRATE, FL_SUBCLASS_BASE = 0x0010 }
 Defined values for flags. More...
 
- Protected Member Functions inherited from nrfcxx::periph::ADCClient
int sample_bi_ (const notifier_type &notify)
 Implements sample() given that the mutex is already held.
 
void complete_queue_bi_ ()
 
virtual void complete_bi_ ()
 Method invoked when the collection completes. More...
 
- Static Protected Member Functions inherited from nrfcxx::periph::ADCClient
static void process_queue_bi_ ()
 
- Protected Attributes inherited from nrfcxx::periph::ADCClient
flags_type flags_ = 0
 Flags for use by the core infrastructure and client specifications. More...
 

Detailed Description

Class supporting thermistor measurements.

Each thermistor is expected to be positioned as the upper resistor in a voltage divider. The value of the lower resistor and the Steinhart-Hart thermistor coefficients must be the same for all channels sampled by a given instance.

Constructor & Destructor Documentation

◆ ntcThermistor()

template<typename Iterator >
nrfcxx::sensor::adc::ntcThermistor::ntcThermistor ( Iterator  ains_begin,
Iterator  ains_end,
volatile uint16_t *  raw = nullptr,
const SteinhartHart coeff = &steinhartHart::adafruit372fullScale,
unsigned int  ref_Ohm = 10000 
)
inline

Generic constructor for an iterable set of thermistor channels and optional external storage.

Parameters
ains_beginas with voltage_divider::voltage_divider.
ains_endas with voltage_divider::voltage_divider.
rawas with voltage_divider::voltage_divider.
coeffpointer to the thermistor coefficients.
ref_Ohmthe value of the reference resistor in the thermistor voltage divider.

Member Function Documentation

◆ convert_adc16_cCel()

int nrfcxx::sensor::adc::ntcThermistor::convert_adc16_cCel ( unsigned int  therm_adc16)

Convert a measured voltage to a temperature.

Parameters
therm_adc16the measured voltage in 16-bit ADC counts. A value of 65535 would correspond to Vcc (a shorted thermistor); a value of zero would correspond to no voltage (an open thermistor).
Returns
The measured temperature of the thermistor in hundredths of a degree Celsius, or OPEN_cCel or SHORT_cCel for a broken thermistor.

◆ temperature_cCel()

int nrfcxx::sensor::adc::ntcThermistor::temperature_cCel ( size_t  ci = 0)

Convert the stored measured voltage to a thermisor.

Parameters
cithe thermistor channel to use.
Returns
as with convert_adc16_cCel()

Field Documentation

◆ INVALID_cCel

constexpr int nrfcxx::sensor::adc::ntcThermistor::INVALID_cCel = 30000
staticconstexpr

An flag value for invalid temperatures.

The value is chosen to allow its positive and negative values to be stored in an int16_t with magnitudes that are not reasonable for true observed measurements. Any observation with a magnitude equal to or greater than this is invalid.

Distinct values may indicate different types of failure. For example the base value indicates a reading that was not performed, while increasing the magnitude by one identifies thermistor inputs that are faulted short or open.

◆ OPEN_cCel

constexpr int nrfcxx::sensor::adc::ntcThermistor::OPEN_cCel = - SHORT_cCel
staticconstexpr

Measurement returned by temperature_cCel() for an open thermistor.

An open thermistor is diagnosed when the measured voltage across the thermistor is at or below #open_adc16. This is in the direction of extremely low temperatures.

Note
The magnitude of this value is greater than INVALID_cCel and is equal to the magnitude of SHORT_cCel. The value is negative.

◆ SHORT_cCel

constexpr int nrfcxx::sensor::adc::ntcThermistor::SHORT_cCel = INVALID_cCel + 1
staticconstexpr

Measurement returned by temperature_cCel() for a shorted thermistor.

A shorted thermistor is diagnosed when the measured voltage across the thermistor is at or above #short_adc16. This is in the direction of extremely high temperatures.

Note
The magnitude of this value is greater than INVALID_cCel and is equal to the magnitude of OPEN_cCel. The value is positive.

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