main
Name Last commit message Last updated
controls Publish 1.4.0 · John Lauer
dashboard Publish 1.4.0 · John Lauer
dist Publish 1.4.1 · John Lauer
firmware Publish 1.4.0 · John Lauer
screenshots Software 1.3.1: test-stage firmware (J4 TMC2209, HOME, limits, self-test), Stage tab and Calibrate in smi-dash (simulat… · John Lauer
README.md Publish 1.4.1 · John Lauer
software-icon.png Overview: add the Software card (firmware and dashboard) · John Lauer

Software: RP2040 firmware and the SMI dashboard

Firmware for the onboard RP2040, and a dashboard that shows both photodiode channels live, finds every fringe, reads its lean for direction and keeps a running position in nanometres. Since board 1.2, and on board 1.3 now, every setting that used to need a screwdriver (laser current, both offsets, the amplifier gains, the monitor bias) is set from the dashboard or the CLI, through the RP2040, with the firmware enforcing the laser's limits. Board 1.3 adds a STAGE connector for the test stage: the RP2040 homes it, steps it and runs its self-test, and the dashboard uses it as the moving target to calibrate the board by itself. With no hardware attached the dashboard runs a physical simulator of the laser, the optics and the board, so everything here can be tried today.

Board 1.3 tuned from software (simulated): laser at 95.1 mA on the head DAC, channel 1 second stage at -20 V/V, both channels centred, fringes from the stage moving counted

Folder What it is
firmware/ C, Pico SDK 2.1.1. Round-robin ADC0/ADC1 at 500 ksps total over DMA, SYNC edges on GPIO15, a framed and delta-packed USB CDC stream with CRC, the command channel on the same link, and the board 1.3 test-stage driver (TMC2209, HOME, limits, self-test).
controls/ The board's control map, the generator that makes the firmware's control table and the dashboard's copy from it, and the README's control table.
dashboard/ smi-dash, a Rust app with a web UI for a Hydrogen webview, a CLI with the same verbs, the simulator and the fringe detector.
dist/ Built files: smi_pico.uf2, smi-dash-linux-x64, smi-dash-windows-x64.exe, with SHA256SUMS.

Quick start

  1. Power the main board through USB-C PD. Connect USB-C DATA to the computer, hold BOOTSEL and press RESET to enter the RPI-RP2 bootloader.
  2. Copy the 1.4 RP2040 firmware to the RPI-RP2 drive. The board reboots into the digitizer.
  3. Run the dashboard: smi-dash start, then smi-dash show to open it in a Hydrogen webview tab (or open the printed http://127.0.0.1:<port>/ in any browser).
  4. Click Pico (USB) under Source, or run smi-dash source serial. Without a RP2040, leave it on Simulator.
  5. Board 1.3: open the Controls tab. Tick the interlock box (beam enclosed or eyewear on) and hold Enable for a second, or run smi-dash laser on --beam-safe. Set a current, then Tune, or run smi-dash tune.
  6. Test stage: open the Stage tab and press Home, or run smi-dash stage home. Step it, run the Self-test, or Calibrate (simulator only for now).

On Windows use smi-dash-windows-x64.exe (CSV recording only): the RP2040 appears as a COM port. The Linux build needs libhdf5 and libudev at run time (Ubuntu 24.04: sudo apt install libhdf5-103-1t64 libudev1). Inside WSL a USB device is only visible after usbipd attach --wsl --busid <BUSID>; smi-dash ports lists what it can see and marks the RP2040.

Board 1.3: every setting from software

Boards 1.2 and 1.3 replace the trimmers and jumpers with a DAC121C085 on the laser head for the laser set-point, a DAC7574 on the main board for both offsets, analog switches on RP2040 GPIOs and on the head's MCP23008 for the gains and monitor bias, a laser enable sent as a 10 kHz carrier, and an ADS1115 on the head that measures the laser current. The set-point never crosses the cable as a voltage: the RP2040 writes it over the cable's I2C and reads it back. The RP2040 drives all of it, follows the board's controller contract (design/control-map.json, revision 1.3.0, and the board's design/decision8-firmware.patch), and takes commands on the same USB link that carries the samples.

The controls

Control map 1.3.0-revision-1.3-controller-contract.

Control (map id) Where Range Scaling Power-on Firmware limits CLI
Laser current (laserCurrent) DAC121C085 on the laser head, 0x09, 2.5 V reference 0 to 109.2 mA 0.0269538 mA per count 0 mA refuses above 109.16 mA (the DAC's top less a 45-count guard band; diode rated 135 mA, hardware cutoff 123.89 mA); each write drops the enable for 2 ms, is read back, and re-arms only on an exact nonzero match (the head's soft-start then ramps the current); at most one write per 250 ms; counts mode takes the contract's command code: DAC code = max(command - 45, 0); set-point 0 at boot and on link loss laser current <mA>
Offset, channel 1 (monitorOffset) DAC7574 channel B 0 to 3.299 V 0.000805664 V per count 0 V moves the ADC by 1 + |K| per volt, K = its stage 2 gain; refused while the laser is on (board rule) offset ch1 <V>, offset auto
Offset, channel 2 (externalOffset) DAC7574 channel C 0 to 3.299 V 0.000805664 V per count 0 V moves the ADC by 1 + |K| per volt, K = its stage 2 gain; refused while the laser is on (board rule) offset ch2 <V>, offset auto
Monitor TIA (headTiaGain) MCP23008 bit 0 1 k / 4.7 k switch 1 k refused while the laser is on (board rule) gain ch1-tia <ohm>
Monitor second stage (monitorSecondStageGain) GPIO7 -5 V/V / -20 V/V switch -5 V/V refused while the laser is on (board rule) gain ch1-amp -5|-20
External TIA (externalTiaGain) GPIO9 46.836 k / 150 k switch 46.836 k refused while the laser is on (board rule) gain ch2-tia <ohm>
External second stage (externalSecondStageGain) GPIO8 -5 V/V / -20 V/V switch -5 V/V refused while the laser is on (board rule) gain ch2-amp -5|-20
Monitor bias (headMonitorBias) MCP23008 bit 1, MCP23008 bit 2 Low 0.252 V / Mid 2.488 V / High 4.649 V switch Low 0.252 V refused while the laser is on (board rule) bias low|mid|high
Laser enable GPIO6, a 10 kHz carrier on / off off needs the interlock key and a checked current zero; off on USB loss or port close, watchdog reset, 3 s without a host command, overcurrent, or a DAC, expander or current-ADC failure; while on, the head DAC is read back every 2 ms (a mismatch turns it off; the traffic keeps the head's I2C watchdog fed) laser on --beam-safe, laser off
Laser current, measured ADS1115 at 0x49 on the laser head, AIN0-AIN1, +/-0.512 V, 128 SPS 0 to 256 mA 0.0078125 mA per count across the 2 ohm shunt, zero calibrated with the laser off read 50 times a second; three readings above 116 mA turn the laser off laser read
Main analog rail ADC2 (GPIO28), 1:2 divider 0 to 6.6 V 1.611 mV per count read once a second, shown in the status bar status

The table is printed by controls/control_table.py from the same normalised map the firmware is built from. The values the board map leaves to software are set in controls/gen_controls.py: at most four laser set-point writes a second, a 116 mA firmware trip (above the 109.2 mA top and below the 123.9 mA hardware cutoff; the generator refuses a map where that order does not hold), 50 current readings a second, a 3 s host heartbeat and a 300 ms watchdog. The head's own shunt cutoff, its resistor-set ceiling and its I2C watchdog are hardware and do not rely on any of this.

Safety, in the firmware as well as the hardware

  • Off by default. The enable pin is driven low before anything else at power-up, and the head DAC is written to zero and read back before any other control. The laser stays off after a watchdog reset, when the host closes the port or USB goes away, and when no command has arrived for 3 s. The dashboard sends a heartbeat every second while the laser is on, so if the dashboard dies or is killed, the laser goes off.
  • Write, read back, then arm. Every set-point write drops the enable, waits 2 ms for the head's disable path and soft-start reset, writes the head DAC, reads the register back, and restarts the 10 kHz carrier only on an exact match with a nonzero code; then it reads the register once more, because the head's watchdog wants fresh I2C traffic right after enable. The head's soft-start ramps the current up from zero on every arm. That is the board's ramp; the firmware does not step the set-point (each step would restart the soft-start) and writes at most four set-points a second.
  • Guard band. Command codes reach the head DAC as max(command - 45, 0), so codes 0 to 45 keep the head disarmed and positive DAC offset error cannot make current. The top set-point is 109.16 mA.
  • Readback while armed. Every 2 ms the firmware reads the head DAC back; a wrong code, a power-down mode or a failed read latches a fault and turns the laser off. The same traffic keeps the head's I2C watchdog fed, and it runs between USB frames and while waiting on USB, not only in the main loop.
  • No writes while armed. The contract allows only reads on the bus while the laser is armed, apart from set-point writes, which disarm first. Offsets and every gain and bias selector are refused while the laser is on, and the head ADC's configuration and pointer are written only while disarmed. smi-dash offset auto and smi-dash tune therefore turn the laser off for each offset or gain write and back on at the same set-point; they never turn on a laser that was off.
  • An interlock to turn it on. The binary enable command carries a fixed key that the dashboard sends only after an explicit confirmation: the page's interlock box plus a one-second hold on Enable, or --beam-safe on the CLI.
  • Checked readback. The current-readback zero is calibrated with the laser off, and the laser cannot be enabled until it is. Three readings above the trip latch an overcurrent fault. Current with the laser disabled latches a fault, and three missed ADS1115 reads with the laser on turn it off. A DAC or expander that stops acknowledging is a fault too. Faults stay latched until smi-dash board clear-fault.

The board's text commands

The firmware also takes the contract's text commands, one per line on the same port: laser CODE (0 to 4095, with the guard band), laser off, laser current (answered in an INFO frame with the signed ADS1115 code, the command code and the DAC code), head MASK (MCP23008 GP0 to GP2), gain MASK (RP2040 GP7 to GP9), offset B CODE, offset C CODE, plus hb MS to set the heartbeat timeout. They run through the same control code as the binary commands, so every limit, refusal and fault applies; selector and offset commands disarm the laser first and it stays off until a new laser command, as the contract says. A text-only host must send a command at least every 3 s while the laser is on (or raise it with hb 30000). These lines bypass the dashboard's interlock confirmation, so a host that uses them must ask for it itself.

Controls tab

Power-up: laser off, every output at its power-on default, the interlock not yet ticked

The Controls tab is built from the control map, so it follows the board without code changes. Laser: the interlock box, hold-to-enable and an always-ready Laser off; the current slider (sent when released, since each write restarts the soft-start) and numeric entry; the target, the set-point the head DAC holds, and the current the head measures, with 20 s of history. Offsets: one slider per channel with its mean in ADC codes, locked while the laser is on, and Auto-centre, which servoes each channel's mean to mid-scale (code 2048) using the board's stage equation Vstage = (1 + K) Voffset - K Vbuffer for the first step and the measured slope after that, cycling the laser for each write. Gains and bias: every switch, locked while the laser is on. Tune, below.

Tune for fringes

Tuning in progress: the current steps, each step re-centred and scored

smi-dash tune (or Tune) steps the laser current across its range, waits for the head's soft-start, re-centres channel 1, and scores the fringes for 0.4 s: the 1st-to-99th percentile swing of the lightly filtered signal over its robust noise, with clipping penalised. It then refines around the best current, tries each second-stage gain, centres both channels, and returns every step's score. It takes about 10 s. Move the target while it runs. On this board the laser current cannot be dithered to make fringes with a still target (every write restarts the soft-start), so with a still target Tune reports that it saw no fringes and puts the current back where it was.

Accuracy through the simulated board, smi-dash eval --board (target at 400 um/s, 2 s per case, both channels centred the way offset auto does it, with the laser cycled for each offset write):

Laser current Stage 2 gain Fringe swing Noise Score True fringes Detected Final error RMS error
65 mA -5 V/V 16 codes 1.39 codes 12 2430 0 -2 nm 115789 nm
65 mA -20 V/V 63 codes 1.39 codes 46 2430 2432 -2 nm 283 nm
80 mA -5 V/V 28 codes 1.39 codes 20 2430 1237 -393157 nm 253494 nm
80 mA -20 V/V 111 codes 1.48 codes 75 2430 2432 -2 nm 244 nm
95 mA -5 V/V 34 codes 1.39 codes 24 2430 2431 -331 nm 377 nm
95 mA -20 V/V 135 codes 1.48 codes 91 2430 2431 -331 nm 377 nm
104 mA -5 V/V 32 codes 1.48 codes 22 2430 2365 -431321 nm 316633 nm
104 mA -20 V/V 128 codes 1.67 codes 76 2430 3628 -81594 nm 91339 nm
109 mA -5 V/V 38 codes 1.39 codes 28 2430 2429 -331 nm 398 nm
109 mA -20 V/V 153 codes 1.48 codes 103 2430 2429 -331 nm 398 nm

At the power-on gain (-5 V/V) the fringe swing at low current falls under the detector's 24-code minimum and fringes go uncounted; the page then says "signal small" above channel 1. At -20 V/V counting is within a fringe except at 104 mA, where the measured current (about 105.6 mA) sits in the simulated laser's mode-hop window around 106 mA and the two competing modes make the detector over-count. Tune scores that current lower and avoids it.

CLI for the board

Every control is a verb, and every verb takes --json, so an AI in an Adom workcell can tune the board:

smi-dash laser on --beam-safe | laser off | laser current 95 --wait | laser read
smi-dash offset ch1 0.52 | offset ch2 650 --counts | offset auto [ch1|ch2|both]     # offsets: laser off, except auto
smi-dash gain ch1-amp -20 | gain ch1-tia 4700 | gain ch2-tia 150k | bias mid        # laser off
smi-dash ctl <map id> <value> [--counts | --index]
smi-dash board | board map | board clear-fault | board config --isense-hz 50 --hb-timeout-ms 3000
smi-dash tune [--channel 1] [--min-ma 50] [--max-ma 109] [--steps 8] [--no-gains] | tune --status | tune --stop
smi-dash eval --board

Refusals name the reason and the fix, for example ERROR: Laser current (mA) out of range with Hint: laserCurrent accepts 0.0000 to 109.1627 mA, or ERROR: the board map says change this only with the laser off with the board's own rule quoted.

Command channel

Commands use the stream's own frame (sync word, type, length, sequence, CRC-16): the host sends type 0x10 frames, the RP2040 answers each with a 0x11 ACK carrying the command's sequence number and a status, and pushes a 0x12 STATE frame four times a second. The ops are get_state, laser_enable (with the key), set (control, unit mode: physical units, DAC counts or setting index, value), read_laser_current, heartbeat, clear_fault, get_map and config. Every op is idempotent, so the dashboard retries a lost ACK. The STATE frame carries the control map's hash; the dashboard warns if the RP2040 was built from a different map. Layouts are in firmware/src/smi_ctl.h.

The control logic (limits, the gated write sequence, guard band, interlock, heartbeat, trips) is one portable C file, firmware/src/smi_ctl.c, and the text commands are another, firmware/src/smi_text.c. The firmware runs them, the host tests run them, and the dashboard's simulator compiles smi_ctl.c in, so the simulated board enforces exactly what the RP2040 does.

The simulated board

With Board 1.3 model on (the default), the simulator's laser current comes from the simulated head DAC through the head's soft-start (modelled as a 25 ms rise on every arm) and a 1.2 % driver gain error, the firmware core's 2 ms readback polls run against it, and the ADS1115 measures the current with its own noise and zero offset. A modelled 658 nm Fabry-Perot diode sets the rest. The threshold is 60 mA, with 0.45 mW/mA above it. The self-mixing depth is largest just above threshold. Thermal tuning is 0.006 nm/mA, so a change of current makes fringes with the target still. Mode hops come every 18 mA, with two-mode competition and partition noise near each hop. These are model values chosen to be plausible, not datasheet figures. Each channel follows the board map's stage equation with the TIA gain, second-stage gain, DAC offset and monitor bias, then the anti-alias filter and the RP2040 ADC. The external TIA's reference is not in the map; the simulator assumes 0.25 V.

Board 1.3: the test stage

Board 1.3 brings the stage controller out on J4, STAGE: GP10 STEP, GP11 DIR, GP12 EN_N (active low, pulled high on the board), GP13 the TMC2209's single-wire UART, GP14 HOME (a normally closed switch to ground, pulled up, so open or disconnected reads high). The test stage (test-stage/) turns a 17HS08 stepper through an M3 screw and a 10:1 lever: 15.625 nm of mirror travel per pulse, nominal, and 1600 pulses (25 um) of travel. The firmware follows test-stage/design/stage-map.json. Board 1.4 will put the RP2040 on the main board with the same GPIO numbers; the firmware does not change for it.

Stage tab (simulated) after a self-test: the staircase out and back, commanded (yellow) and counted from the fringes (teal)

Nothing here has run on a stage. Nothing is assembled. Every number below comes from the dashboard's simulated stage, labelled "simulated" on the page and in the CLI: the firmware's own stage code (firmware/src/smi_stage.c) against a simulated TMC2209 (CRC, registers, IFCNT) and a mechanism model with a true scale of 15.31 nm/pulse (inside the stage map's 14.64 to 16.65 nm geometry range, off nominal on purpose), 1.6 pulses of lost motion at each reversal, a 2 ms lever lag and 0.6 nm/s of thermal drift. These are model values, not measurements.

What the firmware does

  • Disabled at boot. EN_N is driven high before anything else touches the port, and stays high through configuration. The driver is disabled on a fault, on stage off, when USB goes away or the port closes, and (once a dashboard has sent a binary command) when the host is silent for the heartbeat timeout, 3 s; the dashboard sends heartbeats while the stage is enabled. The position becomes invalid whenever the driver is disabled.
  • Configured and checked over the UART. With EN_N high: IOIN must report version 0x21, then GCONF, SLAVECONF, IHOLD_IRUN (27/31, about 0.41 A rms), CHOPCONF (16 microsteps, interpolation off) and VACTUAL are written with the stage map's values, every write checked by IFCNT advancing by one, GSTAT cleared, GCONF and CHOPCONF read back. Only then is EN_N pulled low. Idle, DRV_STATUS is read twice a second; over-temperature, a short or an open load disables it.
  • Homing as the stage map describes. Towards HOME at 80 pulses/s to the first high, verified for 5 ms; back off until low plus 32 pulses; back in at 32 pulses/s; zero is the switch's opening edge. If HOME starts high, only a release search (at most 128 pulses) is allowed. Searches give up after 1920 pulses; a stuck or missing switch latches a fault.
  • Hard limits. Before homing, only homing moves the stage. After homing, any move outside 0 to 1600 pulses is refused. HOME going high during a normal move away from zero disables the driver and invalidates the position.
  • Rate-limited steps. 160 pulses/s by default, at most 640, with the stage map's STEP and DIR timing (3 us high, 3 us DIR setup and hold).
  • Retries never step twice. Stage commands carry the frame's sequence number; a retried command returns the cached answer without new pulses. The dashboard now resends the same sequence number on every retry.
  • Self-test. To pulse 128, then +128 four times and -128 four times, 1 s at each plateau (about 17 s at 160 pulses/s).

Binary op 0x09 on the existing command channel (status, home, step, speed, stop, off, current, selftest, move); a STAGE frame (type 0x13: the 24-byte state block and the sample-pair index) every 50 ms while enabled, else every 500 ms. The stage map's text commands work on the same port: stage home, stage step N, stage speed [N], stage current, stage status, stage stop, stage selftest, plus stage move N and stage off. A text-only host is not held to the heartbeat; the USB disconnect rule still applies. The DIR polarity is a commissioning setting (DIR_POS_LEVEL in smi_stage.c): if the first homing search runs away from the switch, flip it.

The Stage tab

Home, Stop and Off; a step size of 1, 8, 32, 128 or 512 pulses with towards HOME and away buttons; the speed (80, 160, 320 or 640 pulses/s); the position in pulses, the commanded position in nm and the position counted from the fringes. The Stage position plot replaces the spectrum while the tab is open: 30 s of the commanded position (pulses times the scale: nominal 15.625 nm/pulse until Calibrate fits one) against the counted position (fringes times 329 nm), placed on the commanded trace where the stage last finished homing, plus the simulated mirror, dashed, on the simulator.

Steps of 128 and 512 pulses, simulated: commanded and counted move together

Self-test runs the firmware's sequence and analyses the plateaus as the stage map asks: the scale fitted to the counted fringe edges (each edge placed at the stage position where it happened, so the slope is resolved far below one fringe), a plateau fit with a drift term, forward against reverse plateaus at the same position, and the return residual. A whole-fringe counter resolves 329 nm, so a return residual of "0 nm counted" means within one fringe; on the simulator the page also shows the true mirror's residual. If the counted scale is far outside the geometry range (laser off, or fringes missed), it says so instead of reporting a scale.

Simulated self-test after Calibrate: 15.284 nm/pulse from 46 counted fringe edges (outbound 15.273, return 15.296), return residual 0 nm counted; the simulated mirror's own fit is 15.274 nm/pulse and its return residual -19.6 nm, the 1.6 pulses of modelled lost motion. Before Calibrate (75 mA, power-on -5 V/V), the outbound sweep counted no fringes at all and the self-test said fringes were missed.

Calibrate: the board calibrates itself

Tune needs a moving target, and the stage is one. Calibrate (or smi-dash calibrate --beam-safe) homes the stage, then:

  1. records the settings and steps the stage 1024 pulses (16 um nominal) from pulse 128, counting fringes, as the board is;
  2. turns the laser off and waits for the current readback's zero code to settle;
  3. turns it back on at the same set-point and auto-centres both channels;
  4. runs Tune while the stage moves back and forth between pulses 200 and 1400 at 640 pulses/s;
  5. steps the 1024 pulses again, counting fringes and fitting the scale to the fringe edges;
  6. prints a before/after report and uses the fitted scale for the commanded trace from then on.

It turns the laser off and on, so it needs the interlock: the page's checkbox, or --beam-safe. It runs on the simulator only for now and refuses on a RP2040.

Calibrate (simulated) from 75 mA and the power-on gain: before and after

A simulated run from an untuned board (75 mA, -5 V/V), smi-dash calibrate --beam-safe, 43 s:

Before After
Laser current 75.00 mA 95.13 mA
Channel 1 second stage -5 V/V -20 V/V
Fringe score while moving 15.5 80.8
1024-pulse step, counted 0 nm (0 fringes) 15,463 nm (47 fringes)
Scale from fringe edges none 15.338 nm/pulse
Simulated mirror travel 15,680 nm 15,660 nm

The fitted 15.338 nm/pulse is within 0.2 % of the simulated mechanism's 15.31 (the remaining difference is the lost motion and the fit over 47 edges), where the nominal 15.625 is 2 % off. A real stage will need this run, and the self-test, on the bench; the stage map's measurement procedure (stationary windows, temperature, drift fits, sub-fringe phase from raw samples) still applies.

CLI for the stage

smi-dash stage | stage home | stage step 128 | stage step -2000 --nm | stage move 640
smi-dash stage speed 320 | stage stop | stage off | stage current | stage align
smi-dash stage selftest | stage selftest --status
smi-dash calibrate --beam-safe [--check-pulses 1024] | calibrate --status | calibrate --stop

home, step, move and selftest wait until done (--no-wait returns at once); every verb takes --json. Refusals name the reason, for example ERROR: the stage is not homed: only homing may move it with Hint: Home it first.

What the numbers are

Quantity Value Where it comes from
Laser wavelength 658 nm (HL6501MG) One fringe is half a wavelength of target travel: 329 nm
Sampling 500 ksps total, 250 ksps per channel RP2040 ADC free-running at 48 MHz / 96, round robin over ADC0 and ADC1; channel 2 is sampled 2 us after channel 1
Channel 1 ADC0, pin 31 Monitor photodiode, TIA, offset, gain, anti-alias filter
Channel 2 ADC1, pin 32 External photodiode, same chain
SYNC GPIO15, pin 20 SN74LVC1G17 Schmitt buffer, non-inverting, 100 k pull-down at its input
Anti-alias filter 40.8 kHz pole plus a 44.4 kHz Sallen-Key (Q 0.98) design/calcs.json
Multimode beat 1.46 mm Breaking Taps' first laser; the simulator reproduces it with two longitudinal modes
Laser current set-point 0 to 109.2 mA, 0.027 mA per DAC count, 45-count guard band DAC121C085 on the laser head, 2.5 V reference, written and read back over I2C (control map)
Laser current readback 0.0078 mA per count, 50 readings a second ADS1115 on the laser head across the 2 ohm shunt (control map)
Stage 15.625 nm per pulse nominal, 0 to 1600 pulses, 160 pulses/s default, 640 at most test-stage/design/stage-map.json; J4 GP10 to GP14 (control map stage entry)

The dashboard

Both channels scroll live. Detected fringes are marked along the top of channel 1, teal pointing up for motion away from the laser and purple pointing down for motion towards it; SYNC edges from the motion stage are dashed lines. Below them are the running displacement (with the simulator's ground truth dashed when simulating), a spectrum of both channels, and the readouts. Scroll a channel plot to zoom from 0.1 ms to 2 s; freeze the display and drag to look back.

When the target reverses, the sawtooth's lean flips and so do the markers. This capture caught a reversal and its SYNC pulse in a 50 ms window:

A reversal: sawteeth lean one way, then the other

A sinusoidal move: the count follows the target out and back through zero.

Sine move, 10 um at 1 Hz, returning to zero each cycle

The problem a single-mode laser fixes. With a second longitudinal mode the fringe envelope fades every 1.46 mm of travel, fringes are lost in the fades, and the counted position (solid) walks away from the truth (dashed):

Multimode laser: the fringe amplitude fades every 1.46 mm

Settings live on the server, so the page, the CLI and an AI see the same values:

Settings

Recording

The record button (or smi-dash record start --format csv --seconds 10) saves both channels, SYNC, the fringes and the running displacement.

  • CSV streams to disk: pair,t_s,ch1,ch2,ch1_v,ch2_v,sync,fringe,disp_nm,truth_nm, with a commented header giving the source, rates and detector settings.
  • HDF5 (Linux build) keeps up to 120 s in memory and writes on stop: datasets ch1, ch2, disp_nm, truth_nm, groups fringes/{pair,dir} and sync/{pair,level}, and attributes for the sample rate, the 2 us channel offset, the LSB in volts and the wavelength.

CLI

Every verb prints OK: or ERROR: first and a Hint: with the next command; --json returns {status, data, hints}. The CLI calls the same HTTP endpoints as the page, so anything the page can do, a script or an AI can do.

smi-dash start | show | ls | health | status | stop
smi-dash source sim | source serial [--serial-port COM5]
smi-dash sim --profile constant|sine|step|hand|hold|stage --speed-um-s 1000 --amp-um 10 --freq-hz 1 --c 3 --noise 1 --multimode on|off
smi-dash detect --lp-hz 10000 --threshold 0.35 --invert on|off
smi-dash view --window-ms 20 --history-s 6 --pause | --resume
smi-dash zero
smi-dash record start --format csv|h5 --seconds 10 | record stop | record status
smi-dash ui toast "text" | ui click '#btn-zero' | ui reveal '#s-fps'
smi-dash settings get | settings set fps=30 record_format=h5
smi-dash eval --suite

The board verbs (laser, offset, gain, bias, ctl, board, tune, eval --board) are listed under board 1.3 above, and the stage verbs (stage, calibrate) under the test stage.

Fringe detection, and how well it works

The detector is classical DSP on channel 1:

  1. Low-pass, 2nd-order Butterworth, 10 kHz by default (the Detector LP slider).
  2. Envelope: a decaying running maximum and minimum give the fringe's peak-to-peak.
  3. Edge detection: the difference y[n] - y[n-D], with D matched to the filter's rise time. A run above threshold x peak-to-peak is an edge candidate.
  4. Direction: the sawtooth's sharp edge always runs against its ramp. At higher fringe rates the ramp itself crosses the threshold, with the opposite sign and a smaller size, so candidates are weighed by size squared and only those that agree with the running sign are counted. Each counted edge is one fringe, plus or minus 329 nm.

smi-dash eval --suite runs the simulator and the detector together, 1.5 s per case, and compares the count with the simulator's ground truth. These are the results of that command for this release, not estimates:

Case C Motion LP True fringes Detected Direction errors Final error RMS error Max error
constant 1 mm/s 3 1000 um/s 10 kHz 4557 4556 0 12 nm 380 nm 644 nm
constant 5 mm/s, 10 kHz LP 3 5000 um/s 10 kHz 22797 16892 7303 -671100 nm 1164355 nm 1977628 nm
constant 5 mm/s, 60 kHz LP 3 5000 um/s 60 kHz 22797 22787 0 -2243 nm 2247 nm 2665 nm
constant 10 mm/s, 60 kHz LP 3 10000 um/s 60 kHz 45593 55558 23732 986462 nm 1303766 nm 2853106 nm
sine 5 um, 2 Hz 3 5 um at 2 Hz 10 kHz 185 180 0 0 nm 123 nm 256 nm
sine 50 um, 5 Hz 3 50 um at 5 Hz 10 kHz 4544 4550 0 -2638 nm 1951 nm 3308 nm
step 10 um and return 3 10 um steps 10 kHz 60 60 0 0 nm 99 nm 251 nm
hand jitter 3 1.5 um wander 10 kHz 188 43 0 -21 nm 115 nm 255 nm
very weak feedback C 0.1 0.1 1000 um/s 10 kHz 4557 4560 1 -646 nm 414 nm 871 nm
weak feedback C 0.5 0.5 1000 um/s 10 kHz 4557 4559 0 -317 nm 346 nm 562 nm
C 1.2 1.2 1000 um/s 10 kHz 4557 4559 0 -317 nm 349 nm 566 nm
C 6 6 1000 um/s 10 kHz 4557 4509 0 -12819 nm 9089 nm 13958 nm
noise x10 3 1000 um/s 10 kHz 4557 4556 0 12 nm 379 nm 645 nm
single mode, 2 mm/s over 3 mm 3 2000 um/s 10 kHz 9118 9116 0 -828 nm 885 nm 1044 nm
multimode, 2 mm/s over 3 mm 3 2000 um/s 10 kHz 9118 14756 3921 -725286 nm 399648 nm 725501 nm

How to read it:

  • Resolution is one fringe. Counting resolves 329 nm, so an RMS error of a few hundred nanometres is the expected quantisation, not drift. Where the motion is within the limits below, the error does not grow with travel (12 nm after 4557 fringes at 1 mm/s).
  • Speed limit. Keep the fringe rate below about two thirds of the detector's low-pass corner. At the default 10 kHz that is about 2 mm/s (6 kHz fringes). Raising the corner to 60 kHz carries 5 mm/s with 7 fringes lost in 22,797. At 10 mm/s (30 kHz fringes, about 8 samples per fringe) this detector fails; the board's anti-alias filter passes those fringes, so a faster detector is possible but not built.
  • Feedback. It counts from C 0.1 to about 1.2 in the simulator because the residual asymmetry of the fringe still picks the direction; real weak-feedback signals are noisier than this, so aim for the sawtooth (C above 1). Above about C 4.6 the laser can jump more than one fringe at once, and at C 6 it loses about 1 % of fringes.
  • "True fringes" over-counts small oscillations. It counts every crossing of a half-wavelength boundary, and a tremor across a boundary crosses it many times; the laser's hysteresis rightly ignores those. Judge the hand-jitter and sine rows by the error columns.
  • Multimode is the failure the video describes: fringes vanish in the fades and the count is wrong by hundreds of micrometres.
  • Start-up. A fresh detector needs about 15 ms of fringes to learn the envelope and the jump direction. Fringes in that time are not counted (5 fringes in the serial test below).

The simulator

The laser's excess phase follows the Lang-Kobayashi steady-state equation phi_F = phi_0 - C sin(phi_F + atan(alpha)) with phi_0 = 4 pi L / lambda, solved on its stable branch with hysteresis, so C below 1 gives a near-sinusoid and C above 1 the leaning sawtooth. The power is P0 (1 + m cos phi_F). Multimode adds a second longitudinal mode spaced lambda^2 / (2 x 1.46 mm) = 0.148 nm away, which makes the fringe envelope null every 1.46 mm. Target motions: constant speed with reversals, sine, step and return, a hand-held target (smooth wander plus a 9 Hz tremor), hold, and the test stage's mirror.

The electronics follow the board netlist: photodiode current into the TIA (4.7 k monitor, 47 k external), the 1:2 divider and inverting x20 stage (net gain -10) about the offset trim, the 3.9 k / 1 n pole and the Sallen-Key stage, then the RP2040 ADC with 12-bit quantisation, about 1.3 LSB rms noise and its wide codes at 512, 1536, 2560 and 3584. The simulator runs at 500 kHz and samples channel 1 on even ticks and channel 2 on odd ticks, exactly like the firmware's round robin.

The USB stream

The 16-bit raw stream that dropped packets in the video would need 1 MB/s. This firmware packs each 64-sample block of one channel as its first sample plus 63 zigzag deltas at the smallest bit width that fits, falling back to raw 12-bit when deltas would be wider. On the simulator's realistic signal that is 287 kB/s for both channels together, 4.6 bits per sample with all headers and CRCs, against 750 kB/s for plain 12-bit packing. Frames carry a sync word, type, length, sequence number and CRC-16, and the absolute index of their first sample pair, so a lost frame shows as a counted gap rather than a silent time shift. The format is in firmware/README.md.

What was tested, and what was not

  • The firmware builds with Pico SDK 2.1.1 and arm-none-eabi-gcc 13.2 to smi_pico.uf2 with no warnings.
  • The firmware's packer (firmware/src/smi_frame.c) round-trips 40,000 blocks exactly in firmware/test/test_pack.c, including noise that forces raw blocks, constant blocks and wrapping ramps, and its CRC matches the CRC-16/CCITT-FALSE check value.
  • The dashboard's Rust decoder decodes the C packer's reference stream exactly, resynchronises after garbage and drops a corrupted frame with the gap counted (cargo test).
  • End to end over a serial port: 4 s of simulated samples packed by the firmware's C code and replayed in real time through a pseudo-terminal into smi-dash source serial arrived as 797 frames with no CRC errors, gaps or drops at 498 ksps.
  • Control core (since board 1.2): firmware/test/test_ctl.c runs the firmware's control code against the generated control table, 293 checks: boot defaults and the off state, the interlock key, refusals above the limit and of NaN, the gated write sequence (enable dropped and 2 ms waited before every laser write, the carrier only after a verified nonzero code, the readback right after arming, a failure there tripping), one write per change with the latest request winning and at most four writes a second, the guard band (command 45 disarmed, 46 is DAC code 1, 4095 is 4050), readback mismatches, heartbeat timeout, the overcurrent glitch filter and trip, the zero check before enable, a negative zero code, current-ADC loss, the laser-off-only controls, an expander that does not answer, and a DAC failure.
  • Text commands: firmware/test/text_cmd_test.py sends the contract's text lines through firmware/test/ctl_pty.c (the firmware's control, text and frame code behind a pseudo-terminal) and checks the STATE frames: laser 2000 arms at DAC code 1955, laser current reports the codes, offset B and head and gain disarm first and set their codes, laser 45 stays disarmed and laser 46 is DAC code 1, and an out-of-range code or an over-long line disarms (11 checks; 20 with the stage checks below).
  • Control serial path: the same stand-in, polling the DAC readback every 2 ms like the firmware, driven by smi-dash source serial: laser on with the key, a set-point waited on with --wait (60.00 mA set and read back), an offset refused while armed with the board's rule quoted, 115 mA refused at the 109.16 mA limit, a DAC-counts command mapped through the guard band, about 1,300 readback polls while armed, and killing the dashboard with the laser on turned it off by heartbeat timeout.
  • Controls in the dashboard: the simulated board runs the firmware's own control code; every CLI verb and the Controls tab were exercised against it, including auto-centre and Tune cycling the laser for their writes. controls-tuned.png is from the 1.3.1 build; the laser-off and tuning screenshots are from the 1.2.1 build, whose Controls tab is the same. The Windows build's eval --board output is identical to the Linux build's.
  • Stage core: firmware/test/test_stage.c runs smi_stage.c against a mock TMC2209 (CRC, registers, IFCNT) and a mock screw and HOME switch, 62 checks: disabled at boot, every configuration write made with EN_N high, the driver refused on a dead UART, a wrong version or a stuck IFCNT, the TMC CRC against a published vector, homing from off the switch and from on it, a stuck and a missing switch, limits before and after homing, unexpected HOME, the step rate at 80, 160 and 640 pulses/s, stop mid-move keeping a valid position, duplicate sequence numbers issuing no pulses, the self-test plateaus and dwells, DRV_STATUS faults and link loss.
  • Stage text commands and frames: text_cmd_test.py now also checks the stage through ctl_pty.c (20 checks in all): disabled at boot, a step refused before homing, a speed of 700 refused, home to 0 seen in a STAGE frame of the right size, a move past 1600 refused, 200 pulses at 640 pulses/s, stage current, and stage off invalidating the position.
  • Stage serial path: smi-dash source serial against the stand-in: refused before homing, home, moves to 300, 299, 0 and 1600 (2966 pulses issued, the screw where the firmware thinks it is), and the stage stayed enabled while the dashboard's heartbeats ran, then latched link_lost and disabled after kill -9 of the dashboard.
  • Stage dashboard: the simulated stage runs the firmware's stage code; every stage verb, the Stage tab, the self-test and Calibrate were run against it, and the stage screenshots and clips are from those runs.
  • Not yet run on a physical RP2040 or board. No hardware was available. The DMA ring, the SYNC capture timing and the USB throughput on the RP2040 itself are untested; check the STATUS frame's dropped-buffer count (shown in the dashboard's status bar) on first use. The DAC121C085, DAC7574, MCP23008 and ADS1115 drivers follow their datasheets, the control map and the board's own controller patch, but have not talked to real parts: check smi-dash board (head_io and head_adc in the INFO line, the measured current at zero) at first power-up, before enabling the laser. The firmware keeps the 2 ms readback going during USB waits, but its timing on the RP2040 under full streaming load is untested, and the head watchdog's timeout is still being qualified by the board design. The stage driver has never moved a motor: the bit-banged half-duplex UART (with interrupts off for each 87 us byte), the DIR polarity, the HOME switch, the step timing under streaming load and the winding current all need checking at commissioning, with the laser interlock active, as the stage page says.

Building from source

# control table, from the board's control map (writes firmware/src/smi_controls_gen.h and dashboard/assets/controls.json)
python3 controls/gen_controls.py controls/control-map.json

# firmware
export PICO_SDK_PATH=/path/to/pico-sdk        # 2.1.1, with lib/tinyusb
cmake -S firmware -B firmware/build -DCMAKE_BUILD_TYPE=Release
cmake --build firmware/build                  # firmware/build/smi_pico.uf2

# dashboard (Linux needs libudev-dev and libhdf5-dev)
cd dashboard && cargo build --release         # target/release/smi-dash
cargo build --release --target x86_64-pc-windows-gnu --no-default-features   # Windows, CSV only
cargo test --release

# host tests
cc -O2 -Ifirmware/src firmware/test/test_stage.c firmware/src/smi_stage.c -o test_stage && ./test_stage
cc -O2 -Ifirmware/src firmware/test/test_ctl.c firmware/src/smi_ctl.c -lm -o test_ctl && ./test_ctl

MIT licence, as the rest of this page.