This project is a self contained repo meant to design and test a self-trigger feature for the following larger FPGA project: module_test_fw which firmware is used to develop and test front-end electronics for the endcap regions of the new MIP Timing Detector for the CMS Experiment at CERN.
Self-Trigger is a VHDL design with cocotb test-bench simulations that monitors the trigger uplink data of multiple ETROCs. It masks repeatedly occuring βflashingβ bits coming from ETROC words and issues a Level-1 Accept (L1A) trigger whenever a real hit is observed.
It is meant as a compact, simulation-ready solution with:
| Area | Information |
|---|---|
| FPGA design | per ETROC hit rate counters and configurable bit-slipping, Multi-rate data path (320 / 640 / 1280 Mbit sβ»ΒΉ) |
| Verification | Python-driven cocotb tests, self-checking scoreboards, parameter scan, randomised stimulus input |
| Continuous Integration | One-command pytest launches GHDL + cocotb simulations for every HDL unit |
self-trigger/
βββ README.md
βββ pytest.ini β pytest settings
βββ requirements.txt β Python dependencies
βββ src
βββ hdl β VHDL RTL
β βββ Top.vhd β Top-level wrapper (instantiates `self_trig`)
β βββ bitslip.vhd β bit-slipper
β βββ def_pkg.vhd β Types & constants for simulation
β βββ flash.vhd β Flashing-bit detector / clearer
β βββ rate_counter.vhd
β βββ trigger_rx.vhd β L1A generator w/ Hit rate counter + bitsliping and multi-rates
βββ tests β Python simulation test-benches
βββ test_Top.py
βββ test_bitslip.py
βββ test_flashbit.py
Note: All HDL files follow VHDL-2008 syntax; simmulation tests rely on GHDL to run.
Prerequisites
| Tool | Tested version(s) |
|---|---|
| Python | β₯ 3.9 |
| GHDL | 4.0-dev (LLVM or mcode) |
| GTKWave | 3.3.x (for waveform viewing) |
Note: GTKWave is optional
# 1. Clone the repo
git clone https://github.com/your-org/self-trigger.git
cd self-trigger
# 2. Set up a Python virtualenv (recommended but optional)
python -m venv .venv # or use conda/mamba
source .venv/bin/activate
pip install -r requirements.txt # installs cocotb, cocotb-test, pytest β¦
# 3. Run the complete simulation suite
pytest # will compile RTL with GHDL and run all cocotb tests
# 4. Inspect waveforms (optional)
# Each test dumps a .ghw (GHDL wave) in the local directory
gtkwave *.ghw &Detects the flashing bit which is a periodic 1 β 0 β 1 β 0 toggle every FLASH_PERIOD = 3546 clock cycles, over any bit position within an ETROC word. After observing THRESHOLD successive toggles, the module:
- Sets
active_o = '1' - Forces the flashing bit to 0 on the output
data_o
- Bitslip stage β aligns data words by
slip_ibits (one instance per ETROC & data-rate). - Enable mask β only allows triggers from enabled ETROCs.
- Reduction tree β OR-reduces 8 / 16 / 32-bit chunks to detect any hit bit based on ETROC operaiton rate.
- Rate counters β per-ETROC hit rate (free-running up-counters).
- Trigger output β per single clock, synchronous L1A.
Wire-up of:
- Three-rate flash-bit detector array
- An adaptive mask generator which only allows triggers from ETROCs while their flash-cleaner is active
- The trigger receiver
Generics:
| Name | Default | Meaning |
|---|---|---|
NUM_ETROCS |
28 |
Number of ETROC board |
UPLINK_WIDTH |
224 |
Total uplink bits (8 Γ NUM_ETROCS) |
FLASH_PERIOD |
3546 |
Clock cycles for one flash toggle |
THRESHOLD |
10 |
Toggles until cleaner becomes active |
| Test file | DUT | Purpose |
|---|---|---|
test_bitslip.py |
bitslip.vhd |
bit slip/edge cases + random input patterns |
test_flashbit.py |
flash_bit.vhd |
Searches every bit position, confirms clearing |
test_Top.py (aka self_trig_tb) |
self_trig.vhd |
System-level: β’ Test1 zero-hit sanity β’ Test2 periodic hits & trigger counting |
All tests share a 10 ns clock (100 MHz) in simulation.
- Change generics β open
src/hdl/Top.vhdl. Most widths & thresholds are top-level generics. - Simulationβonly knobs β environment variables in
tests/*.py(SIM,GHDL_FLAGS, β¦).
- Naomi Gonzalez β main testbench author and RTL design engineer
- Evaldas Juska β RTL design engineer for
rate_counter.vhdandbitslip.vhd