MCP9700 Driver 0.1.0
API reference
Loading...
Searching...
No Matches
Classes | Concepts | Enumerations | Functions | Variables
mcp9700 Namespace Reference

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

Classes

struct  AccuracyBand
 One accuracy limit of the datasheet: the error band guaranteed over a temperature span. More...
 
struct  AccuracyLimits
 The guaranteed error limits at one temperature, milli-C. More...
 
class  AdcInterface
 CRTP base of the platform ADC port. More...
 
struct  Config
 Everything EnsureInitialized() uses. Config{} is an MCP9700 on a 12 bit, 3.3 V ADC. More...
 
struct  CustomSpec
 What the user declares for Variant::Custom. Every field must be set (an all-zero declaration fails Validate()); every field must stay zero for a named variant. More...
 
class  MCP9700
 Driver for one MCP970x analog temperature sensor (or a declared Custom part) on an ADC port. More...
 
struct  Measurement
 The temperature and the voltage behind it, from one validated reading. 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  VariantSpec
 One row of the variant table: the only place a coefficient, range, supply, accuracy band or package list lives. The code never branches on a variant name. 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  CtrlPin : uint8_t { Enable = 0 }
 Control pins the port may drive through the optional GpioSet() hook. More...
 
enum class  GpioSignal : uint8_t { INACTIVE = 0 , ACTIVE = 1 }
 Logical level of a control pin; the port maps it to the physical polarity. More...
 
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::OutputLow = 16 , Error::OutputHigh = 17 ,
  Error::Saturated = 18 , Error::Unstable = 19
}
 Why a call failed. Values 0 to 9 are the shared base set; chip-specific values start at 16. More...
 
enum class  Variant : uint8_t {
  Variant::Mcp9700 = 0 , Variant::Mcp9700A = 1 , Variant::Mcp9700B = 2 , Variant::Mcp9701 = 3 ,
  Variant::Mcp9701A = 4 , Variant::Custom = 5
}
 Which part of the family is wired up: one of the five datasheet devices, or Custom. More...
 
enum class  TemperatureClass : uint8_t { TemperatureClass::Extended = 0 , TemperatureClass::High = 1 }
 The temperature class of the part: the upper end of its specified range. More...
 
enum class  LogLevel : uint8_t { LogLevel::Error = 0 , LogLevel::Warning , LogLevel::Info , LogLevel::Debug }
 Severity passed to the optional Log() hook. More...
 

Functions

constexpr Config KconfigDefaults () noexcept
 The configuration menuconfig selected, on top of the datasheet defaults.
 
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 Result< VariantSpec > ResolveSpec (const Config &config) noexcept
 The effective variant row of a configuration: a table row, or the row built from the Custom declaration. No I/O.
 
constexpr int32_t OutputMvToMilliC (const VariantSpec &spec, uint32_t output_mv) noexcept
 The temperature of an output voltage, from the row's V0 and TC; rounded half away from zero. No window check, no calibration.
 
constexpr uint32_t MilliCToOutputMv (const VariantSpec &spec, int32_t temperature_mc) noexcept
 The output voltage of a temperature: the inverse of OutputMvToMilliC(), rounded to the nearest millivolt.
 
constexpr Result< AccuracyLimits > AccuracyLimitsFor (const VariantSpec &spec, TemperatureClass range, int32_t temperature_mc) noexcept
 The error limits the datasheet guarantees at a temperature (first band that contains it, narrowest first). With High only the High-option rows (-40 to +150 C) apply over the whole range: the datasheet does not say that an H part also meets the tighter Extended rows. For a named variant they hold at its tested supply; the driver never applies them to a reading.
 
constexpr float ToCelsius (int32_t milli_c) noexcept
 A temperature as float degrees Celsius, for printing and for callers that want it. The only floating-point in the driver.
 
constexpr Config ConfigFor (Variant variant) noexcept
 The configuration of a named part: Config{} with that variant.
 
constexpr Config FastPreset () noexcept
 One conversion per reading: lowest latency, no noise rejection.
 
constexpr Config LowNoisePreset () noexcept
 32 conversions 200 us apart: averages ADC noise and mains pickup.
 
constexpr Config Mcp9701Preset () noexcept
 The MCP9701 transfer function and range.
 
constexpr Config HighTemperaturePreset () noexcept
 An MCP9700 with the High temperature option (to +150 C).
 
constexpr const char * GetDriverVersion () noexcept
 
constexpr uint32_t GetDriverVersionMajor () noexcept
 
constexpr uint32_t GetDriverVersionMinor () noexcept
 
constexpr uint32_t GetDriverVersionPatch () noexcept
 

Variables

constexpr uint32_t kMaxOutputCurrentUa = 100U
 
constexpr uint32_t kMaxLoadCapacitancePf = 1000U
 
constexpr uint32_t kOutputImpedanceOhm = 20U
 Typical output impedance, ohms, at 100 uA and 500 Hz (Z_OUT, p.4).
 
constexpr uint32_t kPowerOnTypicalUs = 800U
 
constexpr uint16_t kMaxSamples = 64U
 Largest number of conversions one reading averages.
 
constexpr uint32_t kMaxSampleIntervalUs = 100'000U
 Largest wait between two conversions, microseconds.
 
constexpr uint8_t kMaxDiscard = 4U
 Largest number of dummy conversions before a reading.
 
constexpr uint32_t kMaxPowerOnSettleUs = 1'000'000U
 Largest power-on wait, microseconds.
 
constexpr uint64_t kMaxAveragingWindowUs = 1'000'000ULL
 Longest span of one reading, (discard + samples - 1) x interval, microseconds: below the 1.3 s thermal response (t_RES, p.4), so an average is never staler than the sensor (design decision).
 
constexpr uint32_t kMaxSpreadLimitMv = 1000U
 Largest max_spread_mv.
 
constexpr int32_t kMaxOffsetCalMc = 20'000
 Largest absolute offset_cal_mc, milli-degrees.
 
constexpr int32_t kMaxRangeMarginMc = 20'000
 Largest range_margin_mc, milli-degrees.
 
constexpr uint32_t kMinAdcFullScaleMv = 100U
 Smallest declarable ADC full scale, millivolts.
 
constexpr uint32_t kMaxAdcFullScaleMv = 10'000U
 Largest declarable ADC full scale, millivolts.
 
constexpr uint8_t kMinAdcResolutionBits = 8U
 Smallest declarable ADC resolution, bits.
 
constexpr uint8_t kMaxAdcResolutionBits = 16U
 Largest declarable ADC resolution, bits.
 
constexpr uint32_t kCustomMinTcUvPerC = 1000U
 Custom: smallest slope, microvolts per degree.
 
constexpr uint32_t kCustomMaxTcUvPerC = 100'000U
 Custom: largest slope, microvolts per degree.
 
constexpr uint32_t kCustomMaxV0Mv = 5000U
 Custom: largest output at 0 C, millivolts.
 
constexpr int32_t kCustomMaxTemperatureMc = 200'000
 Custom: largest absolute temperature limit, milli-degrees.
 
constexpr uint32_t kCustomMaxOutputMv = 20'000U
 Custom: largest output voltage anywhere in the declared range, millivolts.
 
constexpr int32_t kCustomMaxAccuracyMc = 20'000
 Custom: largest absolute accuracy limit, milli-degrees.
 
constexpr uint8_t kPackageSot23 = 1U
 Package bit: SOT-23-3 (/TT).
 
constexpr uint8_t kPackageSc70 = 2U
 Package bit: SC70-5 (/LT).
 
constexpr uint8_t kPackageTo92 = 4U
 Package bit: TO-92-3 (/TO).
 
constexpr uint8_t kPackagesAll
 Every package: SOT-23-3, SC70-5 and TO-92-3.
 
constexpr uint8_t kPackagesNoTo92 = static_cast<uint8_t>(kPackageSot23 + kPackageSc70)
 The packages without TO-92-3 (the MCP9700B, and the High option of every part).
 
constexpr std::size_t kMaxBands = 4U
 Most accuracy bands one row holds.
 
constexpr std::array< VariantSpec, 5 > kVariantTable
 The five datasheet devices (DS20001942L), indexed by Variant. Every value is cited in docs/hardware.md: coefficients p.3 and p.4, supply p.3, ranges p.4, accuracy p.3, packages p.12 and p.23.
 

Detailed Description

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

Enumeration Type Documentation

◆ CtrlPin

enum class mcp9700::CtrlPin : uint8_t
strong

Control pins the port may drive through the optional GpioSet() hook.

Enumerator
Enable 

Supply of the sensor from an MCU pin (Section 4.2); ACTIVE means powered.

◆ GpioSignal

enum class mcp9700::GpioSignal : uint8_t
strong

Logical level of a control pin; the port maps it to the physical polarity.

Enumerator
INACTIVE 

The pin function is deasserted.

ACTIVE 

The pin function is asserted.

Function Documentation

◆ KconfigDefaults()

constexpr Config mcp9700::KconfigDefaults ( )
constexprnoexcept

The configuration menuconfig selected, on top of the datasheet defaults.

Returns
Config{} with the channel, variant, ADC full scale, averaging and calibration from Kconfig; the Custom fields are filled only for Variant::Custom.

Variable Documentation

◆ kMaxLoadCapacitancePf

constexpr uint32_t mcp9700::kMaxLoadCapacitancePf = 1000U
inlineconstexpr

Capacitive load the family is characterised and production tested with, picofarads (p.4, note 4).

◆ kMaxOutputCurrentUa

constexpr uint32_t mcp9700::kMaxOutputCurrentUa = 100U
inlineconstexpr

Most current the output may source or sink, microamps (I_OUT, DS20001942L p.4): the ADC input, including its sample-and-hold charge, must stay below it on average.

◆ kPowerOnTypicalUs

constexpr uint32_t mcp9700::kPowerOnTypicalUs = 800U
inlineconstexpr

Typical turn-on time, microseconds (t_ON, p.4); the datasheet gives no maximum.