NTC_THERMISTOR Driver 0.1.0
API reference
Loading...
Searching...
No Matches
Namespaces | Classes | Concepts | Enumerations | Functions | Variables
ntc_thermistor Namespace Reference

The NTC thermistor driver: everything it declares lives here; internals in detail. More...

Namespaces

namespace  presets
 Example curves; see ntc_thermistor_presets.hpp.
 

Classes

class  AdcInterface
 CRTP base of the platform ADC port. More...
 
struct  Config
 Everything one thermistor and its divider need. There is no default part: a Config{} fails Validate() until a Curve is declared. More...
 
struct  Curve
 What the thermistor is: a table, Steinhart-Hart coefficients, or R at a reference temperature and the beta value. More...
 
class  NtcThermistor
 Driver for one NTC thermistor in a resistor divider on an ADC port. More...
 
struct  Reading
 One reading: the temperature and what it was computed from. More...
 
struct  Result
 The value of a call, or why there is none. More...
 
struct  Result< void >
 The result of a call that returns no value. More...
 
struct  TablePoint
 One row of a resistance and temperature table. More...
 

Concepts

concept  AdcPort
 Satisfied by a class that derives from AdcInterface<Port> and implements the required hooks with exactly the types above, noexcept and returning bool (handbook KB-CPP20-006).
 

Enumerations

enum class  Error : uint8_t {
  Error::Ok = 0 , Error::NotInitialized = 1 , Error::InvalidArgument = 2 , Error::Bus = 3 ,
  Error::Timeout = 4 , Error::DeviceIdMismatch = 5 , Error::Crc = 6 , Error::Busy = 7 ,
  Error::DeviceFault = 8 , Error::Unsupported = 9 , Error::OpenCircuit = 16 , Error::ShortCircuit = 17 ,
  Error::BelowRange = 18 , Error::AboveRange = 19 , Error::Unstable = 20 , Error::CodeOutOfScale = 21
}
 Why a call failed. Values 0 to 9 are the shared base set; this driver's own values start at 16. More...
 
enum class  Topology : uint8_t { Topology::NtcLowSide = 0 , Topology::NtcHighSide = 1 }
 Where the thermistor sits in the divider. More...
 

Functions

constexpr Result< Reading > Convert (const Config &config, uint32_t mean_code) noexcept
 The pure conversion: the maths for an ADC code, with no port and no state.
 
constexpr Result< uint32_t > ConvertResistance (const Config &config, uint32_t mean_code) noexcept
 The thermistor's resistance for a code: the divider arithmetic only, with no curve and no window.
 
constexpr int32_t ToMilliKelvin (int32_t mc) noexcept
 A temperature in milli-kelvin.
 
constexpr int32_t ToMilliFahrenheit (int32_t mc) noexcept
 A temperature in milli-degrees Fahrenheit.
 
constexpr uint32_t SelfHeatingMicrowatts (const Config &config, uint32_t r_ntc_ohm) noexcept
 The power the divider puts into the thermistor, in microwatts: V^2 * Rn / (Rs + Rn)^2.
 
constexpr Config KconfigDefaults () noexcept
 The configuration menuconfig selected.
 
constexpr const char * ToString (Error error) noexcept
 The name of an error, for logs.
 
constexpr Error Validate (const Config &config) noexcept
 Check a configuration without touching the hardware.
 
constexpr const char * GetDriverVersion () noexcept
 
constexpr uint32_t GetDriverVersionMajor () noexcept
 
constexpr uint32_t GetDriverVersionMinor () noexcept
 
constexpr uint32_t GetDriverVersionPatch () noexcept
 

Variables

constexpr uint8_t kMinAdcBits = 8
 Lowest ADC resolution Config::adc_bits accepts.
 
constexpr uint8_t kMaxAdcBits = 24
 Highest ADC resolution Config::adc_bits accepts.
 
constexpr uint32_t kMaxSeriesOhm = 16'777'216
 
constexpr uint32_t kMaxR0Ohm = 10'000'000
 Largest Curve::r0_ohm, in ohms.
 
constexpr uint32_t kMinBetaKelvin = 1000
 Smallest Curve::b_kelvin.
 
constexpr uint32_t kMaxBetaKelvin = 8000
 Largest Curve::b_kelvin.
 
constexpr std::size_t kMinTableRows = 2
 Fewest rows of a table.
 
constexpr std::size_t kMaxTableRows = 256
 Most rows of a table.
 
constexpr uint32_t kMaxWaitUs = 1'000'000
 
constexpr int64_t kMaxShAE15 = 10'000'000'000'000
 
constexpr int64_t kMaxShBE15 = 1'000'000'000'000
 Largest magnitude of Curve::sh_b_e15 (1e-3 per kelvin).
 
constexpr int64_t kMaxShCE15 = 2'000'000'000
 Largest magnitude of Curve::sh_c_e15 (2e-6 per kelvin).
 
constexpr uint32_t kMaxCurveErrorMc = 100'000
 Largest Curve::curve_error_mc, in milli-degrees.
 
constexpr uint8_t kMaxSampleCount = 16
 Most samples one reading averages.
 
constexpr uint32_t kMaxSupplyMv = 20'000
 Largest divider supply or ADC reference, in millivolts.
 
constexpr int32_t kMaxOffsetMc = 20'000
 Largest Config::offset_mc magnitude, in milli-degrees Celsius.
 
constexpr uint32_t kMaxTolerancePpm = 500'000
 Largest tolerance, in parts per million (50 %).
 
constexpr int32_t kAbsoluteZeroMc = -273'150
 
constexpr int32_t kNoMinTemperatureMc = std::numeric_limits<int32_t>::min()
 Config::min_temperature_mc when no lower window is set.
 
constexpr int32_t kNoMaxTemperatureMc = std::numeric_limits<int32_t>::max()
 Config::max_temperature_mc when no upper window is set.
 

Detailed Description

The NTC thermistor driver: everything it declares lives here; internals in detail.

Function Documentation

◆ Convert()

constexpr Result< Reading > ntc_thermistor::Convert ( const Config &  config,
uint32_t  mean_code 
)
constexprnoexcept

The pure conversion: the maths for an ADC code, with no port and no state.

Use it to turn a code the application already has into a temperature, or to test a configuration. A code is the mean code of one reading.

Parameters
configThe configuration; it is validated first.
mean_codeThe ADC code, 0 to 2^adc_bits - 1.
Returns
The reading, or InvalidArgument, CodeOutOfScale, OpenCircuit, ShortCircuit, BelowRange or AboveRange.

◆ ConvertResistance()

constexpr Result< uint32_t > ntc_thermistor::ConvertResistance ( const Config &  config,
uint32_t  mean_code 
)
constexprnoexcept

The thermistor's resistance for a code: the divider arithmetic only, with no curve and no window.

Parameters
configThe configuration; it is validated first.
mean_codeThe ADC code.
Returns
Ohms, or InvalidArgument, CodeOutOfScale, OpenCircuit, ShortCircuit or BelowRange (the resistance does not fit 32 bits).

◆ KconfigDefaults()

constexpr Config ntc_thermistor::KconfigDefaults ( )
constexprnoexcept

The configuration menuconfig selected.

Returns
Config{} with the curve, channel, resolution, series resistor, topology, averaging and temperature window from Kconfig; with no curve option set, the empty curve of Config{}.

◆ SelfHeatingMicrowatts()

constexpr uint32_t ntc_thermistor::SelfHeatingMicrowatts ( const Config &  config,
uint32_t  r_ntc_ohm 
)
constexprnoexcept

The power the divider puts into the thermistor, in microwatts: V^2 * Rn / (Rs + Rn)^2.

Needs divider_supply_mv; a ratiometric configuration does not know the supply and gets 0. Divide by the part's dissipation constant (mW/K in your mounting) for the temperature rise.

Parameters
configThe configuration.
r_ntc_ohmThe thermistor's resistance.
Returns
Microwatts, rounded; 0 when the supply is not declared.

◆ ToMilliFahrenheit()

constexpr int32_t ntc_thermistor::ToMilliFahrenheit ( int32_t  mc)
constexprnoexcept

A temperature in milli-degrees Fahrenheit.

Parameters
mcMilli-degrees Celsius.
Returns
mc * 9 / 5 + 32000, rounded, saturated at the int32_t range.

◆ ToMilliKelvin()

constexpr int32_t ntc_thermistor::ToMilliKelvin ( int32_t  mc)
constexprnoexcept

A temperature in milli-kelvin.

Parameters
mcMilli-degrees Celsius.
Returns
mc + 273150, saturated at the int32_t range.