Q&A-14How do you calibrate an analog sensor, and what is the difference between zero error and span error adjustment?
Answer
Calibration fits the sensor's raw output to true physical units. For a sensor that is linear over its range, that fit is two numbers, offset and gain, and the two error types map onto them exactly. Zero error is the offset: a constant shift, the same magnitude at every input. Span error is the gain: a slope error that is zero at the zero point and grows to its maximum at full scale. You correct zero with one known low reference, span with a second known high reference, and in analog hardware you iterate because the two adjustments interact.
State these assumptions before you start: the sensor is linear (or piecewise linear) over the range that matters; the reference you calibrate against is traceable and at least ~4× more accurate than the target; and the ADC reference is stable. A ratiometric sensor must share its excitation reference with the ADC, or supply drift shows up as span error.
Zero vs span
| Zero (offset) error | Span (gain) error | |
|---|---|---|
| Wrong term in y = m·x + b | b | m |
| Error at zero input | full magnitude | zero |
| Error at full scale | same as at zero | maximum |
| Typical cause | amplifier offset, bridge imbalance, ADC offset | gain-resistor tolerance, reference error, sensor sensitivity tolerance |
| Correction | one-point trim at low reference | two-point trim at high reference |
Two-point procedure
- Apply a known low reference (0 psi, ice point, 4.00 mA). Record raw counts x₁.
- Apply a known high reference near full scale. Record x₂.
- Solve m = (y₂ − y₁)/(x₂ − x₁) and b = y₁ − m·x₁.
- In hardware, trim zero first, then span, then re-check zero. If the zero trim sits ahead of the gain stage, its offset is multiplied by the gain, so any span change moves the zero. Iterate until both endpoints are inside tolerance.
- In firmware the two constants come out of the two points in one shot: no iteration.
typedef struct {
float raw_zero, raw_span; // x1, x2
float phys_zero, phys_span; // y1, y2
float gain, offset; // m, b
} SensorCal;
void compute_cal_constants(SensorCal *cal) {
cal->gain = (cal->phys_span - cal->phys_zero) /
(cal->raw_span - cal->raw_zero); // guard x2 != x1
cal->offset = cal->phys_zero - cal->gain * cal->raw_zero;
}
float convert_raw_to_phys(const SensorCal *cal, float raw_adc) {
return cal->gain * raw_adc + cal->offset;
}Worked example. 0–100 psi sensor, 10-bit ADC, V_ref = 5.0 V, LSB = 5.0/1024 = 4.883 mV. Conditioning is scaled so 0 psi → 0 counts and 100 psi → 1023 counts.
- 0 psi applied: x₁ = 51 counts. Zero error = +51 counts = +249 mV ≈ +5.54 psi.
- 100 psi applied: x₂ = 972 counts. Measured span = 972 − 51 = 921 counts against an ideal 1023 → span error = −9.97% FS.
- m = 100/921 = 0.10858 psi/count; b = −0.10858 × 51 = −5.537 psi.
- At 900 counts: y = 0.10858 × 900 − 5.537 = 92.18 psi. The uncalibrated formula (900/1023 × 100) gives 87.98 psi: 4.2 psi low.
- With no calibration, the 51 counts the sensor actually produces at true 0 psi is reported as 51/1023 × 100 = 4.99 psi of phantom pressure.
Failure modes and how to catch them
- Nonlinearity (bow). Two-point calibration leaves a midscale residual. Check a third point at 50% FS; if the residual exceeds tolerance, fit a polynomial or lookup table instead.
- Hysteresis. Up-scale and down-scale readings differ. Approach the same setpoint from both directions and compare.
- Reference error. A 0.25%-accurate gauge caps your calibration at 0.25%. Use a reference at least 4× better than the target accuracy.
- Temperature drift. Zero and span have separate tempcos; a sensor trimmed at 25 °C can be out of spec at 85 °C. Check the datasheet tempco or calibrate at two temperatures.
- Quantization. A 4.883 mV LSB on a 10-bit ADC means you cannot resolve better than ~1 LSB without averaging.
When two-point is the wrong tool. Strongly nonlinear sensors (thermocouples, some RTDs) need multi-point fits. Sensors that ship with factory coefficients (IEEE 1451 TEDS) need those coefficients applied, not derived.
Curated: · Written: · Reviewed:
Log in free to save your progress and keep bookmarks and notes for a quick revision before your interview.