Skip to content

About

Web interface for a DE2 FPGA coincidence counter (quantum optics: A, B, AB, C, AC, BC)

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

de2AlteraOptics

Web interface for a DE2 (Altera Cyclone II) FPGA coincidence counter, as used in undergraduate quantum-optics labs (Galvez / Beck style): singles A, B, coincidences AB, and, behind a toggle, a third detector C with AC, BC, ABC and the heralded g⁽²⁾(0).

Packet format: docs/protocol.md.

Quick start (no install)

  1. Connect the DE2's RS-232 port to the PC with a USB-to-RS232 adapter that Windows 11 supports (see Hardware).
  2. Open https://openphysics.github.io/de2AlteraOptics/ in Chrome or Edge.
  3. Set Data source to USB serial (Web Serial), click Connect and pick the adapter's COM port (e.g. USB Serial Port (COM11)).

A and B should start counting. Chrome remembers the permission, so after the first time it is one click per session.

DE2 RS-232 ──► FTDI USB-RS232 adapter ──► Windows COM port ──Web Serial──► browser

Hardware

  • Adapter: a standard (not null-modem) USB-to-RS232 adapter with a DB9 end, built on a genuine FTDI FT232R chip. Windows installs the driver automatically. Check in Device Manager → Ports → Properties → Details → Hardware Ids that it shows VID_0403. Newer Prolific chips (PL2303GT/GS/GC) also work.
  • Avoid: old Prolific PL2303TA/HXA adapters (Windows 11's driver refuses them: "PL2303TA DO NOT SUPPORT WINDOWS 11"), unbranded no-name cables, TTL/3.3 V "USB-serial" boards, and null-modem/DCE adapters such as the StarTech ICUSB232FTN (transmit and receive are crossed).
  • Settings: 19200 baud, 8N1, no flow control (the page sets these).

Data sources

Source Needs Browsers
USB serial (Web Serial), the recommended one an adapter with a working OS driver (above) Chrome, Edge
Local bridge npm run bridge on the lab PC; the page reads http://localhost:8787 Chrome, Edge, Firefox (Chrome may ask to allow local-network access)
Simulator nothing: simulated heralded single-photon source any

Fallback: local bridge (Linux / WSL)

Use this when the browser cannot open the adapter: Firefox/Safari, or an adapter whose Windows driver is blocked. server/bridge.ts (plain Node, no native modules) reads a serial device and streams decoded packets to the page over Server-Sent Events.

DE2 RS-232 ──► USB adapter ──► /dev/ttyUSB0 ──► server/bridge.ts ──SSE──► browser

Under WSL2 the adapter must first be passed through with usbipd-win, in an admin PowerShell:

usbipd list                          # find the adapter's BUSID
usbipd bind --busid <BUSID>          # once
usbipd attach --wsl --busid <BUSID>  # after every replug / WSL restart

While attached to WSL the adapter is invisible to Windows (and to Web Serial). usbipd detach --busid <BUSID> gives it back.

Linux's pl2303 driver still supports PL2303TA chips, so this route also rescues an old Prolific cable.

Development

npm install
npm run dev          # page + bridge on /dev/ttyUSB0  → http://localhost:5173
npm run dev:sim      # page + simulated board
npm start            # build + standalone bridge/page on http://localhost:8787

Bridge options (flags for node server/bridge.ts, or env vars for npm run dev): --device / DE2_DEVICE, --baud / DE2_BAUD, --simulate / DE2_SIMULATE=1, --capture file.bin / DE2_CAPTURE (save the raw byte stream), --port / PORT.

The page

  • Integration time 0.1–60 s (multiples of the 100 ms FPGA gate).
  • Rates with Poisson errors, counts N in the window.
  • Accidentals R₁R₂Δt, net rate and coincidence-to-accidental ratio for each coincidence. Calibrate Δt sets Δt = R_AB/(R_A R_B) from the last window. Use it only with no true pairs, e.g. a long cable delay in one arm.
  • Third detector toggle: C, AC, BC, ABC and g⁽²⁾(0) = N_A N_ABC / (N_AB N_AC).
  • Strip charts, Record → Download CSV (mapped and raw counters).
  • Raw counters & channel mapping: live values of all 8 counters and an editable counter → channel map (saved in the browser).

CI / deploy

  • .github/workflows/ci.yml: lint, typecheck, tests, build, plus a simulator smoke test of the bridge (stream, CORS allow/deny), on every push and PR.
  • .github/workflows/deploy.yml: builds and publishes dist/ to GitHub Pages on every push to main.

The bridge only accepts cross-origin requests from https://openphysics.github.io and localhost; add more with DE2_ALLOW_ORIGIN="https://a.example,…". It binds to localhost only.

Checks

npm run lint && npm run check && npm test && npm run build

About

Web interface for a DE2 FPGA coincidence counter (quantum optics: A, B, AB, C, AC, BC)

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages