Skip to content

Understanding Waveforms

Waveforms are the primary way to debug and verify digital circuits. They show how signal values change over time (clock cycles).

Hardcaml’s waveform output uses ASCII art:

β”ŒSignalsβ”€β”€β”€β”€β”€β”€β”€β”€β”β”ŒWaves──────────────────────────────────────────────┐
β”‚clock β”‚β”‚β”Œβ”€β”€β” β”Œβ”€β”€β” β”Œβ”€β”€β” β”Œβ”€β”€β” β”Œβ”€β”€β” β”Œβ”€β”€β” β”Œβ”€β”€β” β”Œβ”€β”€β” β”Œβ”€β”€β”‚
β”‚ β”‚β”‚ β””β”€β”€β”˜ β””β”€β”€β”˜ β””β”€β”€β”˜ β””β”€β”€β”˜ β””β”€β”€β”˜ β””β”€β”€β”˜ β””β”€β”€β”˜ β””β”€β”€β”˜ β”‚
β”‚clear β”‚β”‚ β”‚
β”‚ ││────────────────────────────────────────────────── β”‚
β”‚enable ││────────────────────────────────────────────────── β”‚
β”‚ β”‚β”‚ β”‚
β”‚ ││────┬────┬────┬────┬────┬────┬────┬────┬────┬────┬─│
β”‚out β”‚β”‚ 00 β”‚ 01 β”‚ 02 β”‚ 03 β”‚ 04 β”‚ 05 β”‚ 06 β”‚ 07 β”‚ 08 β”‚ 09 β”‚ β”‚
β”‚ ││────┴────┴────┴────┴────┴────┴────┴────┴────┴────┴─│
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

1-bit signals show high/low transitions:

  • ────── - Signal is high (1)
  • (blank) - Signal is low (0)
  • β”Œβ”€β”€β” β”Œβ”€β”€β” - Clock toggling

Multi-bit signals show hex values:

  • β”‚ 00 β”‚ 01 β”‚ 02 β”‚ - Values in each cycle
  • ────┴────┴──── - Value changes

Control waveform appearance with options:

Waveform.expect
~display_height:20 (* More vertical space *)
~display_width:80 (* Wider display *)
~wave_width:2 (* Wider waves per cycle *)
waves

By default, all signals are shown. Select specific signals:

Waveform.expect
~display_rules:
[ Display_rule.port_name_is "out"
; Display_rule.port_name_is "enable"
]
waves
  1. Count cycles - Each vertical bar marks a clock edge
  2. Watch edges - Outputs change after the clock edge that triggered them
  3. Check setup - Inputs must be stable before the clock edge

For complex debugging, download VCD files and open in GTKWave:

  1. Click Download VCD in the IDE
  2. Open in GTKWave or other waveform viewer
  3. Zoom, measure, and analyze signals
  • Nand2Tetris - Apply these skills building real circuits