nrfcxx
0.1.0
C++-17 Framework for Nordic nRF5 Devices
|
Class supporting thermistor measurements. More...
#include <nrfcxx/sensor/adc.hpp>
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 ¬ify={}) |
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 ¬ify={}) |
Trigger a client-specific collection. More... | |
int | queue (const notifier_type ¬ify, 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 ¬ify) |
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... | |
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.
|
inline |
Generic constructor for an iterable set of thermistor channels and optional external storage.
ains_begin | as with voltage_divider::voltage_divider. |
ains_end | as with voltage_divider::voltage_divider. |
raw | as with voltage_divider::voltage_divider. |
coeff | pointer to the thermistor coefficients. |
ref_Ohm | the value of the reference resistor in the thermistor voltage divider. |
int nrfcxx::sensor::adc::ntcThermistor::convert_adc16_cCel | ( | unsigned int | therm_adc16 | ) |
Convert a measured voltage to a temperature.
therm_adc16 | the 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). |
int nrfcxx::sensor::adc::ntcThermistor::temperature_cCel | ( | size_t | ci = 0 | ) |
Convert the stored measured voltage to a thermisor.
ci | the thermistor channel to use. |
|
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.
|
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.
|
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.