A single-photon lidar pixel catches at most one photon per laser shot, so it builds a histogram of thousands of shots. Sunlight arrives first and hides the echo.
Learn how a photon becomes a timestamp, how timestamps become a histogram, and why a bright day bends the peak toward the laser.
Press Fire 4,000 shots, then raise the sunlight. Switch between All photons and First photon only and watch the recorded peak slide early. Then we build every piece from zero: the detector, the stopwatch, the bins, the pile-up, and the fixes.
You need the idea that light travels at a fixed speed (the first ranging lesson covers it) and a little C. We build the rest from zero.
Sources: Sesta, Incoronato, Madonini and Villa, Measurement 212 (2023) 112705; Incoronato, Locatelli and Zappa, Sensors 21(13) 2021, statistical modelling of SPADs. The full list is in the Field Guide.
A model, not a measurement. Sunlight is the mean number of background photons the pixel would detect per shot across the whole 100 ns window; echo strength is the mean number of echo photons it would detect per shot. Both are illustrative. The target sits at 40 ns, which is 5.996 m. The laser pulse is Gaussian with a standard deviation of 0.6 ns. Bins are 0.5 ns wide. The recorder follows the Poisson model in Incoronato et al. 2021.
Chapter 0
See why one laser shot can never give a range, and why a pile of shots can
You stand in a dark hall with a torch that blinks for one billionth of a second. A wall stands some way off. You hold a stopwatch. You start it as the torch blinks. You stop it when the light comes back. Half the time on the stopwatch, multiplied by the speed of light, is the distance to the wall.
That is direct time of flight, or dToF: time the light's round trip, then convert time to distance with D = ½ · c · TOF. The first ranging lesson built this idea. Light covers about 30 cm in one nanosecond, so the range changes by 15 cm for every nanosecond of round trip.
Now take the hall away and put the wall outside, in the sun. The sun pours photons onto your detector all the time. A photon is the smallest packet of light, and your detector can see one at a time. Some of those photons come from your torch. Most come from the sun. The detector cannot tell them apart. It only says: “a photon came, now.”
A single-photon lidar pixel has three parts. Each has a chapter in this lesson.
The firmware and the chip logic around these three parts decide the range you report. A wrong choice in the histogram looks, on the screen, like a wall that is nearer than it is.
The pixel sees a mix of echo photons and sun photons. In one shot it may see zero echo photons, because the echo is faint. It may see three sun photons. The stopwatch stops on the first one. If that one is the sun, you read a random time. One shot lies.
But the sun is random in time, and the echo is not. The echo comes at the same delay on every shot. Fire the torch a thousand times and write down each stop time. Random times spread over the whole window. Echo times pile up on one slot. The tall column is your range.
Try it below. Each shot fires the laser once and shows every photon the pixel would catch. The recorder here keeps only the first. Fire one shot, then ten, then a thousand.
The strip on top is the last shot: warm ticks are echo photons, yellow ticks are sunlight, and the teal ring is the photon that stopped the clock. The bars below are the stop times of all shots so far. Press a button to fire more shots.
A model. The pixel catches 0.6 echo photons and 1.0 sunlight photons per shot on average (illustrative numbers). The target sits at 40 ns. Bins are 1 ns wide. The same shots are reused after Reset, so the picture repeats.
After one shot the histogram is a single bar, and it is probably wrong. After a thousand shots there is one clear column near 40 ns. That is the whole trick of this lesson: a noisy single-photon count becomes a clean range once you add up many shots.
The trick has a catch. The sun does not only add random bars. Because the clock stops on the first photon, sunlight that arrives before the echo can steal the stop. The echo then goes uncounted. This is pile-up, and it bends the histogram. The hero at the top of this page showed it. Chapters 4 to 6 explain it and fix it.
Take the light away and a shot is a small data record. The laser trigger opens a listening window of 100 ns. During it the pixel may give zero, one or several stop codes. Each code is an integer, for example a value from 0 to 199 at 0.5 ns per step. The firmware does not keep the list of codes. It adds one to a counter.
Three words keep the later chapters tidy. A shot is one laser pulse and its listening window. A histogram is the row of counters for one pixel, with shape [bins]. A frame is the histograms of all pixels, with shape [pixels][bins]. Chapter 7 puts byte counts on these shapes.
The time budget is plain arithmetic. If the laser fires 1,000,000 times a second, a point that collects 1,000 shots takes 1 ms. A scanner that must produce 100,000 points a second has 10 µs for each point, which is 10 shots. So every design trades two things: how many shots it can afford, and how clean the histogram must be. These rates are illustrative. A real sensor takes its laser rate from its datasheet and from its eye-safety limits.
One more rule sets the window. The next shot must not start before the echo of the last one has gone, or a far target answers in the wrong window. A 1 MHz laser repeats every 1,000 ns, which is 150 m of round trip. The 100 ns window used here covers only the first 15 m of that period, so the rest of the period is spare time for the electronics to reset.
Chapter 1
Follow a single photon into the detector, and see why a bright scene makes the pixel miss photons
Picture a mousetrap set so lightly that one grain of dust springs it. When it snaps, it makes a loud bang. The bang is the same size for a grain of dust or a heavy weight. Then you must reset the trap before it can catch anything again.
A SPAD (single-photon avalanche diode) works like that trap. A diode is a one-way gate for current. Here the diode sits at a bias voltage (a steady voltage across it) just above its breakdown voltage, the point where the gate bursts open. In this state, called Geiger mode, no current flows until something sets it off. A single photon frees one electron inside the silicon. That electron triggers an avalanche: many more electrons break free, and a large current pulse flows. The pulse is big and digital. It does not matter that the cause was one photon.
The pulse would keep flowing. A quenching circuit stops it by lowering the bias below breakdown, and then restores the bias. While this happens the SPAD sees nothing. That blind time is the hold-off time, also called dead time. In the simulations of Incoronato et al. it is 5 ns or 10 ns.
Sesta et al. list the reasons. A SPAD has single-photon sensitivity. It has no read-out noise, because its output is a pulse and not a small analogue voltage that an amplifier must measure. It needs a relatively low bias voltage. And it can be built in ordinary CMOS silicon next to its timing electronics, so thousands of pixels fit on one chip. They also note that SPADs can be wired together into a SiPM (silicon photomultiplier) that gives one common output, or kept as an SPAD array where every pixel reports on its own.
Not every photon that lands on the chip makes a pulse. Incoronato et al. write the rate of photons the detector sees as
Two things lower the number: photons that fall on circuit area, and photons that fall on the SPAD but do not set it off. The first is a layout choice. The second depends on the wavelength of the light and the bias.
Now the key effect for the rest of this lesson. After each avalanche the SPAD is blind for the hold-off time THO. A photon that arrives during that time is lost. Incoronato et al. model the stationary case, where light arrives steadily:
λspad = 0.05 per ns, THO = 10 ns: 0.05 / (1 + 0.5) = 0.0333 per ns (33.3 million pulses a second)
Work the example. The SPAD would trigger 0.05 times each nanosecond, which is 50 million a second. Each blind window of 10 ns holds 0.05 × 10 = 0.5 photons on average. The rate drops by a factor of 1.5, to 33.3 million a second. One photon in three never counts. Push the light ten times higher, to 0.5 per ns, and the output is 0.5 / 6 = 0.083 per ns. It can never pass 1 / THO = 0.1 per ns. The SPAD saturates.
The hold-off length is a design choice with a clear price. Take light at 0.2 photons per ns, which is 200 Mcps. A 5 ns hold-off counts 0.2 / (1 + 1) = 0.1 per ns, half the photons. A 20 ns hold-off counts 0.2 / (1 + 4) = 0.04 per ns, only one photon in five. Shorter is better for counting. Afterpulsing, the false second pulse described below, is one reason a designer cannot shrink the hold-off freely.
Splitting the light over several SPADs helps a great deal. Send 0.8 photons per ns to one SPAD with a 10 ns hold-off. It counts 0.8 / 9 = 0.089 per ns, only 11% of the photons. Spread the same light over 16 SPADs and each sees 0.05 per ns. Each counts 0.0333 per ns, and together they count 0.533 per ns, which is 67% of the photons. This is one reason lidar pixels are built from groups of SPADs. It also prepares the coincidence trick of Chapter 6.
Use the device. Each tick on the timeline is a photon. Teal ticks set off an avalanche. Red ticks arrived in the blind window and are lost. The curve below shows the formula, with a dot for your settings.
Top: 200 ns of photon arrivals. Blue bands are the hold-off after each pulse. Bottom: the pulse rate the SPAD can report against the photon rate it receives. Raise the light and lengthen the hold-off.
Mcps means million counts per second. The curve is the stationary formula of Incoronato et al. 2021 (non-paralysable hold-off). The simulated rate comes from 20,000 ns of seeded random arrivals. Dark counts and afterpulsing are left out here.
Look at the timeline at 50 Mcps with a 10 ns hold-off. Most photons count, and a few fall inside a band. Now push the light to 500 Mcps. Almost every band swallows several photons. The pulse rate barely moves, however much light you add.
The symptom: in bright sun, the count rate stops rising, and distant bright targets look the same as near dim ones. The measurement: plot the counted rate against the light level. A flat top near 1 / THO says the SPAD is saturated. The fixes: shorten the hold-off, split the light over many SPADs in a macro-pixel, or reduce the light with a narrow optical filter. Sesta et al. also point to short detector dead time as a design target, since it lets the pixel detect more useful photons per laser shot.
There are two more false-event sources the sources name. Afterpulsing is a second pulse caused by charge left over from the first avalanche. Crosstalk is a pulse in one SPAD triggered by an avalanche in its neighbour. Both add events that no photon caused. We leave them out of the devices and keep them in the checklist.
On real hardware. SPAD sensors are rarely on a hobby board. A simple way to see saturation is a Si photomultiplier or SPAD breakout read by an STM32 Nucleo timer in external-clock mode (TIM2 counts SPAD pulses). Raise a lamp's brightness and log the count per 1 ms gate. The curve should flatten as in the device.
Chapter 2
Turn a SPAD pulse into a number, and see how the size of one tick sets the size of one range step
Take a stopwatch that ticks once a second, and a runner who finishes between two ticks. You read 12 seconds, not 12.4. The watch rounds the time down to its tick. Every reading hides up to one tick of error.
A TDC (time-to-digital converter) is that stopwatch for very short times. Two electrical edges define a time interval. The START edge opens the interval. In our pixel the laser trigger sends it. The STOP edge closes it. The SPAD pulse sends that. The TDC outputs a digital code, an integer, that says how many ticks passed in between.
Sesta et al. sort TDCs into a few families. The simplest is a counter. START enables a counter. The counter counts clock periods until STOP arrives. The tick is one clock period, so the clock sets the resolution. A 100 MHz clock gives a 10 ns tick, which is 1.5 m of range. That is fine for a rough, long-range meter and far too coarse for centimetres.
For finer ticks there are two paths. An analogue converter turns the interval into a voltage, with a time-to-amplitude converter, and then reads the voltage with an ADC. It reaches good resolution. A digital converter uses delay lines, time amplifiers or ring oscillators built from ordinary CMOS gates. The tick is then a gate delay, so it depends on the chip process. Sesta et al. note that an LSB of tens of picoseconds is easy in a scaled process, and that digital designs suit chips with many TDCs. The cost is power: a ring oscillator that runs all the time burns energy, which limits how many TDCs a chip can afford. Real parts combine a coarse counter for the long range with a fine stage for the small ticks.
The firmware seldom touches this layer. It sees the code and a few numbers from the datasheet: the LSB, the FSR, the conversion dead time, and whether the TDC accepts several stops per shot.
The size of one tick is the LSB (least significant bit), the smallest time step the TDC can tell apart. For us it is also the width of one histogram bin, one slot that collects all stops with the same code. Sesta et al. say the time resolution fixes the distance resolution through D = ½ · c · TOF. So the LSB converts directly to range:
1 ns → 0.14990 m · 100 ps → 1.499 cm · 38 ps → 5.7 mm
Each line is the LSB times c / 2, with c = 299,792,458 m/s. The 38 ps line is an illustrative LSB of the size that fine digital TDCs reach, worth about 6 mm. Incoronato et al. give the opposite direction: for a single-shot precision of 1 cm, the timing uncertainty must be below about 70 ps.
The other big number is the FSR (full scale range), the longest time the TDC can measure. It follows from the number of bits and the reference clock, and it caps the distance range: Dmax = ½ · c · FSR. A 100 ns FSR reaches 14.99 m. Our devices use a 100 ns window for that reason. The number of bins is FSR / LSB. At 0.5 ns that is 200 bins, which needs 8 bits (256 codes).
A stop lands anywhere inside its tick with equal chance. The rounding error then has a spread (standard deviation) of LSB / √12. Sesta et al. give this and two more terms for the TDC. They add the three in quadrature, meaning the squares add:
The whole single-shot spread adds the laser pulse and the SPAD too: σsingle-shot = √(σlaser2 + σSPAD2 + σTDC2). Sesta et al. note that the laser pulse usually dominates, often under 1 ns FWHM. So the LSB only needs to be small enough that its share becomes negligible.
σlaser = 0.6 ns, LSB = 1 ns: √(0.62 + 0.2892) = 0.666 ns (10.0 cm)
σlaser = 0.6 ns, LSB = 0.1 ns: √(0.62 + 0.0292) = 0.601 ns (9.0 cm)
Check the first line. The rounding spread is 1 / √12 = 0.289 ns. Squares: 0.36 + 0.0833 = 0.4433. Root: 0.666 ns. Times 14.99 cm per ns gives 10.0 cm. Ten times finer bins win back only 1 cm. A finer TDC costs power and silicon, so the useful bin width is about the pulse width, not much below.
3,000 shots of the same laser pulse near 40 ns, zoomed to 30 to 50 ns. Choose a bin width. The warm curve is the true pulse shape. Then switch on uneven bins and see what a bad converter does.
A model. The pulse is Gaussian with sigma 0.6 ns, centred on 40 ns, with a faint flat background (illustrative). Uneven bins have widths between 50% and 150% of the nominal width, drawn from a fixed random list.
A real TDC never has perfectly equal ticks. Sesta et al. define the DNL (differential non-linearity) of step i as how far that step is from the mean step, as a share of the mean: DNLi = (LSBi − LSB) / LSB. The INL (integral non-linearity) is the running sum of those errors, so it measures how far the whole scale has drifted. They give process variation, such as temperature gradients and doping, as the cause.
The symptom is a histogram with fake structure. A wide bin collects more stops than a narrow one, even if photons arrive evenly. Turn on Uneven bins with the 1 ns width and watch the bars wobble around the smooth curve. The measurement is to count how many stops each bin gets under flat light: the counts should be equal, and any difference shows the bin widths. The fix, as Sesta et al. say, is to measure each bin width and correct the code in post-processing. Press Calibrate widths to divide each count by its relative width.
On real hardware. An STM32 Nucleo timer cannot reach picosecond ticks, but you can feel the idea. Run a general-purpose timer at 100 MHz if your part allows it (check the clock tree in your reference manual), so one tick is 10 ns, which is 1.5 m of range. Capture a GPIO edge with input capture. Feed it a 1 kHz pulse train and plot the captured counts. Raise the timer clock and watch the spread of codes change.
Chapter 3
Learn the one random rule that governs sunlight and echo, and see how adding shots shrinks the range error
Stand under light rain and watch one paving stone. Drops land at random. You cannot say when the next one falls. But if you count for a minute you find a steady average, say 30 drops. Drops do not remember each other: one landing does not make the next one more or less likely.
Photons from the sun behave like those drops. So do echo photons. This kind of randomness has a name. A Poisson process is a stream of events where each event is independent and the average rate is fixed. The count of events in a time window then follows the Poisson distribution. If the window holds on average μ events, the chance of exactly k events is
The most useful case is k = 0. The chance that a SPAD sees at least one photon in a time step is 1 − e−λT, where λ is the photon rate and T the step. This is exactly the formula Incoronato et al. write for the chance that a photon triggers an avalanche in one step. We use it again in Chapter 4.
The pixel sees two Poisson streams added together. Sunlight has a flat rate, so its photons land evenly over the 100 ns window. The echo is also Poisson, but its rate is a bump: the laser pulse shape, centred on the delay of the target. In the model of this lesson the pulse is Gaussian with a spread of 0.6 ns.
Work the odds for one shot with the numbers from Chapter 0. The sun delivers μ = 1.0 photons per window on average. The chance of no sunlight photon is e−1.0 = 0.368. The echo delivers μ = 0.6. The chance of no echo photon is e−0.6 = 0.549, so 45.1% of shots carry at least one echo photon. In the other 54.9% the echo is simply not there, and any stop is background. Averaging does the rest.
The Poisson rule also gives the gap before the next photon. With a rate of λ photons per ns, the average gap is 1 / λ, and the chance of waiting longer than t is e−λt. It is the same “no photon” formula, now applied to a stretch of time.
Try sunlight of 2.0 photons per 100 ns window, so λ = 0.02 per ns. The average gap is 50 ns. The chance of no sun photon in the first 40 ns is e−0.8 = 0.449. So 44.9% of shots have a clear run up to 40 ns. The other 55.1% already hold a sun photon before the echo has arrived. That number drives Chapter 4.
Rates also add. Sun at 2.0 and echo at 0.6 per window give a mean of 2.6 photons per shot, but they sit differently in time. The sun is spread over 100 ns. The echo is packed into about 2 ns. Packing is why the echo shows as a peak above a flat floor. The sun brings 2.0 / 100 = 0.02 photons per 1 ns bin. The echo brings about 0.3 per bin over its two bins. The peak stands 15 times above the floor in a single shot's expectation, and many shots reveal it.
Each echo photon gives one noisy estimate of the true time. Its scatter is the single-shot spread, σsingle-shot, from Chapter 2. Sesta et al. write the spread of the average of N echo photons:
0.67 ns / √100 = 0.067 ns (1.0 cm) · 0.67 ns / √10,000 = 0.0067 ns (0.10 cm)
Take σsingle-shot = 0.67 ns, the value from Chapter 2. One hundred echo photons give 0.067 ns, which is 1.0 cm. Ten thousand give 0.0067 ns, which is 1 mm. So the estimate can be far finer than one bin, because the average of many timestamps has no rounding limit. This is why the histogram is worth building: Sesta et al. say the centroid of the histogram peak lets a system get past the TDC quantization error. Their cost note matters too: the centroid needs many measurements, so it lowers the frame rate.
The cost is easy to count. If the laser fires 1 million times a second (an illustrative rate), 1,000 shots take 1 ms. A scanner that dwells 1 ms per point needs that dwell for each pixel of each frame. That is the trade between precision and frame rate.
Every photon is timestamped here, with no dead time. Drag the number of shots. The blue band is the one-sigma range from the formula. The teal line is the centroid of the photons near the peak.
A model. Timestamps are exact, not rounded to bins, so sigma is the 0.6 ns laser pulse alone (the 0.67 ns total in the text adds a 1 ns TDC). The centroid is the mean time of photons within 1.8 ns (three sigma) of the tallest 0.5 ns bin. Sunlight and echo are mean photons per shot (illustrative).
Put the shots at 10 and the echo at 0.6. The histogram is a few scattered bars. Drag to 1,000 and a bump grows, and the teal line settles on the target. Now lift the sunlight to 4. The bump needs more shots to stand out, because the floor of random counts is higher.
Chapter 4
Work out why a single-stop TDC bends the histogram, and predict the bend with one formula
A race is timed by a photo finish camera that records only the first runner over the line. On a quiet track it works. Now a stray dog trots across the line a moment before the runners arrive. The camera records the dog. The runners are never seen, because the camera is done for this race.
A single-hit TDC works like that camera. After START it keeps only the first STOP pulse and ignores the rest until the next laser shot. Sesta et al. describe the result: ambient photons arrive earlier than the echo, mask it, and distort the histogram. They call this photon pile-up. The name is a little misleading. Photons do not pile up in time; the early ones pile their counts into the early bins and starve the late ones.
Divide the window into bins. Let μk be the average number of photons that reach the SPAD in bin k in one shot. From Chapter 3, the chance of at least one photon in bin k is 1 − e−μk. But the first-photon recorder only gets to see bin k if no earlier bin has already stopped the clock. Incoronato et al. write this as a recursion:
Unroll it. Each bin multiplies the survival by e−μ, so Sk = exp(−Σj<k μj). The survival is a staircase that only goes down. The recorded histogram is the true light profile multiplied by that falling staircase.
sunlight μ = 2.0 per window: S(40 ns) = e−2.0 × 0.4 = e−0.8 = 0.449
Work it with flat sunlight of 2.0 photons per 100 ns window. By 40 ns the sun has contributed 2.0 × 0.40 = 0.8 photons on average. Survival is e−0.8 = 0.449. So the echo at 40 ns is recorded only 45% as strongly as it arrived. At 90 ns the survival is e−1.8 = 0.165, and an echo there would keep only 17% of its strength.
First, the sun steals the stop and the echo fades. That is the case above. The background part of the histogram is no longer flat: it falls like an exponential ramp from the first bin to the last. Second, a strong echo steals from itself. If the echo brings 3 photons per shot, the first one to arrive stops the clock, and the first of three draws from the pulse shape comes earlier than a typical draw. For a Gaussian pulse, the mean of the earliest of n draws sits 0.56 σ early for n = 2, 0.85 σ for n = 3 and 1.16 σ for n = 5. With σ = 0.6 ns, n = 3 is 0.51 ns early, which is 7.6 cm of range error. The peak slides toward the laser.
So a nearby bright wall reads too short, and a far dim target vanishes at noon. Both come from one rule: the first photon wins.
Teal bars are 4,000 simulated shots recorded by a first-photon TDC. The white line is the formula: light profile times survival. The blue dashed line is the survival S(t), read on the right axis. Raise the echo and the sunlight in turn.
A model. Bins are 0.5 ns, the target is at 40 ns, the pulse sigma is 0.6 ns, and sunlight and echo are mean detected photons per shot (illustrative). The formula is the first-photon recursion of Incoronato et al. 2021 with no hold-off.
Set the echo to 0.8 and the sunlight to 0. The bars follow the line and the peak sits within one bin of 40 ns. Raise the sunlight to 4. The bars still match the line, which now carries a downhill ramp, and the echo bump is lower than the weak 0.8 would suggest. Now set the sunlight to 0 and the echo to 5. The bump leans toward its early side, and the line leans with it. The formula explains what the shots do.
You can check for pile-up with two numbers. For pure sunlight, the counts in bin k are proportional to the survival Sk. So the last bin divided by the first bin is about e−μ, where μ is the sun photons per window. If the first bin holds 100 stops and the last holds 14, then μ = −ln(0.14) = 1.97. The sun delivers about 2 photons per shot, and the recorder is working near its limit.
That is the measurement the failure mode below asks for, as a one-line firmware check. When μ is below about 0.1, the ramp is under 10% and a first-photon histogram is nearly honest. When μ is above 1, correct the histogram or change the recorder.
The symptom: a bright target reads a few centimetres short, and a faint target at noon disappears. The measurement: look at an empty part of the histogram. If it slopes down in a smooth exponential instead of lying flat, the recorder is single-hit and pile-up is active. The fix has two parts. Keep the photon count low, or record more than one photon per shot. Chapter 5 does the second. Incoronato et al. give a rule of thumb for classical single-photon timing: the effect is negligible when the count rate stays under 5% of the laser repetition rate. Check it: at μ = 0.05 photons per shot, the chance of two or more photons in one shot is only 0.12%. In sunlight that rule would throw away almost all the signal, which is why lidar needs the tools of the next chapters.
Chapter 5
Use a multi-hit TDC to see more photons, and apply the Coates formula to take the staircase out of the histogram
Back at the race track: if the camera keeps filming after the dog crosses, it sees the runners too. That is the first fix. A multi-hit TDC timestamps several photons within one laser shot. Sesta et al. list multi-hit operation and short SPAD dead time as the two key design choices against pile-up. A multi-hit TDC does not remove the blind time. Each SPAD still goes blind after a pulse, and the TDC itself needs a conversion dead time to finish one code before it takes the next. Sesta et al. write that the inverse of this dead time is the highest measurement rate.
With multi-hit timing, a photon is lost only if it lands in a blind window after another photon. The histogram is no longer a staircase that drops to a few percent. It has a much milder slope. But some bend remains, and the second fix cleans it up in software.
Chapter 4 told us what the recorder produces: the counts hk in bin k are about N · Sk · (1 − e−μk), where N is the number of shots and Sk is the survival. Now ask the reverse. Can we get μk back from the counts?
The number of shots still unstopped when bin k begins is N − Σj<k hj. Every shot that has recorded a stop is out of the race. That count is about N · Sk. Divide the bin's count by that number and the survival cancels:
This is the Coates-type correction that Incoronato et al. give for single-hit timing. Work an example with flat light. Take N = 1,000 shots and a uniform μ of 0.357 per bin. The recorder stores h0 = 300, h1 = 210, h2 = 147, falling by 30% each bin. Now correct. Bin 0: 300 / 1,000 = 0.3, and −ln(0.7) = 0.357. Bin 1: 210 / (1,000 − 300) = 0.3, so 0.357 again. Bin 2: 147 / (1,000 − 510) = 147 / 490 = 0.3, so 0.357 again. The falling counts become a flat line. The ramp is gone.
For multi-hit timing with a dead time of Δ bins, the same paper replaces the running sum with the stops in the last Δ bins only: the denominator becomes N − Σ of hj for j from k − Δ to k − 1. Now only the photons inside the blind window are removed.
Correction cannot create information. The late bins rest on only N · Sk shots. If Sk is 5%, then 1,000 shots leave 50 to estimate from, and the correction scales their noise up. Incoronato et al. state that the correction diverges when the flux is too high and no repetitions are empty. They count empty repetitions as N · exp(−Σ μ): with a 35% chance of an empty shot, 100,000 repetitions leave 35,000 empty ones, and 1,000,000 leave 350,000. More shots buy more usable late data.
Teal bars: what the recorder stored. Green line: the corrected estimate. Grey dashed line: the true light that reached the SPAD. Choose a recorder, raise the sunlight, and switch the correction on and off.
A model. Echo 1.0 photon per shot, target at 40 ns, pulse sigma 0.6 ns, bins 0.5 ns (illustrative). The correction is the Coates-type form in Incoronato et al. 2021; the multi-hit form removes only the stops inside the last 10 ns (20 bins). Where no shots remain, the estimate is capped.
Start with first-photon timing, sunlight 3, correction off. The bars slope down. Switch the correction on: the green line sits on the grey curve. Pull the shots down to 100 and the green line trembles, mostly in the late bins. Now try multi-hit: the raw bars are already close to the truth, because most photons are recorded.
The loop is short. For each bin, read the count, divide by the unstopped shots, take a logarithm, and add the count to a running sum. That is one division and one logarithm per bin. For 200 bins and 1,024 pixels, a frame needs 204,800 logarithms. At 100 frames a second that is about 20 million a second. This is heavy for a small MCU and easy for an FPGA, or for a lookup table. The sizes are illustrative.
The noise of the result is easy to estimate. A bin with h stops has a count noise near the square root of h. Late in the window h is small, and the unstopped shots in the denominator are few too, so the ratio is noisy. A practical limit is to stop correcting once the unstopped shots fall under a set level, for example 5% of N, and to flag the rest of the row as unreliable. That limit is a design choice, not a number from the sources.
On real hardware. Many shipping parts do the histogramming on-chip, so you cannot see raw stops. On a board whose timer you control (STM32 Nucleo input capture), build the first-photon histogram of a pulse train with random noise edges in software, then apply the formula above to the stored array. Check that the corrected array is flat for flat noise.
Chapter 6
Use coincidence and gating to keep the echo and throw most of the sunlight away before it reaches the histogram
In a noisy room, one voice shouting a word means little. A dozen people all shouting the same word in the same half second means something. Sun photons are the random voices. Echo photons are the chorus: they come from one laser pulse, so they arrive together.
Sesta et al. say that when background light dominates, a designer has five tools: choose a region of interest (ROI), use coincidence detection, use temporal gating, use optical methods, or apply post-processing. Chapter 5 was post-processing. This chapter covers the two tools that work inside the pixel: coincidence and gating.
Group a few SPADs into a macro-pixel, say 16 of them, all looking at the same spot. Accept an event only when at least Nt of the 16 fire within a short coincidence window τ. One sun photon fires one SPAD. It fails the test. The echo of a bright enough pulse reaches several SPADs at once, and passes.
Incoronato et al. give the chance of a false event with the binomial rule. If each SPAD has chance p of firing from the sun in the window, the chance that at least Nt of Nspad fire is
p = 1 − e−4 × 1.5/100 = 0.0582 → Nt = 1: 61.7% · 2: 23.8% · 3: 6.3% · 4: 1.2%
Work it with 16 SPADs, 4 sunlight photons per SPAD per 100 ns window, and τ = 1.5 ns. A SPAD fires in the window with chance p = 1 − e−0.06 = 0.0582. With Nt = 1, 61.7% of windows are false. Require 2 and it drops to 23.8%. Require 4 and it is 1.2%. That is a 52-fold cut. The paper's own simulation of 16 SPADs (its Fig. 10, with 10 signal and 100 noise photons per repetition on average) reports that the background falls by a factor of 10 at Nt = 2 and by 10,000 at Nt = 4.
There is a price. The echo must also fire Nt SPADs. A faint echo that reaches only two of 16 is thrown away at Nt = 4. Sesta et al. note a second gain: coincidence reduces the number of conversions, so the TDC and the histogram write fewer events.
Now work out the price. Suppose each SPAD sees 0.2 echo photons per shot, and the whole pulse falls inside the coincidence window. The chance that one SPAD fires is 1 − e−0.2 = 0.181. The chance that at least 4 of 16 fire is 32.7%, and at least 2 is 81.5%. With 0.8 echo photons per SPAD the chance of 4 of 16 is 99.7%. So a 4-of-16 rule keeps nearly every bright echo and loses two shots in three of a faint one. The right threshold depends on the scene, and the firmware can set it again for every frame.
Temporal gating turns the SPADs on only in a window around the time the echo is expected, and keeps them off at all other times. Photons outside the gate are never seen. A 20 ns gate in a 100 ns window cuts the sunlight to 20%. It also stops SPADs from going blind on early photons that do not matter. Sesta et al. describe one design (Seo et al.) that gates the SPADs around the histogram peak. Incoronato et al. call gating a convenient way to avoid timestamping useless photons.
That is a firmware task. The gate centre must come from somewhere: a coarse scan, the last frame, or a neighbouring pixel. If the target moves out of the gate, the echo disappears and a naive loop locks onto nothing. A good controller widens the gate again after a few empty frames.
1,500 shots on a 16-SPAD macro-pixel. Choose how many SPADs must fire together, and switch on a gate around the target. Watch the floor of the histogram fall and the peak stay.
A model. Sunlight is mean photons per SPAD per 100 ns window; echo per SPAD is mean photons per shot at the target (both illustrative). Coincidence window 1.5 ns; one event per shot at most, timestamped at the earliest photon of the first group. SPAD hold-off is left out. Real chips differ in how they pick the timestamp.
Start with 1 of 16 and sunlight 4: the floor is thick and the peak sits in it. Press 3 of 16. The floor drops by a factor of dozens and the peak shrinks only a little. Now switch the gate on at 20 ns. The floor outside the gate vanishes and the picture is clean.
The symptom: the point cloud has holes on dim targets in the sun, or ghost points on bright clouds. The measurement: log events per shot and the share inside the gate, per pixel. If almost no shots produce an event, the threshold is too strict. If the floor sits as high as the peak, it is too loose. The fix: pick Nt from the sunlight level, and let the firmware lower it when the scene is dim.
On real hardware. Any gate control is a register in the sensor. If you have a small ToF sensor with a configurable ranging window, such as a VL53-class part, change the window length under a bright lamp and log the valid-reading rate. The datasheet of your part names the register; the next ranging lessons cover those parts.
Chapter 7
Count the memory a histogram needs, see why it beats a stream of raw timestamps, and learn the two-stage trick
A post office sorts letters into pigeonholes, one per street. Each letter adds a tick to its street's tally. At the end of the day you read the tallies, not the letters. The histogram builder is that sorting desk. The TDC code is the street. The pigeonhole is a counter in memory, and each stop adds one to the counter at its code.
The sorting is simple. The memory is not. Sesta et al. note that building the histogram on the chip, next to the SPADs and TDCs, is the path to compact, real-time lidar with a lower data rate. They say an off-chip builder is also possible, by reading all the time-of-flight values out. The trade is memory against bandwidth.
Each pixel needs one counter per bin. The number of bins is the FSR divided by the LSB. The counter width is the bit depth. So
1,024 pixels × 400 bins × 8 bits / 8 = 409,600 bytes (400 KiB)
Work the example. A 100 ns window at 0.25 ns has 400 bins. With 8-bit counters each pixel needs 400 bytes. A chip with 1,024 pixels needs 409,600 bytes, which is 400 KiB. That is more than the whole RAM of many small microcontrollers. Check your own part's SRAM size in its datasheet. This is why the histogram usually lives in the sensor chip or an FPGA, not in the MCU.
An n-bit counter holds up to 2n − 1. With 8 bits that is 255. If a bin receives more stops than that, the counter either wraps to zero or sticks at 255. Wrapping turns the tallest bin into a short one. Sticking flattens the top of the peak. Both bend the centroid. In the worst case all N shots land in one bin, so a safe counter needs at least log2(N + 1) bits. With N = 1,000 shots that is 10 bits. Incoronato et al. also model storage saturation of the histogram memory with a binomial formula.
The firmware habit is a saturating add, so a full counter stays full:
c/* One histogram frame: PIXELS histograms of BINS counters. Illustrative sizes. */ #define PIXELS 1024 #define BINS 400 static uint8_t hist[PIXELS][BINS]; /* 409,600 bytes: 8-bit counters */ static inline void hist_add(uint16_t px, uint16_t code) { if (code >= BINS) return; /* outside the FSR: drop it */ if (hist[px][code] != 255) hist[px][code]++; /* saturate, never wrap */ }
Data flows like this: the TDC puts out a code (a uint16_t) and a pixel index. The builder adds one to hist[px][code]. After N shots the frame is read out as PIXELS × BINS bytes, and the peak finder of Chapter 8 runs on each row.
The alternative is to send every timestamp out. If each shot gives one 16-bit code per pixel, a frame costs pixels × N × 2 bytes. At 1,024 pixels and 1,000 shots that is 2,048,000 bytes, five times larger than the histogram. The histogram wins whenever N times the code size is larger than the bins times the counter size. Doubling the shots doubles the raw stream but leaves the histogram unchanged. That is the reason for building it on the chip.
Read-out time matters as well. A 10 MHz SPI link moves 1.25 million bytes a second. A 409,600-byte frame then takes 0.33 s, which limits you to three frames a second. Fast sensors use wide, fast links, or send only the window of bins around each peak. Always divide the frame size by your link rate before you choose the bit depth.
Sesta et al. describe a way to shrink the table. Split each TDC code into its high bits (MSBs) and its low bits (LSBs). Build two histograms at once: a coarse one over the MSBs with 2Nm bins, and a fine one over the LSBs with 2Nl bins. Both fold the whole range into their bins. Find the peak bin of each, and put the two together to get the first estimate of the time. They call this the double-stage histogram. Memory is 2Nm + 2Nl instead of 2Nm+Nl. A 9-bit code of 512 bins becomes 16 + 32 = 48 bins.
Two costs follow. Sunlight from the whole range folds into few bins, so the noise floor rises. And if the echo straddles two coarse bins, the centroid can be wrong by the span of the fine histogram, 2Nl bins. Sesta et al. say the frame rate falls only by a factor of 2 here. A different design, the partial histogram, scans the range in slices. With 2Nf bins in the full range and 2Np in a slice it needs 2Nf−Np slices, so the frame rate falls by that factor. Peak detection first, then a small histogram around the peak, avoids the long scan. One design they describe ends with a 16-bin window of 5-bit counters.
Bars show bytes per frame on a log scale. Choose the bin width, the counter width, the number of pixels and the number of shots. Compare the full histogram, the two-stage one and the raw stream.
Arithmetic, not a measurement. The window is 100 ns (FSR). The raw stream assumes one 16-bit timestamp per pixel per shot. The two-stage histogram splits the code bits as evenly as it can, folds the full range into both histograms, and ignores the higher noise floor and the second acquisition. Counters are packed to the bit.
Set 0.25 ns, 8 bits, 1,024 pixels and 1,000 shots. The full histogram is 400 KiB. Slide the shots to 10,000 and the status goes red: 8 bits cannot hold 10,000 stops in one bin. Add bits and the memory grows, so shorter shot counts with more passes may be a better trade.
The symptom: a bright, near target reads a few centimetres off while a dim one is fine. The measurement: dump one pixel's raw row and look for a flat top at 255 or 65,535. The fix: widen the counters, cap the shots, or saturate and flag the pixel.
On real hardware. On an STM32 Nucleo, put a byte array like the one above in SRAM and fill it from a timer-capture interrupt. Watch the map file from the toolchain lesson to see the array's size in .bss. Change BINS and read the new number.
Chapter 8
Turn a row of counters into one distance, and measure how each estimator behaves as the sun rises
You look for the top of a hill through fog. You can see the height of the ground at every step, but each reading is noisy. You can walk to the step with the highest reading and call that the top. Or you can average the positions of all the high steps, giving more weight to the higher ones. The second way is steadier and can land between two steps.
The histogram is that hill. The firmware has to find the top and report one time. Sesta et al. describe two stages: peak detection finds where the echo is, and a centroid refines it. The centroid of a window of bins is the weighted average of their times, where each weight is the bin's count:
counts 5, 20, 60, 100, 55, 18, 4 at 37.5 ... 43.5 ns: 10,599 / 262 = 40.454 ns (6.064 m)
Work a small case with 1 ns bins whose centres are 37.5, 38.5, …, 43.5 ns, and counts 5, 20, 60, 100, 55, 18, 4. The counts add to 262. Each count times its time: 187.5, 770, 2,370, 4,050, 2,282.5, 765, 174. These add to 10,599. Divide: 40.454 ns. The tallest bin alone says 40.5 ns. The centroid says 40.454, which is 0.046 ns finer than the bin could show, and it is a distance of 6.064 m.
Before the centroid, the firmware must decide where the peak is and whether there is one. The simplest rule is a threshold: a peak exists only if the tallest bin is well above the floor. A typical choice is the floor plus a few times the noise of the floor, which for counts is the square root of the floor level. If no bin passes, the pixel reports no return. That is better than reporting a random bin as a range.
Sesta et al. describe smarter schemes built into the sensor. One finds the peak in a few cheap passes over coarse sub-histograms, then builds a small fine histogram of 16 bins around it. Another applies a matching filter to the fine histogram to rebuild a peak that fell on a bin border. The firmware idea is the same in all of them: find the peak cheaply, then spend the memory and the maths only near it.
The centroid is a weighted average of everything in its window, including background. A flat floor of sunlight pulls the average toward the middle of the window. If the window is centred on the peak, the pull cancels. If the peak sits near the window's edge, the estimate drifts toward the centre. The usual fix is to subtract a floor level first. A typical floor estimate is the median of the whole histogram, since most bins hold only background.
Work a small case of the pull. Take the six bins 38.5 to 43.5 ns with counts 20, 60, 100, 55, 18, 4. Their centroid is 10,411.5 / 257 = 40.512 ns. Now use a window of nine bins, 38.5 to 46.5 ns, that sits too far right, and add a floor of 3 counts in every bin. The floor adds 27 counts at an average time of 42.5 ns. The centroid becomes 11,559 / 284 = 40.701 ns. It moved 0.189 ns, which is 2.8 cm, only because of sunlight. Subtracting the floor first restores 40.512 ns.
A second trap is the pile-up from Chapter 4. A first-photon histogram has a downhill ramp, so the centroid over a window leans toward the early side. Correct the histogram first (Chapter 5) or use a multi-hit recorder, then find the peak. Sesta et al. also point to post-processing with a matching filter on the fine histogram, as in the partial-histogram work of Zhang et al., to rebuild the peak position when it falls at the border of a bin.
There is also a cost, repeated from Chapter 3: the centroid needs many photons, so more shots, so a slower frame rate. The device runs 120 repeat trials with the same settings and measures how far each estimator lands from the truth. Every bar is the root-mean-square error in centimetres.
Each bar is the root-mean-square range error of one estimator over 120 trials. A tick marks its bias (the average error). Change the bin width, the sunlight and the shots per trial, and choose the recorder.
A model. Echo 0.8 photon per shot, target at 40 ns, pulse sigma 0.6 ns (illustrative). The centroid window is 1.8 ns (three sigma) either side of the tallest bin. The floor is the median bin count. Trials use a fixed random seed, so the numbers repeat.
Start with 1 ns bins, all photons, sunlight 2. The tallest bin is off by about 7 cm, which is the rounding of half a bin, while the centroids sit near 1 cm. Switch to first-photon recording at sunlight 6: the early ramp is now taller than the echo, all three estimators lock onto it, and the error jumps to metres. Floor subtraction cannot rescue that. It is the cue to correct the histogram first.
The symptom: a flat wall reads with ripples of one bin width as you scan across it. The measurement: log the raw argmax bin per point. A staircase of steps one bin wide shows the tallest-bin estimator. The fix: use a centroid, and subtract the floor.
Chapter 9
Keep the numbers, the checks, the code and the sources for the next time a histogram looks wrong
A SPAD turns one photon into one pulse and then goes blind for its hold-off time. A TDC turns the pulse time into a code, and the size of one code step sets the range step. Sunlight and echo are Poisson streams. The histogram adds up many shots so that the echo stands out. A first-photon recorder lets early sunlight steal the stop, which bends the histogram into a ramp and slides strong peaks early. Multi-hit recording, the Coates formula, coincidence and gating each undo part of that. Firmware sizes the counters and finds the peak.
| Term | What it is | Number or formula | Source |
|---|---|---|---|
| Range from time | Half the round trip times the speed of light | D = ½ · c · TOF; 1 ns = 14.99 cm | Sesta et al. eq. 1 |
| Hold-off | SPAD blind time after a pulse | λdet = λ / (1 + λ · THO); 5 ns and 10 ns in the paper's runs | Incoronato et al. |
| Detected rate | Photons that make a pulse | Φin · FF · PDP | Incoronato et al. |
| LSB | One TDC step, one bin | 38 ps is about 6 mm; 70 ps is about 1 cm | Sesta et al.; Incoronato et al. |
| Rounding error | Spread from rounding to the tick | σq = LSB / √12 | Sesta et al. |
| DNL, INL | Step error, and its running sum | DNLi = (LSBi − LSB) / LSB | Sesta et al. |
| FSR | Longest time the TDC can read | 100 ns reaches 14.99 m; bins = FSR / LSB | Sesta et al. |
| Averaging | Spread of the mean of N echo photons | σTOF = σsingle-shot / √N | Sesta et al. eq. 7 |
| First-photon histogram | Light profile times survival | P(DETk) = (1 − e−μk) · (1 − Σj<k P(DETj)) | Incoronato et al. |
| Low-flux rule | Pile-up is negligible below this rate | Count rate under 5% of laser rate | Incoronato et al. |
| Coates correction | Undoes the staircase | μ̂k = −ln(1 − hk / (N − Σj<k hj)) | Incoronato et al. |
| Coincidence | At least Nt of N SPADs together | Binomial sum; 16 SPADs: 10× at Nt = 2, 10,000× at 4 (their Fig. 10) | Incoronato et al. |
| Histogram memory | Counters for a frame | pixels × bins × bits / 8; two-stage: 2Nm + 2Nl bins | Arithmetic; Sesta et al. |
This is the whole receive path in plain C, from the TDC code to a range. It builds a saturating histogram, corrects it for first-photon recording, and finds the peak with a floor-subtracted centroid. The sizes are illustrative.
c/* fw-rng-02: histogram, Coates correction, centroid. Compiles with any C99 compiler. */ #include <stdint.h> #include <math.h> #define BINS 200 /* 100 ns window / 0.5 ns LSB */ #define LSB_NS 0.5f #define C_M_PER_NS 0.299792458f /* metres per ns, one way */ typedef struct { uint16_t h[BINS]; uint32_t shots; } hist_t; /* One stop from the TDC. code = 0..BINS-1. Saturate, never wrap. */ static inline void hist_add(hist_t *H, uint16_t code) { if (code < BINS && H->h[code] != UINT16_MAX) H->h[code]++; } /* Coates-type correction for a first-photon recorder: mu[k] = -ln(1 - h[k] / (N - sum of earlier h)). */ void coates_first(const hist_t *H, float mu[BINS]) { uint32_t gone = 0; for (int k = 0; k < BINS; k++) { float den = (float)H->shots - (float)gone; float r = den > 0 ? H->h[k] / den : 1.0f; mu[k] = r >= 0.999f ? 7.0f : -logf(1.0f - r); /* cap where no shots remain */ gone += H->h[k]; } } /* Peak time in ns: tallest bin, then a centroid of +-win_ns around it with the median floor removed. */ float peak_ns(const float *v, float floor_level, float win_ns) { int top = 0; for (int k = 1; k < BINS; k++) if (v[k] > v[top]) top = k; float tc = (top + 0.5f) * LSB_NS, s = 0, w = 0; for (int k = 0; k < BINS; k++) { float t = (k + 0.5f) * LSB_NS; if (fabsf(t - tc) <= win_ns) { float c = fmaxf(0.0f, v[k] - floor_level); s += c * t; w += c; } } return w > 0 ? s / w : tc; } float range_m(float t_ns, float t_offset_ns) { return C_M_PER_NS * (t_ns - t_offset_ns) * 0.5f; }
t_offset_ns is the fixed delay between the laser trigger and the true emission, plus cable and electronics delays. Measure it once against a target at a known distance. Sesta et al. note that a fixed offset shifts every distance and is easy to remove.
Before this lesson: time-of-flight basics built the idea of a light clock, and quantization noise explains the LSB / √12 rule on a general converter. After it: firing the laser on time covers the scan and the pulse timing that start the TDC. From histograms to point packets takes the peak of this lesson and packs range, intensity and a timestamp into the network packet. Timing and sync for lidar puts a global time on each point. Small ranging sensors shows these ideas inside a VL53-class part.
For the firmware habits (interrupts, timers, DMA into a buffer) see timers and sampling and hardware interfacing. For what lidar models do downstream, see lidar sensors and ICP, point clouds and lidar-inertial factor graphs.
Every toy number (photons per shot, pulse width, hold-off in the devices, counter sizes) is labelled illustrative where it appears. The devices are models in the page, not measurements from real silicon.
Now press Present or Teach and explain, from memory, why a bright day bends the peak, and which of the five fixes you would reach for first. Then go back to the hero and fire 4,000 shots with the sunlight at 6.