Time-of-flight sensor: how ToF works and why calibration decides everything

Time-of-flight sensor: how ToF works and why calibration decides everything

A time-of-flight (ToF) sensor measures distance by emitting a pulse of infrared light and timing how long it takes to return; at the speed of light, every nanosecond of round trip is about 15 centimeters of distance. Modern single-chip ToF sensors do this with an array of single-photon avalanche diodes (SPADs) and report distance for one zone or a grid of zones, typically 4 by 4 or 8 by 8, at ranges from a few centimeters to about 4 meters. The raw reading is only as good as three calibrated numbers: an offset correction, a crosstalk coefficient and a reference SPAD count. Without them, readings carry systematic errors of tens of millimeters, which is enough to misfire a trigger or miss an event entirely.

This post explains how a ToF sensor works, what each calibration value corrects, how ToF compares with other proximity sensors, and the two ways calibration gets silently lost in a shipped product.

The short version

  • ToF sensors time infrared light directly; they are not affected by target color the way infrared reflectance sensors are, and they return an absolute distance rather than a relative signal.
  • Three calibration values (offset, crosstalk, reference SPAD) must be measured per unit, after the sensor is behind its cover glass, and stored in non-volatile memory.
  • Multizone ToF sensors return a small depth grid, which lets a product detect where in its field of view something is, not only how far away.
  • Calibration stored at a fixed flash address can be silently invalidated by a firmware update that swaps flash banks; redundant slots in both banks prevent that.

How a time-of-flight sensor measures distance

There are two ToF methods. Direct ToF (dToF) emits a short laser pulse, usually from a 940 nm vertical-cavity surface-emitting laser (VCSEL), and measures the arrival time of returning photons with a SPAD array and a time-to-digital converter. Indirect ToF (iToF) emits modulated light and measures the phase shift of the returned signal. Most small proximity and ranging sensors in consumer products are direct ToF; iToF is more common in depth cameras.

In a direct ToF sensor, each SPAD fires when a single photon arrives. Over many pulses the sensor builds a histogram of arrival times; the peak of that histogram is the target’s round-trip time, and half of it times the speed of light is the distance. Because the measurement is a time, not an intensity, a dark target and a bright target at the same distance return the same reading, as long as enough photons come back to form a peak. That is the main advantage over classic infrared reflectance sensors, whose output depends on how reflective the target is.

Multizone sensors such as ST’s VL53L5CX split the SPAD array into a grid, 4 by 4 or 8 by 8 zones, and return a distance per zone. The result is a very low-resolution depth image, enough to tell whether an object is centered in the field of view or at its edge, approaching or leaving, and roughly how large it is.

The three calibration values and what they fix

The datasheet distance of a ToF sensor assumes an ideal mounting. Real products put the sensor behind a cover window, inside a housing, at a position that varies by fractions of a millimeter between units. Three corrections bring the reading back to truth.

Calibration

What causes the error

What happens if it is missing

Offset

The physical distance between the emitter aperture and the mounting surface is never exactly zero; the housing adds its own path length

Every reading is shifted by a constant; a 2 mm mounting offset is enough to misfire a trigger set at the edge of its window

Crosstalk

Infrared energy reflects off the cover glass straight back into the detector without reaching the target

Every reading is shorter than the true distance, and the error grows as the target gets farther or darker

Reference SPAD

Individual photodiodes in the array vary in sensitivity; the sensor must select the best-performing set and bias them correctly

Higher noise variance, visible as jitter between successive readings at a fixed distance

Offset is measured by placing a target at a known distance, often a gray card at 100 mm or 140 mm depending on the part, and recording the difference. Crosstalk is measured with a target far enough away that it returns almost nothing, so whatever the sensor sees is the cover glass. Reference SPAD calibration is a procedure the sensor runs on itself with no target. All three must be done after final assembly, because the cover glass and the housing are what create the errors.

Our own camera node uses a narrow 4 by 4 zone ToF sensor as the trigger that wakes the camera when something enters the capture window. With calibration missing, the trigger fires at the wrong distance and the camera captures either an empty bowl or nothing. The detail of what each value does on that sensor is in ToF calibration persistence with dual-bank flash redundancy.

ToF compared with other proximity sensors

Sensor

Measures

Strengths

Weaknesses

Time-of-flight

Absolute distance from light travel time

Independent of target color; millimeter resolution; multizone variants give position

Cover glass crosstalk; ambient sunlight reduces range; needs per-unit calibration

Infrared reflectance

Returned light intensity

Cheap; tiny

Reading depends on target reflectivity; no absolute distance

Ultrasonic

Echo time of a sound pulse

Long range; works on glass

Slow; wide beam; poor on soft or angled targets; audible to some animals

Passive infrared (PIR)

Change in body heat across zones

Very low power; cheap

Detects motion only, not distance or presence of a still object

Capacitive

Change in electric field

No emitter; works through plastic

Very short range; affected by moisture

For a product that needs to know that a specific object is at a specific distance in a specific place, ToF is usually the only sensor in this table that answers all three questions. For “did something move in the room,” PIR is cheaper and uses less power.

Where ToF sensors fail in the field

Bright sunlight. Ambient infrared adds noise photons to the histogram and shortens usable range, sometimes by half. Sensors report an ambient level; firmware should read it and widen averaging or raise thresholds when it climbs.

Transparent and glossy targets. Clear water, glass and polished metal return little light or return it from an unexpected surface. A ToF sensor pointed at a bowl of water may read the bottom of the bowl, the surface, or a mixture, depending on angle.

Cover glass changes. Scratches, condensation and a film of grease all change crosstalk. A crosstalk value measured on a clean window drifts as the product ages. Products that live in kitchens should expect this.

Edge-of-window trigger thresholds. A trigger set at the boundary of a capture window is the most sensitive to offset error. Set thresholds with margin on both sides, and prefer “distance crossed into a band” over “distance equals a value.”

Lost calibration. The most expensive failure is the one that leaves no trace: a firmware update erases or relocates the calibration, and the device boots on factory defaults, reporting plausible distances that are wrong by tens of millimeters.

Keeping calibration alive through firmware updates

Calibration values live in non-volatile memory, and on a microcontroller that usually means a reserved area of the same flash the firmware occupies. Two things break that arrangement.

The first is live firmware updates that swap flash banks. On a dual-bank microcontroller, an update writes the new firmware to the inactive bank and then flips which bank the processor executes from, so the logical address space changes. A calibration slot at one fixed logical address can end up pointing at the wrong physical bank after a swap. The bootloader side of that mechanism is described in firmware updates with bank switching on STM32H5.

The second is sector reservation conflicts. If the bootloader reserves the last sector of each bank for update metadata and the calibration slot is placed in that same sector, every update zeroes the calibration along with the old metadata, with no error and no log entry.

The design that survives both is redundancy with a contract: four calibration slots (primary and backup in each of the two banks), every write touches all four, every boot reads the first slot that passes validation and stops. With 1 MB per bank and 8 KB sectors, the slots sit at offsets of minus three and minus two sectors from each bank’s end, never at minus one where the update metadata lives. A power loss mid-write, a single sector failure or a full bank swap cannot then leave the device without valid calibration. Our post on the recovery bootloader that cannot be overwritten covers the same discipline applied to the bootloader itself.

How EverBowl™ uses time-of-flight sensing

EverBowl™ learns how a dog eats and drinks from thousands of ordinary visits to the bowl, and each of those visits starts with knowing that a dog has arrived. A time-of-flight sensor is the trigger: it recognizes that something has entered the capture window at the right distance and wakes the camera, which keeps the camera asleep the rest of the day and keeps the record free of empty frames. Because that trigger depends on three calibrated numbers, the calibration is stored redundantly across both flash banks so a firmware update in the field never costs a household its accuracy. EverBowl does not diagnose anything; the value is the record, and the record is only as reliable as the sensor that decides when to look.

Conclusion

A time-of-flight sensor gives an absolute distance that does not depend on target color, and multizone variants add coarse position for very little power. The accuracy promised in the datasheet exists only after offset, crosstalk and reference SPAD calibration are measured on the assembled unit and stored where nothing can erase them. If you ship a product with a ToF sensor, do two things this week: confirm calibration happens after the cover glass is fitted, and confirm the calibration slot’s flash address cannot collide with, or be swapped away from, your firmware update mechanism.

FAQs

What does a time-of-flight sensor do?

It measures the distance to an object by emitting infrared light and timing how long the light takes to return. Single-chip ToF sensors report distance for one zone or a grid of zones at ranges from a few centimeters to about 4 meters.

What is the difference between direct and indirect ToF?

Direct ToF times individual light pulses with a SPAD array and a time-to-digital converter. Indirect ToF measures the phase shift of modulated light. Small proximity and ranging sensors are usually direct ToF; depth cameras are often indirect.

Why does a ToF sensor need calibration?

Because the housing and cover glass add offset and crosstalk that the factory cannot know, and because the photodiode array varies between units. Offset, crosstalk and reference SPAD calibration remove systematic errors of tens of millimeters.

Does a ToF sensor work through glass or plastic?

Yes, through an infrared-transparent cover, but the cover reflects some light back into the detector. That crosstalk must be measured and corrected after assembly, and it changes if the cover gets scratched or dirty.

How accurate is a time-of-flight sensor?

Calibrated short-range ToF sensors typically achieve accuracy within a few millimeters to a few percent of distance indoors. Accuracy degrades in bright sunlight, on glossy or transparent targets, and when calibration is missing.

Can a firmware update erase sensor calibration?

Yes, if calibration is stored at a fixed flash address that a bank-swapping update relocates or in a sector the bootloader reserves. Redundant calibration slots in both flash banks, away from the update metadata sector, prevent it.

Read more