Configuration¶
The two coefficients the driver uses, where their values come from, and how to calibrate them for one sensor.
The driver has no configuration structure and no registers: the constructor's two coefficient arguments and the
plausibility range are the whole configuration. Snippets are compiled from tests/docs/configuration.cpp.
Constructor arguments¶
| Argument | Default | Meaning |
|---|---|---|
adc_interface |
AdcType*: your adapter; must outlive the driver |
|
adc_channel |
uint8_t: passed to ReadChannelV() unchanged |
|
v_zero_c |
0.5F |
Output at 0 °C, in volts |
v_per_c |
0.01F |
Slope in volts per °C; must be finite and greater than 0 |
The coefficients cannot be changed after construction. VoltsAtZeroC() and VoltsPerCelsius() read them back.
Datasheet values¶
| Part | v_zero_c (V) |
v_per_c (V/°C) |
|---|---|---|
| MCP9700, MCP9700A, MCP9700B | 0.500 | 0.0100 |
| MCP9701, MCP9701A | 0.400 | 0.0195 |
These are typical values from the DC Electrical Characteristics; the datasheet gives no minimum or maximum for them. The spread between parts is in the accuracy limits instead (Hardware).
One-point calibration¶
Measure VOUT once at a known temperature, keep the typical slope and move the offset. At +25 °C this gives ±0.5 °C typical from 0 °C to +70 °C (datasheet Section 4.1).
// One-point calibration: keep the 10 mV/°C slope, move the offset so the sensor reads the reference.
// Measured: VOUT = 0.7431 V while a reference thermometer next to it reads 24.6 °C.
constexpr float kSlope = hf::mcp9700::kDefaultVoltsPerCelsius;
constexpr float kOffset = 0.7431F - kSlope * 24.6F; // 0.4971 V at 0 °C
Read the voltage with the same ADC and adapter you will use in operation, so the ADC's offset is calibrated out too. Let the sensor and the reference settle at the same temperature first.
Two-point calibration¶
Measure VOUT at two temperatures far apart, for example 0 °C and +70 °C, and fit both coefficients.
struct Coefficients {
float v_zero_c; // volts at 0 °C
float v_per_c; // volts per °C
};
// Two-point calibration: VOUT measured at two reference temperatures far apart (here 0 °C and +70 °C).
constexpr Coefficients two_point(float t1_c, float v1, float t2_c, float v2) {
const float slope = (v2 - v1) / (t2_c - t1_c);
return {v1 - slope * t1_c, slope};
}
constexpr Coefficients kUnit7 = two_point(0.0F, 0.4987F, 70.0F, 1.2034F);
This also corrects the ADC's gain error. It cannot correct the sensor's nonlinearity (±0.5 °C typical over 0 °C to +70 °C), which remains between and outside the two points.
Apply the coefficients¶
hf::mcp9700::Mcp9700Thermistor<MyAdc> one_point(&adc, 0, kOffset, kSlope);
hf::mcp9700::Mcp9700Thermistor<MyAdc> two_point_sensor(&adc, 1, kUnit7.v_zero_c, kUnit7.v_per_c);
Store the coefficients per unit (non-volatile memory, a calibration table) and pass them at construction.
Other parts of the family¶
// MCP9701 / MCP9701A: same transfer function, different typicals (datasheet DC characteristics).
constexpr float kMcp9701VoltsAtZeroC = 0.400F; // 400 mV
constexpr float kMcp9701VoltsPerCelsius = 0.0195F; // 19.5 mV/°C
constexpr float kMcp9701MinCelsius = -10.0F; // specified range -10 °C to +125 °C
constexpr float kMcp9701MaxCelsius = 125.0F;
bool make_mcp9701(MyAdc& adc) {
hf::mcp9700::Mcp9700Thermistor<MyAdc> sensor(&adc, 2, kMcp9701VoltsAtZeroC, kMcp9701VoltsPerCelsius);
return sensor.SetSpecifiedRange(kMcp9701MinCelsius, kMcp9701MaxCelsius) && sensor.Initialize();
}
The MCP9701 and MCP9701A use the same equation with these typicals, a 3.1 V to 5.5 V supply and an output of 200 mV to 3 V, specified from −10 °C to +125 °C, so the snippet narrows the plausibility range as well. The driver was written and tested for the MCP9700 family; with these coefficients it computes the MCP9701 transfer function the same way.
Plausibility range¶
ReadTemperatureCelsius() fails with Error::kOutOfRange when the result is outside the specified temperature
range widened by a margin on both sides (API guide). Set it with
SetSpecifiedRange(min_celsius, max_celsius, margin_celsius).
| Part | min_celsius |
max_celsius |
Datasheet |
|---|---|---|---|
| MCP9700, MCP9700A, MCP9700B (default) | −40 | +125 | Temperature Characteristics, specified range |
| MCP9700, MCP9700B high temperature (SOT-23-3, SC70-5) | −40 | +150 | Temperature Characteristics |
| MCP9701, MCP9701A | −10 | +125 | Temperature Characteristics |
The margin defaults to 8 °C (kDefaultRangeMarginCelsius). It must be zero or more; a minimum that is not below
the maximum, or a value that is not finite, is refused and the previous range is kept.
Next¶
Porting writes the ADC adapter; Transfer function explains the error budget.