MCP9700 Driver
API reference
Loading...
Searching...
No Matches
Public Member Functions | List of all members
hf::mcp9700::Mcp9700Thermistor< AdcType > Class Template Reference

Template driver for MCP9700 family sensors on a multiplexed ADC. More...

#include <mcp9700_thermistor.hpp>

Public Member Functions

 Mcp9700Thermistor (AdcType *adc_interface, uint8_t adc_channel, float v_zero_c=kDefaultVoltsAtZeroC, float v_per_c=kDefaultVoltsPerCelsius) noexcept
 
 Mcp9700Thermistor (const Mcp9700Thermistor &)=delete
 
Mcp9700Thermistor & operator= (const Mcp9700Thermistor &)=delete
 
 ~Mcp9700Thermistor () noexcept=default
 
bool Initialize () noexcept
 Initialize the underlying ADC (calls EnsureInitialized on the adapter).
 
bool Deinitialize () noexcept
 Release logical ownership; underlying ADC teardown is adapter-specific.
 
bool ReadTemperatureCelsius (float *temperature_celsius) noexcept
 Read temperature in degrees Celsius.
 
bool ReadVoltage (float *voltage_v) noexcept
 Read the raw sensor output voltage (volts at VOUT, as the adapter reports it).
 
bool SetSpecifiedRange (float min_celsius, float max_celsius, float margin_celsius=kDefaultRangeMarginCelsius) noexcept
 Set the temperature range a reading must fall in to be accepted.
 
float SpecifiedMinCelsius () const noexcept
 Lower end of the specified range (°C).
 
float SpecifiedMaxCelsius () const noexcept
 Upper end of the specified range (°C).
 
float RangeMarginCelsius () const noexcept
 Margin added on both sides of the specified range (°C).
 
Error LastError () const noexcept
 Why the last call that can fail failed; Error::kNone after a success.
 
bool HasValidCoefficients () const noexcept
 True when the coefficients can be used: a finite offset and a finite slope above zero.
 
float VoltsAtZeroC () const noexcept
 Last configured output at 0 °C (volts).
 
float VoltsPerCelsius () const noexcept
 Last configured sensitivity (volts per °C).
 

Detailed Description

template<typename AdcType>
class hf::mcp9700::Mcp9700Thermistor< AdcType >

Template driver for MCP9700 family sensors on a multiplexed ADC.

Template Parameters
AdcTypePlatform ADC adapter providing:
  • bool EnsureInitialized() noexcept
  • int ReadChannelV(uint8_t channel, float* voltage_v) noexcept returning 0 on success and non-zero on failure (compatible with enums whose underlying value uses 0 for success).

Constructor & Destructor Documentation

◆ Mcp9700Thermistor() [1/2]

template<typename AdcType >
hf::mcp9700::Mcp9700Thermistor< AdcType >::Mcp9700Thermistor ( AdcType *  adc_interface,
uint8_t  adc_channel,
float  v_zero_c = kDefaultVoltsAtZeroC,
float  v_per_c = kDefaultVoltsPerCelsius 
)
noexcept
Parameters
adc_interfaceNon-owning pointer to the ADC adapter (must outlive this object).
adc_channelLogical channel index passed to ReadChannelV (driver-specific).
v_zero_cVolts at 0 °C (default 0.5 V per datasheet).
v_per_cVolts per °C (default 0.01 V/°C per datasheet).

◆ Mcp9700Thermistor() [2/2]

template<typename AdcType >
hf::mcp9700::Mcp9700Thermistor< AdcType >::Mcp9700Thermistor ( const Mcp9700Thermistor< AdcType > &  )
delete

◆ ~Mcp9700Thermistor()

template<typename AdcType >
hf::mcp9700::Mcp9700Thermistor< AdcType >::~Mcp9700Thermistor ( )
defaultnoexcept

Member Function Documentation

◆ Deinitialize()

template<typename AdcType >
bool hf::mcp9700::Mcp9700Thermistor< AdcType >::Deinitialize ( )
noexcept

Release logical ownership; underlying ADC teardown is adapter-specific.

◆ HasValidCoefficients()

template<typename AdcType >
bool hf::mcp9700::Mcp9700Thermistor< AdcType >::HasValidCoefficients ( ) const
inlinenoexcept

True when the coefficients can be used: a finite offset and a finite slope above zero.

Initialize() fails with Error::kInvalidCoefficients when this is false. A NaN or infinite offset or slope would otherwise make every reading NaN, 0 or infinite.

◆ Initialize()

template<typename AdcType >
bool hf::mcp9700::Mcp9700Thermistor< AdcType >::Initialize ( )
noexcept

Initialize the underlying ADC (calls EnsureInitialized on the adapter).

◆ LastError()

template<typename AdcType >
Error hf::mcp9700::Mcp9700Thermistor< AdcType >::LastError ( ) const
inlinenoexcept

Why the last call that can fail failed; Error::kNone after a success.

◆ operator=()

template<typename AdcType >
Mcp9700Thermistor & hf::mcp9700::Mcp9700Thermistor< AdcType >::operator= ( const Mcp9700Thermistor< AdcType > &  )
delete

◆ RangeMarginCelsius()

template<typename AdcType >
float hf::mcp9700::Mcp9700Thermistor< AdcType >::RangeMarginCelsius ( ) const
inlinenoexcept

Margin added on both sides of the specified range (°C).

◆ ReadTemperatureCelsius()

template<typename AdcType >
bool hf::mcp9700::Mcp9700Thermistor< AdcType >::ReadTemperatureCelsius ( float *  temperature_celsius)
noexcept

Read temperature in degrees Celsius.

Fails (returns false, output untouched, LastError() == Error::kOutOfRange) when the converted temperature is outside [SpecifiedMinCelsius() - RangeMarginCelsius(), SpecifiedMaxCelsius() + RangeMarginCelsius()] or the voltage is not finite: that is an open, grounded or shorted input or a wrong ADC scale, not a temperature.

◆ ReadVoltage()

template<typename AdcType >
bool hf::mcp9700::Mcp9700Thermistor< AdcType >::ReadVoltage ( float *  voltage_v)
noexcept

Read the raw sensor output voltage (volts at VOUT, as the adapter reports it).

One ReadChannelV() call, no conversion and no range check, so it shows what the pin really reads when ReadTemperatureCelsius() fails with Error::kOutOfRange.

Returns
false (output untouched) when not initialised, voltage_v is null or the adapter fails.

◆ SetSpecifiedRange()

template<typename AdcType >
bool hf::mcp9700::Mcp9700Thermistor< AdcType >::SetSpecifiedRange ( float  min_celsius,
float  max_celsius,
float  margin_celsius = kDefaultRangeMarginCelsius 
)
noexcept

Set the temperature range a reading must fall in to be accepted.

Defaults: -40 °C to +125 °C with an 8 °C margin. Use -10 °C to +125 °C for the MCP9701/9701A and up to +150 °C for the high-temperature MCP9700/9700B parts (DS20001942, Temperature Characteristics).

Returns
false (settings unchanged, LastError() == Error::kInvalidArgument) when a value is not finite, min_celsius >= max_celsius or margin_celsius < 0.

◆ SpecifiedMaxCelsius()

template<typename AdcType >
float hf::mcp9700::Mcp9700Thermistor< AdcType >::SpecifiedMaxCelsius ( ) const
inlinenoexcept

Upper end of the specified range (°C).

◆ SpecifiedMinCelsius()

template<typename AdcType >
float hf::mcp9700::Mcp9700Thermistor< AdcType >::SpecifiedMinCelsius ( ) const
inlinenoexcept

Lower end of the specified range (°C).

◆ VoltsAtZeroC()

template<typename AdcType >
float hf::mcp9700::Mcp9700Thermistor< AdcType >::VoltsAtZeroC ( ) const
inlinenoexcept

Last configured output at 0 °C (volts).

◆ VoltsPerCelsius()

template<typename AdcType >
float hf::mcp9700::Mcp9700Thermistor< AdcType >::VoltsPerCelsius ( ) const
inlinenoexcept

Last configured sensitivity (volts per °C).


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