A spinning lidar fires its laser about twenty thousand times a second. Each shot that is late by a few microseconds slides a dot sideways by centimetres at 100 m.
Learn how firmware decides when the laser fires, why the encoder beats the clock, how timing errors turn into angle errors, and how interlocks keep the beam safe when the motor does not.
Press Scan a pass for each firing scheme and watch where the dots land. Add jitter and see which scheme survives. Then we build, piece by piece, the motor, the encoder, the timer and the safety chain underneath.
You need a feel for what a timer and an interrupt are and a little C. We build the rest from zero.
Built from primary sources: the Ouster sensor documentation, US federal rule 21 CFR 1040.10, and Cortex-M and STM32 timer documentation. Every device on this page is a model in your browser, not real silicon, and each chapter names a board and a measurement to repeat. The full source list is in the Field Guide. It follows SPAD, TDC and the Histogram.
Toy model at 10 Hz (3,600 degrees per second). Columns are 0.176 degrees apart, as in the 2048-column mode of the Ouster data format (44 of its 90,112 encoder counts). Jitter is drawn uniformly within the slider value. Motor speed ripple is illustrative: 0.2 percent at 40 Hz. Each row is one pass over the same 12 columns. Offsets are shown as a share of one column, so the picture does not change with range; only the read-out in millimetres does.
Chapter 0
See what one late shot does to a dot on a wall, and why a safe lidar needs more than a fast one
A delivery robot rolls down a pavement at night. On its roof sits a small drum that spins ten times every second. Inside the drum a laser flashes thousands of times a second, and a sensor listens for each echo. From the echoes the robot builds a picture of the street: kerbs, parked cars, a person with a pram.
That drum is a spinning lidar. The word lidar means “light detection and ranging”: measure how long a flash of light takes to bounce back, and you know how far away the thing is. Our time of flight lesson builds that clock. This lesson asks a different question. When, exactly, does the laser fire?
The answer is a job for firmware: the small program that lives inside the chip on the board and runs the hardware. The firmware does not shoot the laser at random. It shoots once for every small step of rotation, so that the dots on a wall sit in neat, evenly spaced columns.
Take a lidar in the style of the Ouster data format, which we use as our running example. It can cut each turn into 2,048 columns and it turns ten times a second. That makes 2,048 × 10 = 20,480 columns every second. One column lasts 1 ÷ 20,480 s = 48.83 µs. A microsecond (µs) is one millionth of a second.
The turn is 360 degrees, so each column is 360 ÷ 2,048 = 0.1758° wide. That sounds tiny. But angles grow with distance. At 100 m, 0.1758° is a sideways step of 100 m × 0.1758 × π/180, which is about 30.7 cm. Hold that number: it is the spacing between neighbouring dots on a wall 100 m away.
The drum turns at 3,600 degrees per second (10 turns × 360°). If a shot fires 1 µs late, the drum has already turned 3,600 × 0.000001 = 0.0036° further. At 100 m that moves the dot sideways by about 6.3 mm.
6 mm of 30.7 cm is only 2 percent of a column. So one microsecond is harmless. But firmware rarely runs late by exactly one microsecond. An interrupt (a request that makes the chip pause its work and run a short handler) may wait behind another handler for ten microseconds or more. Ten microseconds is 6.3 cm at 100 m, a fifth of a whole column. A wall stops looking like a wall.
The picture at the top of this page lets you try it. Switch between the three firing schemes and push the jitter up. The rest of this lesson builds, piece by piece, why the third scheme holds still.
The warm arm is the laser beam, seen from above. Each tick on the ring is one shot. The arm turns in slow motion here. Choose how many columns each turn holds and how fast the drum spins.
Turn rates of 10 and 20 Hz and 512, 1,024 or 2,048 columns are the lidar modes named in the Ouster sensor documentation (for example 2048x10 and 1024x20). The ring draws at most 128 ticks so it stays legible; the read-out counts all of them. The animation is slowed down; the real drum turns 10 to 20 times each second.
Look at the read-out. Two different modes, 2048 columns at 10 Hz and 1024 columns at 20 Hz, both give 20,480 columns a second and a 48.83 µs gap. They differ in how wide a column is. Firmware sees one number: the gap between shots. It must hit that gap every time.
Follow one shot from start to finish. The steps below are the parts of the lidar, and each later chapter opens one of them.
Each arrow between those steps can add a delay. The skill is to know which delays matter, how big they are and which ones you can remove.
A late shot can be wrong in two separate ways, and mixing them up is the commonest mistake. If the firing command is late, the beam points at the wrong angle. That is an angle error. If the laser pulse itself leaves late relative to the clock that times the echo, the measured distance is wrong. That is a range error. Chapter 4 handles the first and Chapter 6 the second.
There is a third reason to care. A laser beam that sweeps past an eye in a millisecond is one thing. The same beam parked on one spot because the motor stopped is another. Lidars are sold as Class 1 products, which means the light that can reach a person stays below a safe limit in normal use. The firmware is part of what keeps that promise. Chapters 7 to 9 show how it does that, and how you test it.
The lesson goes in this order:
On real hardwareTake any STM32 Nucleo board with a spare timer pin. Toggle the pin in a loop, then from a timer interrupt. Watch the pin on a scope or a cheap logic analyser. The loop shows a steady edge; the interrupt edge shifts when you add other interrupts. That shift is the whole lesson in one picture.
Chapter 1
Compare a spinning drum with a swinging mirror and see why the pattern decides how you must fire
Imagine painting a fence with a spray can. You can walk along the fence at a steady pace, pressing the nozzle every second. The dots land evenly. Now swing the can left and right like a pendulum instead. At the ends of each swing your hand slows, stops and turns round. If you still press every second, the dots pile up near the ends and spread out in the middle.
A lidar faces the same choice. A scan pattern is the path the beam takes across the world, and the list of angles where it fires. Three families cover most products.
A spinning lidar puts a stack of lasers and detectors on a drum. A motor turns the drum at a steady rate. Each laser draws one horizontal ring around the sensor, so a stack of lasers draws a stack of rings. The Ouster sensor documentation describes this layout: each frame is built from 512, 1,024 or 2,048 measurement blocks, which this lesson calls columns. A column is one vertical slice, one shot from every laser at the same turn angle.
A mirror scanner keeps the laser still and moves a small mirror. A MEMS mirror (a mirror etched in silicon, about the size of a grain of rice) tilts back and forth, often at its natural resonant frequency, because that costs the least power. The beam sweeps through an angle and returns.
A flash lidar does not scan. It lights the whole scene at once and a sensor array reads many pixels together. The firing problem then shrinks to one flash on time. We set it aside here, because the interesting timing lives in the other two.
Whatever the hardware, the firmware needs one answer for every shot: at what angle should shot number k fire? For a spinning drum the table is trivial. Column k fires at k × 360° ÷ N. With N = 2,048 columns that is k × 0.1758°. The Ouster data format counts the same turn in encoder counts, from 0 to 90,111, and adds 44 counts per column in the 2,048-column mode. 44 × 360° ÷ 90,112 = 0.1758°, which matches.
360° ÷ 90,112 counts = 0.003995° per count → 44 counts = 0.1758° per column
Also notice what the data format lets a user do: it allows a custom azimuth window (azimuth is the angle around the vertical axis), so the lidar only reports and, if configured, fires over part of the turn. Turning the laser off outside a window is a pattern too. We will meet it again as a safety tool.
For a drum at steady speed, angle grows in a straight line with time, so “fire every 48.83 µs” and “fire every 0.1758°” mean the same thing. A mirror breaks that link. Its angle follows a sine wave:
The speed of the beam is the slope of that curve: A × 2πf × cos(2πft). It is fastest in the middle, where cos is 1, and zero at the ends, where the mirror turns round. If you fire at a fixed time step Δt, the gap between neighbouring dots is speed × Δt. So the gaps shrink with cos, and the dots crowd together near the ends.
Worked example. Use A = 30°, f = 100 Hz and Δt = 20 µs (all made up). The peak speed is 30 × 2π × 100 = 18,850°/s. The central gap is 18,850 × 0.00002 = 0.377°. At the point where sin = 0.8 (24° out), cos = 0.6, so the gap is 0.377 × 0.6 = 0.226°. At sin = 0.99 (29.7° out), cos = 0.141, so the gap is only 0.053°, seven times tighter than the middle. Try it below.
One half-sweep of a mirror, left to right. Dots are shots. Bars count shots in each 5° band. Choose the rule that decides when to fire, then change how many shots you want in the sweep.
Illustrative mirror: amplitude 30°, sine motion. A half-sweep takes 5 ms at 100 Hz, so 250 shots is a 20 µs step. Counts are exact for the rule you pick; the bands are 5° wide and the outermost bands are the two at each end.
With the clock rule, the end bands hold several times more shots than the middle ones, while the middle is thin. Wasted laser pulses, and a blurry point cloud in the middle where you want it sharp. With the angle rule every band holds the same number. The price is that the firmware must know the angle at each instant. That is Chapter 2.
A drum at perfect steady speed needs no angle sensing: the clock is enough. But no motor turns at perfect steady speed. Cogging (small pulls as magnets pass the coils), belt wobble and load changes make the speed ripple. A clock-driven scheme assumes constant speed, so the ripple becomes angle error. The drum is not safe from the mirror’s problem; it just has a gentler version of it. Chapter 3 measures it.
On real hardwareOn an STM32 Nucleo, drive a hobby servo with a PWM timer, command it in a sine sweep, and log the commanded angle from a timer interrupt every 100 µs. Plot the histogram of angles. It should match the crowding shape you see above. Then log the angle only when it crosses each 1° step, and the histogram flattens.
Chapter 2
Build a hardware angle counter from two square waves and see what its counts can and cannot tell you
You sit in a car with your eyes closed. The driver says nothing. How fast are you going? You count the bumps from the lane markers under the wheels. Bumps per second, times the gap between markers, is your speed. You never opened your eyes.
A lidar chip does the same with the drum. It cannot see the drum. A small disc on the shaft carries fine marks, and a light sensor counts them as they pass. That is an encoder: a part that turns shaft rotation into electrical pulses.
One track of marks tells you how far the shaft moved, but not which way. So encoders carry two tracks, A and B, offset by a quarter of a mark. This is quadrature output. Turning forward, A rises first and B follows. Turning backward, B rises first.
Read A and B together as a two-bit number and it walks through four states in a loop: 00, 10, 11, 01. Each step is one count. If the number moves one way round the loop, add one. If it moves the other way, subtract one. Counting every edge of both signals gives four counts per mark, called x4 decoding.
The Ouster data format reports a turn as 90,112 raw encoder counts, from 0 to 90,111. We use the same scale. One count is 360° ÷ 90,112 = 0.003995°. If it came from x4 decoding, the disc would hold 22,528 marks. The documentation I read does not say how the disc is built, so treat that as a plausible picture, not a fact about any product.
At 10 turns a second the counts arrive 90,112 × 10 = 901,120 times a second, one every 1.110 µs. A processor that took an interrupt for every count would spend almost all its time answering them. So the counting goes into hardware.
Many microcontrollers have a general-purpose timer (a counter driven by a clock) with an encoder interface mode. In this mode the timer stops counting clock ticks and counts the edges on two input pins instead. On the STM32F407 (a Cortex-M4 part), TIM2 is a 32-bit timer you can wire this way. The reference manual RM0090 describes the mode in the general-purpose timer chapter. The counter register TIM2->CNT now is the angle. The processor reads it when it wants, at no cost per edge.
c/* TIM2 as a 32-bit encoder counter on PA0 (TI1) and PA1 (TI2), STM32F407. Register names follow RM0090; check them against your own part. */ RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN; /* clock the pins first (the blink that did not blink) */ RCC->APB1ENR |= RCC_APB1ENR_TIM2EN; /* clock the timer */ GPIOA->MODER |= (2u << 0) | (2u << 2); /* PA0, PA1: alternate function */ GPIOA->AFR[0] |= (1u << 0) | (1u << 4); /* AF1 = TIM2 */ TIM2->CCMR1 = (1u << 0) | (1u << 8); /* CC1S=01, CC2S=01: inputs are TI1 and TI2 */ TIM2->CCMR1 |= (0xFu << 4) | (0xFu << 12); /* IC1F, IC2F: strongest input filter, rejects glitches */ TIM2->SMCR = 3u; /* SMS=011: count on both edges of both inputs (x4) */ TIM2->ARR = 90112u - 1u; /* wrap once per turn: CNT is 0..90111 */ TIM2->CCER = TIM_CCER_CC1E | TIM_CCER_CC2E; TIM2->CR1 |= TIM_CR1_CEN; uint32_t angle_counts = TIM2->CNT; /* no interrupt per edge */
Two details deserve a sentence each. First, the input filter ignores very short pulses, so electrical noise does not add false counts. Second, the counter only knows change. It starts at zero wherever the shaft happens to be. Real encoders add a third index pulse, once per turn, that resets the counter, so a lost count cannot grow into a lasting error.
Here is why the index pulse matters, with numbers. Suppose electrical noise eats one count in every 10 turns. After 1,000 turns (100 s at 10 Hz) the counter has lost 100 counts. That is 100 × 0.003995° = 0.40°, or 2.3 columns, and every shot is now aimed 2.3 columns away from where the optics think it points. With an index pulse that resets the counter once per turn, the error never grows past the loss in one turn: a tenth of a count.
Speed is counts per second. The simplest method reads the counter every fixed window and subtracts. At 10 Hz, a 1 ms window sees 901.12 counts. But the counter only gives whole numbers, so the answer can be off by one count: 1 ÷ 901 = 0.11 percent. Shorten the window to 0.1 ms and you see about 90 counts, so one count is 1.1 percent. Slow the drum to 2 Hz and the same 1 ms window sees 180 counts, so the error is 0.55 percent.
That is why a speed loop (the control code that keeps the motor at its target rate) likes long windows, while a firing schedule likes short ones. Chapter 3 shows how to get both. The motor control lesson covers the loop that holds the speed.
The top trace is channel A, the lower one channel B, over a 40 µs window. Each coloured edge is one count. Spin the drum faster or slower, flip its direction, and change how long you count before you estimate the speed.
Model only. The count scale is the Ouster data format’s 90,112 counts per turn, treated as x4 decoding of a 22,528-mark disc (illustrative). The waveform is ideal; a real one has noise, which is what the input filter in the code removes.
Look at the 0.1 ms window at 10 Hz: the estimate wobbles by more than one percent just from rounding. The drum did not change speed; the instrument did. Keep this in mind whenever a speed reading looks noisy.
On real hardwareOn an STM32 Nucleo, wire a small quadrature encoder (a hobby rotary encoder works) to the two TIM2 pins and run the code above. Turn it by hand through 20 full turns and return to your start mark. Print TIM2->CNT. A clean setup returns to the same value; a noisy one drifts, and a longer input filter fixes it.
Chapter 3
Compare firing on a timetable with firing on a position, and measure how far each drifts in one turn
A conductor raises her baton. One choir sings by a metronome that ticks at 120 beats a minute. Another choir follows the lead singer, who speeds up and slows down as she feels the song. If the lead singer holds a steady tempo, both choirs sound the same. If she does not, the metronome choir drifts away, bar by bar, until it sings in the wrong place.
Firing a laser has the same two choices. A time-based schedule asks a timer to fire every 48.83 µs and trusts the drum to keep pace. An angle-based schedule asks the encoder where the drum is and fires when it reaches the next planned angle. The drum is the lead singer.
Take a timer clocked at 84 MHz (the clock that feeds the timers on a Cortex-M4 part such as the STM32F407 when the system runs at 168 MHz). One timer tick lasts 11.9 ns. The ideal gap between columns is 1 ÷ 20,480 s = 48.828125 µs. In ticks that is 48.828125 × 84 = 4,101.5625.
The timer reload register holds a whole number. You write 4,102, which is 0.4375 ticks too long. That looks harmless. Add it up over one turn of 2,048 columns: 2,048 × 0.4375 = 896 ticks = 10.7 µs. At 10 Hz the drum turns 0.038° in that time, a fifth of a column. The schedule slowly slides away from the drum, even if the drum is perfect.
Now the drum. Its speed is never exactly 10.000 Hz. Say it runs 0.1 percent fast. Each column then arrives 0.1 percent too early compared with the timer, and over one turn the shot angles slide by 0.1 percent of 360°, which is 0.36°: two whole columns. A time-based schedule must therefore be re-aligned often, normally once per turn from the index pulse, or continuously by adjusting the reload value from the measured speed. Both are extra firmware to write and to test.
The angle-based schedule needs no such repair. It keeps a table of targets in encoder counts. Column k fires at count 44 k plus a fixed calibration offset, wrapped at 90,112. When the counter reaches the target, the laser fires. If the drum is 0.1 percent fast, the target counts simply arrive 0.1 percent sooner, and the shots arrive with them. The shot is tied to the position, not to a guess about speed.
c/* The schedule is a table of angles, in encoder counts, not times. */ #define COUNTS_PER_TURN 90112u #define COLS_PER_TURN 2048u #define COL_COUNTS (COUNTS_PER_TURN / COLS_PER_TURN) /* 44 */ extern uint32_t cal_offset; /* counts from encoder zero to the optical window, set once */ static inline uint32_t target_for_column(uint32_t k) { return (k * COL_COUNTS + cal_offset) % COUNTS_PER_TURN; }
There is a cost. The target arrives in counts, and one count lasts 1.110 µs at 10 Hz. So an angle schedule can only place a shot to the nearest count: at most half a count, or 0.002°, which is 3.5 mm at 100 m. That is a hard floor, but a small and honest one, and it does not grow with time.
When the encoder is coarser than the angle you need, firmware adds interpolation: it reads the last count and the time since, multiplies by the measured speed, and estimates an angle between counts. That brings back a small dependence on speed, but only across one count, not one turn. Our 44 counts per column leave no need for it.
Some designs keep a timer in charge of the spacing but let the encoder correct it. After each column the firmware compares where the drum is with where it should be. The difference is a phase error in encoder counts. One count lasts 1.110 µs, which is 93.2 timer ticks at 84 MHz, so a phase error of 2 counts means the reload value should move by about 186 ticks. A small gain on that correction pulls the timer back in step, a little at a time. It is a phase-locked loop: a feedback loop that locks a local clock to an outside signal. It works, but it adds a tuning job and a way to go wrong. A table of angles needs none of that.
The device below runs one full turn of 2,048 columns. The warm line shows the angle error of the clock schedule at every column, in columns of error. The blue line shows the angle schedule. Slide the drum’s speed away from nominal and add some ripple. Watch which line stays flat.
Horizontal: the 2,048 columns of one turn. Vertical: how far each shot lands from its ideal angle, measured in columns. Warm is the clock schedule. Blue is the angle schedule.
Model: both schedules start aligned at column 0 at 10 Hz. Clock error at column k is 3,600°/s × (offset × t + ripple term), with t = k × 48.83 µs; the ripple term is a sine of 40 Hz. Angle error is at most half an encoder count (0.002°) from rounding. Ripple and offsets are illustrative; the 40 Hz is a made-up cogging frequency.
With a 0.1 percent offset, the clock line climbs in a straight ramp: about two columns late by the end of the turn. The ripple adds small waves to the ramp. The blue line sits on zero. This is why the hero’s first scheme looks wavy while the other two stay tidy.
One more fair point: a clock schedule is not useless. When the drum is held by a good speed loop and re-aligned at the index, the drift stays small, and a clock needs no table. Many sensors mix the two: the encoder sets the phase once per turn or per column, and a timer fills in the spacing. What matters is that something ties the shots to the shaft.
On real hardwareOn an STM32 Nucleo, spin any small motor with an encoder at a steady PWM. Toggle a pin once every 48.83 µs from a timer, and toggle a second pin each time the encoder count passes a multiple of 44. Trigger a scope on the second pin and watch the first. Over many turns the clock pin slides against the encoder pin; the encoder pin does not.
Chapter 4
Turn a few microseconds of interrupt delay into millimetres on a wall, and find out where the delay comes from
A train is due at 08:00. If it always arrives at 08:03, you can plan for it: leave three minutes later. If it arrives anywhere between 08:00 and 08:09, you cannot plan. The first case is a delay. The second is jitter: the shot-to-shot variation in the delay.
Firmware people say latency for the time from an event (the encoder reaches the target count) to the moment the code that answers it runs. A fixed latency is a calibration constant. Jitter is the part that changes from shot to shot, and no constant can remove it.
The drum turns at a steady rate. If the firing command comes δt late, the drum has turned further by that time, so the beam points at a wrong angle.
10 Hz, δt = 8 µs: δθ = 360 × 10 × 0.000008 = 0.0288°; at 100 m, δx = 100 × 0.0288 × π/180 = 50.3 mm
50.3 mm is 16 percent of the 306.8 mm column spacing. Double the turn rate and the same 8 µs costs twice as much. Double the range and it costs twice as much again. Both are linear, so you can do this sum in your head: 1 µs at 10 Hz is 6.3 mm per 100 m.
Now scale it. Run the same drum at 20 Hz and look at a wall 200 m away. The same 8 µs of jitter gives δθ = 360 × 20 × 0.000008 = 0.0576°, and δx = 200 × 0.0576 × π/180 = 201 mm. A column at that range is 614 mm wide, so the dot has moved a third of the way to its neighbour. The far, fast case is four times worse than the near, slow one, with the code unchanged.
Take the angle schedule of Chapter 3 and fire from an interrupt service routine (ISR): a function the chip runs when a hardware event, such as a timer compare, asks for attention. What can delay it?
None of these is wrong by itself. Each one is fine for a printf or a button. They become faults only because one shot every 48.83 µs must not wait for any of them.
Each bar counts how many of 4,000 shots arrived that many microseconds late. Switch sources on and off. The lower scale turns microseconds into millimetres on a wall at the range you choose.
Illustrative sources with made-up odds: the UART handler collides with 20% of shots, the critical section with 15%, the RTOS tick with 1.2% (a 12 µs handler once per millisecond), memory stalls with every shot. Each delay is uniform up to its limit. The fixed 71 ns interrupt entry is left out because it can be calibrated.
Turn on the UART handler and the histogram grows a long tail. Add the RTOS tick and the tail grows again, rare but tall in millimetres. Notice that the average delay is small. The tail is what blurs a wall, because the worst shots land far from where they belong.
Symptom. A flat wall looks thick in the point cloud. Edges look furry. Two passes over the same wall do not line up.
Measurement. Set a spare pin high on entry to the firing handler and low on exit. Put the trigger edge from the timer on one scope channel and the laser trigger on another. Use infinite persistence (the screen keeps every trace). The spread of the laser edge against the timer edge is the jitter. Convert with the formula above.
Fix. Do not make the handler faster. Remove what it waits for. Give the firing handler the highest interrupt priority. Keep other handlers short. Replace long critical sections with lock-free code. Better still, take the processor out of the loop: Chapter 5 lets the timer hardware fire the laser.
On real hardwareOn an STM32 Nucleo, make a timer interrupt toggle a pin every 48.83 µs, then also run a UART transmit at 115,200 baud in a loop. Look at the toggle pin on a scope set to infinite persistence. The edge smears by the length of the UART handler. Raise the timer interrupt priority and the smear shrinks.
Chapter 5
Move the moment of firing out of the processor and into a timer comparator, then guard the one deadline that is left
A restaurant has a bell for the kitchen. In one design, a waiter stands by the clock and rings the bell when the soup is ready. If the waiter is carrying plates, the bell rings late. In the other design, a mechanical egg timer rings the bell itself. The waiter's only job is to set the timer for the next dish, any time before the current one finishes.
That second design is the idea of this chapter. In Chapter 4 the processor fired the laser, so every delay of the processor became a delay of the shot. Here the hardware fires it, and the processor only prepares the next shot.
Every general-purpose timer has channels. A channel has a capture/compare register, on STM32 parts called CCRx. In output compare mode a small comparator circuit looks at the counter and at CCRx on every timer clock. When the two numbers are equal, the circuit changes the channel’s output pin, with no instruction run by the core.
In Chapter 2 the counter CNT counts encoder edges. So CCRx is not a time. It is an angle in encoder counts. Put the target count for the next column in CCR3 and the pin fires exactly when the drum reaches that angle. The comparator checks once per timer clock, so the pin changes within about one clock after the counter reaches the value. At 84 MHz that is about 12 ns, which is 0.00004° at 10 Hz and under 0.1 mm at 100 m. The remaining error is the count itself: half a count, 3.5 mm.
The output pin goes to a laser driver, a small circuit that turns a logic edge into a short, strong pulse of current through the laser diode. The processor does not shape the pulse. A microcontroller timer cannot make a pulse a few nanoseconds wide. It makes the trigger edge; the driver makes the light. Chapter 6 comes back to the pulse.
The comparator fires only once per target. After the shot, someone must write the next target into CCR3. That someone is a small handler, triggered by the same compare event. It has to finish before the counter reaches the next target, which is 44 counts, or 48.83 µs at 10 Hz, away.
That window is the slack: the time you could lose without a failure. Work it out for our handler. Writing a register, clearing a flag and doing one table lookup take maybe 300 cycles (about 1.8 µs at 168 MHz, an estimate to replace by measurement). The slack is 48.83 − 1.8 = 47 µs. A UART handler of 8 µs in the way leaves 39 µs of slack. A 40 µs handler leaves 7 µs. A 60 µs handler leaves nothing, and the column is dropped.
Work through a harder case. An 8 µs UART handler and a 12 µs tick handler run back to back just as a target arrives. They take 20 µs together. The reload then ends at 20 + 1.8 = 21.8 µs and the slack is 48.83 − 21.8 = 27 µs. The shot is still on time and the reload still wins. You can see how much stacking the design can take: about 47 µs of handlers, no more, before a column is lost. If your measured worst case is 30 µs, you have a margin of only about 1.5 times. Many teams want 2 times or better.
Now compare the two designs when a 30 µs handler blocks at just the wrong moment. With the processor firing, the shot is 30 µs late: 0.108°, or 18.8 cm at 100 m, 61 percent of a column. With the comparator firing, the shot is still on time. The reload is 30 µs late, but there are 47 µs of slack, so nothing is lost.
Blue lines are the targets, 48.83 µs apart. The purple bar is another handler that blocks the processor right when a target arrives. Choose who fires the laser, then lengthen the blocking handler.
Timeline model at 10 Hz and 2,048 columns. The 1.8 µs reload handler is an estimate (about 300 cycles at 168 MHz), not a measurement; measure yours. The 71 ns interrupt entry is 12 cycles at 168 MHz. Offset on the wall uses 100 m.
At 49 µs of blocking or more, the reload handler runs after the next target has gone by. The counter has passed it, so the comparator will not match until the counter wraps a full turn later. That column is simply not fired. The picture shows a missing dot, not a misplaced one.
A good handler checks the distance to the target before it writes. If the target is already behind the counter, it counts the miss and skips the column. A missing dot is easy for downstream software to see, because the packet carries a flag. A dot in the wrong place is not.
c/* PA2 = TIM2_CH3 (AF1) drives the laser driver's trigger input. Check names in RM0090. */ TIM2->CCMR2 = (1u << 4); /* OC3M=001: pin goes active when CNT == CCR3 */ TIM2->CCR3 = target_for_column(0); TIM2->CCER |= TIM_CCER_CC3E; TIM2->DIER |= TIM_DIER_CC3IE; /* interrupt on the same match, only to reload */ NVIC_SetPriority(TIM2_IRQn, 0); /* 0 is the highest priority on Cortex-M */ NVIC_EnableIRQ(TIM2_IRQn); void TIM2_IRQHandler(void) { TIM2->SR = ~TIM_SR_CC3IF; /* clear the flag */ TIM2->CCMR2 = (4u << 4); /* OC3M=100: force pin inactive (ends the trigger) */ TIM2->CCMR2 = (1u << 4); /* re-arm: active on next match */ col = (col + 1u) % COLS_PER_TURN; uint32_t tgt = target_for_column(col); uint32_t ahead = (tgt + COUNTS_PER_TURN - TIM2->CNT) % COUNTS_PER_TURN; if (ahead > COUNTS_PER_TURN / 2) { missed++; } /* target already passed: skip this column, flag it */ else { TIM2->CCR3 = tgt; } }
Read the handler as a data-flow story. In: a compare event and the counter. Out: a new CCR3, or a counted miss. Nothing in it decides when the laser fires. That decision was made by the comparator one column earlier. A DMA channel (a small copy engine that moves data without the core) can even do the reload from a table, leaving the processor idle. The interrupts and DMA lesson shows that variant.
On real hardwareOn an STM32 Nucleo, run the code above on a spare timer pin with a function generator standing in for the encoder (two 90-degree square waves). Add a loop that blocks for 30 µs in a lower-priority handler and one that blocks in a higher one. Capture the CH3 pin and the generator edge on a scope. Compare the delay between them in both cases.
Chapter 6
Separate the lateness that moves a dot sideways from the lateness that moves it in depth, and see why the processor cannot time the second
A race official fires a starting pistol and starts a stopwatch on the bang. A sprinter leaves the blocks 0.1 seconds later. The stopwatch reads 0.1 s too long, and it makes the runner look slow. If the sprinter's reaction time were the same every race, you could subtract it. If it changed every race, you could not.
A lidar measures distance the same way. Its stopwatch starts when the pulse leaves, stops when the echo arrives, and the distance is the speed of light times half the time. Our time of flight lesson derives it.
One nanosecond of start error: R changes by 0.2998 ÷ 2 = 14.99 cm
Now put the two kinds of lateness side by side. If the firing command is 1 µs late, the dot moves sideways by 6.3 mm at 100 m (Chapter 4). If the pulse leaves 1 ns late relative to the stopwatch, the dot moves in depth by 15 cm. A nanosecond is a thousand times smaller than a microsecond, but its effect on range is about twenty-four times larger in millimetres than the microsecond's effect on angle. Different parts of the system own each one.
| What is late | Typical unit | Effect | Who owns it |
|---|---|---|---|
| The firing command | microseconds | dot moves sideways: 6.3 mm per µs at 10 Hz, 100 m | firmware: timer, encoder, ISR |
| The pulse leaving the laser | nanoseconds | dot moves in depth: 15 cm per ns | driver circuit and timing block |
Look at the timer tick from Chapter 3: 11.9 ns at 84 MHz. As a range step that is 11.9 × 14.99 cm = 1.78 m. A processor timer can tell a wall at 10 m from a wall at 12 m. It cannot tell 10 m from 10.5 m. Range timing needs a dedicated time-to-digital converter (TDC), a circuit that stamps events with a resolution of picoseconds to hundreds of picoseconds. The SPAD, TDC and histogram lesson builds one.
That fixes the division of work. The processor's timer produces the trigger edge, with microsecond-level care for the angle. The timing block counts from the pulse to the echo with nanosecond care for the range. The two meet at the laser driver.
Between the trigger edge and the light leaving there is a chain: a logic gate, a driver, a transistor turning on, and a laser diode that needs a moment to start lasing. Each stage adds delay. We write the total as D. Three things can be true of D:
A design option that avoids most of this is to timestamp the pulse where it actually leaves, for example by tapping a little of the light or the driver current into the same timing block that stamps the echo. Then D cancels, because both stamps share it. That moves the problem into the analog front end; the firmware's part is to run the calibration and keep its table honest.
Each dot is one range measurement of a wall that is truly 20 m away. The blue line is the truth. Change the temperature and the pulse jitter. Then switch on the calibration, which removes the delay measured at 25°C.
Illustrative numbers: a constant driver delay of 8 ns and a drift of 30 ps per °C. These are made up to show the shape of the problem; a real driver has its own values, which you measure. The 60 samples are seeded so the same jitter gives the same dots on every visit.
Without calibration, the whole cloud sits more than a metre too far, because 8 ns is 1.2 m. With calibration at 25°C the cloud returns to the line, until the temperature moves. At 85°C the cloud is 27 cm off. Jitter, by contrast, only widens the cloud around its centre, and no calibration shrinks it.
On real hardwareOn any board you can build the analogue of this with a nanosecond-class edge: send a pulse down 10 m of coax and measure the round trip on a scope. Light in cable travels at about two thirds of c, so 10 m of cable each way is roughly 100 ns. Warm the driver chip with a hairdryer and watch the edge delay move. That is drift, seen directly.
Chapter 7
Learn what Class 1 promises, why a sweeping beam is safe where a parked one may not be, and what that asks of the firmware
Hold a magnifying glass over a leaf on a sunny day. Sweep it quickly across the leaf and nothing happens. Hold it still for a few seconds and the leaf smokes. The sun is just as strong in both cases. What changed is how long the energy stayed on one spot.
A lidar beam is the same kind of problem on a much smaller scale. The eye focuses light onto the retina, the light-sensitive layer at the back of the eye. A tiny, intense spot on the retina can heat it. Whether that harms the eye depends on how much energy lands there and how long it stays. The firmware controls the second part.
Laser products are sorted into classes by how much hazard they pose. The US federal rule 21 CFR 1040.10, which governs laser products sold in the US, defines a Class I product as one that does not permit access, during operation, to laser radiation above the Class I limits. The international standard IEC 60825-1 sorts lasers in a similar way. The Ouster sensor documentation says its sensors have been evaluated as Class 1 laser products to IEC 60825-1:2014 (Edition 3), use an 865 nm infrared laser that is only dimly visible, and recommends against peering into the window.
Two facts help here. Light between about 400 and 1,400 nm passes through the front of the eye and reaches the retina, which is why infrared lasers near 865 nm need care; light outside that band is mostly absorbed in the front of the eye. And the limit used in safety work is the maximum permissible exposure, the highest dose that is still thought to carry a negligible chance of harm, defined for a given wavelength and exposure time. I did not open the IEC standard itself, so this lesson prints no limit values from it. Every number in the device below is a pulse count, not an energy.
Also, you cannot count on a blink. The eye closes against a bright visible light, but it does not react to light it cannot see. That is one reason the product, and not the person, has to guarantee safety.
The same rule, in paragraph (f)(9), covers scanned lasers: a scanning product must not, after a failure that changes the scan velocity or amplitude, permit human access to radiation above its class limits. (The rule goes on to name what is allowed in certain higher classes; read it before you design.) In plain words: if the motor slows, speeds up or stops, the product must still be safe. This is a rule about a fault, not about normal use. A lidar that is safe only while everything works is not a Class 1 lidar.
Build a small model. A viewer holds an eye 100 mm from the window. The pupil is 7 mm across, which is a common simplification for the open pupil. The drum turns at 10 Hz and fires 2,048 shots per turn, 20,480 a second, each 0.1758° from its neighbour. At 100 mm, neighbouring shots land 100 × 0.1758 × π/180 = 0.307 mm apart. A 7 mm pupil spans 7 ÷ 0.307 = 22.8 shots. So each pass of the beam puts about 23 pulses into the eye, and the pass repeats 10 times a second: 228 pulses a second.
Now stop the motor with the beam aimed at the pupil. If the schedule runs on a clock, it keeps firing 20,480 times a second into the same 7 mm. That is 20,480 ÷ 228 = 90 times as many pulses a second. In 11.1 ms the stalled beam delivers as many pulses as normal scanning delivers in a whole second (228 ÷ 20,480 = 11.1 ms).
The scanner is on the left, an eye on the right. Warm dots are laser pulses that enter the pupil. Time runs 25 times slower than real. Press Stall the motor to park the beam on the pupil, and move the eye nearer or farther.
Toy model, in pulse counts and not in energy: 7 mm pupil, 20,480 pulses a second, beam width ignored, pupil drawn larger than scale, one laser only, stall with the beam aimed at the pupil and the firing schedule still running. Limit values depend on wavelength, pulse length, repetition rate and exposure time, and they come from the standard, which this lesson does not reproduce.
Slide the eye away to 500 mm. Each pass now puts only 4.6 shots in the pupil, because the columns are spread over a wider arc. The stalled beam still delivers 20,480 a second. Distance helps a normal scan; it does not help the parked beam, which is why a stall is the bad day to design for.
Partly. An angle schedule fires when the encoder reaches a target. If the drum stops, the encoder stops, no new target is reached, and no new shots fire. That is a built-in safeguard a clock schedule does not have. But do not rely on it. An encoder can dither: a worn bearing or an electrical glitch can make the count step back and forth across one value, and each crossing can match the compare register again. A broken schedule table can repeat a target. A faulted timer register can keep an output high. Each fault can return the parked beam. The answer is to treat the stall as a fault the system must detect and answer, independent of how the shots were scheduled. That is Chapter 8.
On real hardwareDo not point a lidar laser at anything you care about. Use a visible, low-power red alignment laser at Class 2 or below, or an LED, on a Nucleo with a small motor. Park the motor and count, with a photodiode and a scope, how many pulses reach a fixed 7 mm aperture per second in motion and when stopped. The ratio you measure should resemble the one above.
Chapter 8
Design the circuit and code that cut the laser when the scan stops, and check them against a time budget
A gas stove has a small flame under a metal probe. If the flame blows out, the probe cools, and a valve closes on its own spring. Nobody has to notice. Nobody has to press a button. The default, with nothing holding the valve open, is no gas.
That idea runs the whole chapter. An interlock is a mechanism that allows a hazard only while a list of safe conditions holds. A fail-safe interlock is built so that when it breaks, loses power or hangs, the result is the safe state. For a lidar, the hazard is laser emission. The safe state is laser off.
The encoder already tells us. A monitor wakes every millisecond and subtracts the previous count from the counter. At 10 Hz that is 901 counts. If the drum stalls, the difference is zero. If it spins too fast, the difference is large. If it reverses, the subtraction wraps to a huge number. All of these fall outside a window, a low and a high limit. We set 800 to 1,000 here, a plausible band around 901.
Check the limits against real cases. Nominal is 901 counts per millisecond. An over-speed of 30 percent gives 1,171, which is above 1,000, so it trips. A reversed drum makes the subtraction wrap: the result is near 89,000, far above the high limit, so it trips too. A dead encoder gives 0, below the low limit, and trips. A drum within 10 percent of nominal (811 to 991) passes. The window is a trade-off: narrow rejects more faults and false-trips more often.
One bad sample could be a glitch, so the monitor can ask for n bad samples in a row before it trips. A larger n rejects glitches and slows detection by one monitor period each. Detection time in the worst case is n × the monitor period, since a stall that starts just after a sample is first seen at the next one.
c/* 1 kHz monitor on TIM6. Priority just below the firing handler, above everything else. */ #define WIN_LO 800u /* counts per ms; nominal is 901 at 10 Hz */ #define WIN_HI 1000u #define BAD_LIMIT 2u /* consecutive bad samples before a trip */ static volatile uint8_t fault_latched; static void trip(uint8_t why) { LASER_EN_PORT->BSRR = (uint32_t)LASER_EN_PIN << 16; /* enable low: first, before anything else */ TIM2->CCER &= ~TIM_CCER_CC3E; /* disconnect the trigger output from the pin */ fault_latched = why; /* stays until a deliberate reset */ } void TIM6_DAC_IRQHandler(void) { static uint32_t last; static uint8_t bad; TIM6->SR = 0; uint32_t now = TIM2->CNT; uint32_t d = (now + COUNTS_PER_TURN - last) % COUNTS_PER_TURN; /* reverse gives a huge d */ last = now; if (d < WIN_LO || d > WIN_HI) { if (++bad >= BAD_LIMIT) trip(FAULT_SPEED); } else { bad = 0; toggle_alive_pin(); } /* the hardware watchdog watches this pin */ }
The monitor above is firmware. A wild pointer, a stuck loop or a bad interrupt priority can stop it. So a second layer sits outside the processor: a small circuit (a retriggerable one-shot, or an external watchdog chip) that holds the laser-enable line high only while it keeps seeing the alive pin toggle. Each toggle restarts its timer. If the toggles stop, the timer runs out after a time Th and the enable line drops, with no processor involved. The alive pin toggles only when the speed is good, so a stall stops the toggles too. One layer sees the stall by comparing; the other sees it by silence.
The cost of the second layer is a worse worst case: the hardware layer reacts after Th, which is usually longer than the firmware path. It is the net under the wire, not the wire.
Zero is the moment of the fault. Each bar is when a layer cuts the laser, in the worst case. The red line is the time budget from Chapter 7 (1 second of normal exposure). Choose the fault, then tune the layers.
Model. Firmware path worst case: samples × period, plus an assumed 0.01 ms (10 µs) for the enable line and laser driver to switch off. Hardware path: its timeout, counted from the last good toggle. Budget: 11.1 ms, the time a parked beam needs to deliver one second of normal scanning’s pulses to a 7 mm pupil at 100 mm (Chapter 7, a toy count, not a standard’s limit). Your real budget comes from the standard and your own analysis.
With the defaults, the firmware path trips in 2 ms and the hardware net in 8 ms. Both fit in 11.1 ms. Now switch to Firmware hangs. The firmware bar disappears: no code is running to trip. The hardware layer alone must act, and it does, at 8 ms. Push the hardware timeout to 20 ms and it fails, and the page says so. The same chain passes one fault and fails the other, which is why we test faults separately.
A last design point: the monitor needs a safe start-up too. At power-on the drum is not at speed. The enable stays off, the monitor ignores the window while the speed ramps, and only a continuous run of good samples arms the laser. Skipping this step is the easiest way to emit while stopped.
On real hardwareOn an STM32 Nucleo, build the layers with an LED in place of the laser. Wire a pull-down on the enable pin. Let the firmware toggle a second pin only when the encoder speed is good, and feed that pin to a one-shot (or a watchdog chip with a known timeout). Stop the encoder with your hand and measure, with a scope, the time from the last encoder edge to the LED going dark. Repeat after halting the processor in the debugger.
Chapter 9
List what can fail, inject each fault, and measure the time until the laser goes dark
A building has a fire alarm. Once a year someone presses the test button and a bell rings. Nobody believes the alarm works because the drawings say so. They believe it because they heard it. A safety chain that has never been made to fail is a hope, not a design.
For the lidar, fault injection means causing a failure on purpose, at a bench, and watching what the laser does. The pass condition is not “the code looks right”. It is a number: the time from the fault to the laser being dark, below the budget.
Walk through every part of the firing path and ask, how can this stop being right? Engineers call this a failure modes and effects pass. Ours yields seven faults.
Notice what the list teaches. A speed window alone catches faults 1 to 3. It cannot catch 4, 5, 6 or 7. Each extra layer exists because some fault slips past the layers before it.
L1, speed window. The monitor of Chapter 8: counts per millisecond must sit between 800 and 1,000. L2, shot-count check. The firmware also counts trigger pulses per millisecond with a second timer and checks them against 20 or 21 (the nominal is 20.48). A stuck trigger gives 0 or a flood; a dither gives far too many. L3, hardware gate. An external watchdog chip watches an alive pin that toggles only when L1 and L2 are both happy. Its output is ANDed into the laser-enable line. The AND means a stuck processor pin cannot hold the enable up alone.
Try it. The three layers start with only L1 on. Press Run all seven tests, read which ones fail, and turn on the layer that covers each. Then run again.
Each row is one injected fault. A green row means the laser was dark inside 11.1 ms. A red row means it was not, or not in time. Switch layers on and off, then run the tests again.
Model, with assumed times: firmware layers act 2.01 ms after a fault (two bad 1 ms samples plus 10 µs to switch off); the hardware gate acts 8 ms after the last good alive toggle. If the firmware hangs, no alive toggle comes. L1 and L2 alone cannot clear a stuck enable pin; only the AND gate can. The 11.1 ms budget is the Chapter 7 toy figure, not a standard’s limit.
With all three layers on, every row turns green, and the slowest are the hardware-only cases at 8 ms. Turn off L3 and rows 4 and 5 turn red: firmware cannot save you from its own hang or from a pin it cannot control. Turn off L2 and rows 6 and 7 turn red: the drum looks perfect while the laser misbehaves.
Work one design choice through. The monitor sends an alive toggle every 1 ms. If the hardware timeout Th is only 1.2 ms, ordinary jitter in the monitor makes it trip by mistake and the lidar keeps turning itself off: a nuisance fault. So Th must be well above the toggle gap, say at least 3 ms. For the other side, you want the worst case to be no more than half the 11.1 ms budget, which is 5.55 ms, so there is room for drift. A choice of 4 ms with a part that drifts by 30 percent gives a range of 2.8 to 5.2 ms. That fits both limits. The 8 ms of our device passes the bare budget but fails this half-budget rule, which is why the table above records the margin and not only the pass.
Also decide how you measure time-to-dark. Put one scope probe on the signal that injects the fault (the line that opens the encoder, or the debugger pin that halts the core). Put a second probe on the laser-driver input and a third on its supply. The delay from the first edge to the last light-carrying edge is the number that goes in the table. Do not use the processor’s own timer for this: it may be the thing that broke.
Symptom. The bench passes at the desk and a unit fails in a hot chamber. The hardware gate that took 8 ms at 25°C takes 14 ms at 70°C.
Measurement. Repeat every injected fault at the temperature and supply extremes, with the scope on the fault signal and on the laser-driver input. Record the worst time for each, not the average. Make a table: fault, layer that acted, time, margin to the budget.
Fix. Choose parts whose timeout does not drift (a crystal-based or window watchdog rather than a bare resistor and capacitor), and set the budget with a margin you can defend. And avoid common cause failures: if the monitor and the thing it watches share one clock, one dead crystal stops both. Give the hardware gate its own oscillator.
Finally, keep the bench. The test list belongs in the project, run on a hardware-in-the-loop rig (a board with real I/O wired to a test harness) on every firmware release. The fail-safe and functional safety lesson goes deeper on safe states and test discipline, and the robotics test engineering lesson covers rigs.
On real hardwareUse an STM32 Nucleo, an LED for the laser and a scope. Inject the seven faults by hand: stop the encoder with a finger, unplug it, spin it fast, halt the core in the debugger, tie the enable pin to 3.3 V through a jumper, write 0x1 to the timer output enable from the debugger, and wiggle the encoder by hand across one value. Record each time-to-dark with the scope trigger on the injected event.
Chapter 10
Keep the numbers, the checklist and the core code, and see where each source came from
One idea runs through all of it: tie each shot to the shaft, not to the clock, let hardware pull the trigger, and make the safe state the default. The encoder gives the angle. The timer comparator turns the angle into a trigger edge with nanosecond care. The processor only prepares the next shot. And a layered chain, with a hardware gate that does not trust the processor, keeps the beam off whenever the scan is wrong.
| Quantity | Value | Where it comes from |
|---|---|---|
| Encoder counts per turn | 90,112 (0 to 90,111) | Ouster lidar data packet format |
| Counts per column | 44 / 88 / 176 | Ouster: 2048 / 1024 / 512 column modes |
| Lidar modes | 512x10, 1024x10, 512x20, 2048x10, 1024x20 | Ouster documentation |
| Columns per second (2048x10) | 20,480; one per 48.83 µs | 2,048 × 10, then 1 ÷ 20,480 |
| Column width | 0.1758°; 30.7 cm at 100 m | 360° ÷ 2,048 |
| One count | 0.003995°; 1.110 µs at 10 Hz | 360° ÷ 90,112 |
| 1 µs late at 10 Hz | 0.0036°; 6.3 mm at 100 m | 360 × f × δt |
| 1 ns of pulse start error | 14.99 cm of range | c ÷ 2, c = 299,792,458 m/s |
| One 84 MHz timer tick | 11.9 ns; 1.78 m of range | 1 ÷ 84 MHz; STM32F407 timer clock with a 168 MHz system clock |
| Interrupt entry, Cortex-M4 | about 12 cycles; 71 ns at 168 MHz | ARM documentation figure, zero wait states; measure your board |
| Reload slack | about 47 µs | 48.83 µs minus an estimated 1.8 µs handler |
| Pulses per pass into a 7 mm pupil at 100 mm | 22.8; stalled beam 90× the rate | Toy model (Chapter 7) |
| Interlock budget | 11.1 ms | Toy model (Chapter 7); yours comes from the standard |
Jitter: shot-to-shot variation in delay. Latency: the fixed part of the delay. Quadrature: two square waves 90 degrees apart that give position and direction. Encoder interface mode: a timer that counts encoder edges in hardware. Output compare: a comparator that changes a pin when the counter equals a register. Slack: time to spare before a deadline. Interlock: logic that allows a hazard only while conditions hold. Fail-safe: broken means safe. Latch: stays tripped until a deliberate reset. Common cause: one fault that disables several layers at once.
c/* The whole idea in one place (STM32F407; check names against RM0090). */ /* 1. Angle: TIM2 counts encoder edges in hardware. CNT is 0..90111. */ TIM2->SMCR = 3u; TIM2->ARR = 90112u - 1u; TIM2->CR1 |= TIM_CR1_CEN; /* 2. Shot: the comparator fires the trigger pin when CNT == CCR3. */ TIM2->CCMR2 = (1u << 4); TIM2->CCR3 = target_for_column(0); TIM2->CCER |= TIM_CCER_CC3E; /* 3. Reload: the highest-priority ISR writes the next target, or counts a miss. */ void TIM2_IRQHandler(void) { TIM2->SR = ~TIM_SR_CC3IF; col = (col + 1u) % COLS_PER_TURN; uint32_t tgt = target_for_column(col); if (((tgt + COUNTS_PER_TURN - TIM2->CNT) % COUNTS_PER_TURN) > COUNTS_PER_TURN / 2) missed++; else TIM2->CCR3 = tgt; } /* 4. Safety: a 1 kHz monitor trips on a bad speed window and feeds the hardware gate. */ void TIM6_DAC_IRQHandler(void) { TIM6->SR = 0; uint32_t d = (TIM2->CNT + COUNTS_PER_TURN - last) % COUNTS_PER_TURN; last = TIM2->CNT; if (d < 800u || d > 1000u) { if (++bad >= 2u) trip(FAULT_SPEED); } else { bad = 0; toggle_alive_pin(); } }
The lidar track continues: from histograms to point packets turns each echo into a data packet, timing and sync for lidar stamps those packets so they survive fusion, and small ranging sensors covers the compact cousins. Earlier foundations: timers, PWM and sampling, interrupts and DMA, and motor control firmware. For what the dots become, see lidar sensors and ICP and point clouds. For deadlines in general, real-time performance and embedded real-time systems.
Now press Present or Teach and explain, from memory, how a 10 microsecond delay moves a dot, why a hardware compare removes it, and what makes a stalled scanner a safety problem. Then go back to the wall at the top, set the jitter to 30 microseconds, and explain why only the third scheme stays tidy. Credit: the Ouster team’s public documentation made the scale concrete; any mistakes here are ours.