Claude
Skills
Sign in
Back

wavejson

Included with Lifetime
$97 forever

Generate WaveJSON timing diagrams for digital signals and create HTML viewers to display them. Use when documenting signal timing, creating timing diagrams, analyzing protocol sequences, visualizing digital waveforms (clock, data, control signals), or displaying/rendering WaveDrom diagrams locally.

Web Dev

What this skill does


# WaveJSON Timing Diagram Generator

Generate WaveJSON format timing diagrams for WaveDrom rendering. Perfect for documenting hardware interfaces, signal timing, protocol sequences, and any digital signal visualization.

**Format Reference:** This skill uses the [WaveJSON specification](https://github.com/wavedrom/schema/blob/master/WaveJSON.md)
and [WaveDrom](https://github.com/wavedrom/wavedrom) rendering engine, both licensed under MIT.

**Additional Resources:**
- `reference.md` - Quick reference card with wave characters, common patterns, detailed signal pattern examples, and validation checklist

## Important

- Keep signal names short, space is at a premium

## WaveJSON Format Overview

WaveJSON uses JSON to describe timing diagrams with these key components:

### Signal Object Structure

```json
{
  "signal": [
    { "name": "clk",  "wave": "p......." },
    { "name": "data", "wave": "x.345x..", "data": ["head", "body", "tail"] },
    { "name": "req",  "wave": "0.1...0." }
  ]
}
```

### Wave Characters

**Clock waves:**
- `p` - positive edge clock (rising edge)
- `n` - negative edge clock (falling edge)
- `P` - positive edge with arrow
- `N` - negative edge with arrow

**Logic levels:**
- `0` - low level
- `1` - high level
- `.` - extends previous state

**Data values:**
- `=` - data value (color 2)
- `2`, `3`, `4`, `5` - data values with different colors
- `x` - undefined/don't care
- `z` - high impedance (tri-state)
- `u` - pull-up
- `d` - pull-down

**Special:**
- `|` - extend cycle and add gap

### Signal Properties

- `name` - Signal label (string)
- `wave` - Timing pattern (string, one char per cycle)
- `data` - Array of labels for data values (corresponds to `=`, `2`-`5` in wave)
- `period` - Signal repetition period (number)
- `phase` - Phase shift, positive=future, negative=delay (number)
- `node` - Markers for arrows: `.` (none), `A-Z` (invisible), others (visible)

### Signal Groups

Create hierarchical groups by using arrays with a label string:

```json
{
  "signal": [
    ["Control Signals",
      { "name": "LE",  "wave": "01.0...." },
      { "name": "WR",  "wave": "1..01.0." }
    ],
    ["Data Bus",
      { "name": "D[7:0]", "wave": "x.3.4..x", "data": ["CTRL", "DATA"] }
    ]
  ]
}
```

### Edges (Arrows)

Add dependency arrows between signal markers:

```json
{
  "signal": [...],
  "edge": [
    "a~>b Setup time",
    "c-~d Hold time",
    "e~|~f Pulse width"
  ]
}
```

**Edge syntax:**
- First char: source node (from `node` property)
- Last char: destination node
- `>` before last char: arrow head
- Shape: `-` (horizontal), `|` (vertical), `~` (curvy), `/` (diagonal)
- `#` marks label position
- Text after first word: arrow label

### Config

```json
{
  "signal": [...],
  "config": { "hscale": 2 }
}
```

- `hscale` - Horizontal scale (≥1, default 1)

## Generating HTML Viewers

Create local HTML files to render WaveJSON diagrams using the WaveDrom library.

### When to Generate HTML Viewers

Generate an HTML viewer when:
- User wants to "view", "display", "render", or "visualize" a diagram locally
- User wants to save diagrams for documentation
- User needs to see multiple diagrams on one page
- User wants an offline/local viewer instead of online editor

### HTML Template Structure

```html
<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>WaveDrom Timing Diagram</title>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/wavedrom/3.1.0/skins/default.js" type="text/javascript"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/wavedrom/3.1.0/wavedrom.min.js" type="text/javascript"></script>
  <style>
    body {
      font-family: Arial, sans-serif;
      margin: 20px;
      background-color: #f5f5f5;
    }
    h1, h2 {
      color: #333;
    }
    .diagram-container {
      background: white;
      padding: 20px;
      margin: 20px 0;
      border-radius: 5px;
      box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    }
  </style>
</head>
<body onload="WaveDrom.ProcessAll()">
  <h1>Timing Diagrams</h1>

  <div class="diagram-container">
    <h2>Diagram Title Here</h2>
    <script type="WaveDrom">
    {
      "signal": [
        { "name": "clk", "wave": "p......." },
        { "name": "data", "wave": "x.345x..", "data": ["head", "body", "tail"] }
      ]
    }
    </script>
  </div>

  <!-- Add more diagrams by adding more diagram-container divs -->

</body>
</html>
```

### Multi-Diagram HTML Template

For pages with multiple timing diagrams:

```html
<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>Hardware Timing Reference</title>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/wavedrom/3.1.0/skins/default.js" type="text/javascript"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/wavedrom/3.1.0/wavedrom.min.js" type="text/javascript"></script>
  <style>
    body {
      font-family: Arial, sans-serif;
      margin: 20px;
      background-color: #f5f5f5;
    }
    h1 { color: #333; }
    h2 { color: #555; margin-top: 0; }
    .diagram-container {
      background: white;
      padding: 20px;
      margin: 20px 0;
      border-radius: 5px;
      box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    }
    .description {
      color: #666;
      margin: 10px 0;
      font-size: 14px;
    }
  </style>
</head>
<body onload="WaveDrom.ProcessAll()">
  <h1>Project Timing Diagrams</h1>

  <div class="diagram-container">
    <h2>Two-Phase Write Sequence</h2>
    <p class="description">Shows the complete writeByte() operation with control latch and character write.</p>
    <script type="WaveDrom">
    { /* First WaveJSON here */ }
    </script>
  </div>

  <div class="diagram-container">
    <h2>Control Word Timing</h2>
    <p class="description">D7 clear bit requires 1.0µs delay per PD2437 datasheet.</p>
    <script type="WaveDrom">
    { /* Second WaveJSON here */ }
    </script>
  </div>

</body>
</html>
```

### HTML Generation Workflow

When user requests HTML viewer:

1. **Generate or use existing WaveJSON** for the timing diagram(s)
2. **Create HTML file** using the template above
3. **Embed WaveJSON** in `<script type="WaveDrom">` tags
4. **Add descriptive titles** (h2) and descriptions for each diagram
5. **Save to appropriate location** (suggest `docs/timing_diagrams.html`)
6. **Offer to open** in browser using `open` command (macOS) or `xdg-open` (Linux)

### Opening HTML in Browser

After creating the HTML file:

```bash
# macOS
open /path/to/timing_diagrams.html

# Linux
xdg-open /path/to/timing_diagrams.html

# Windows (Git Bash)
start /path/to/timing_diagrams.html
```

### Example HTML Generation

**User request:** "Create an HTML page showing the SPI transfer timing"

**Claude should:**
1. Generate (or retrieve) the WaveJSON for SPI transfer
2. Create HTML file with WaveDrom CDN scripts
3. Embed the WaveJSON in `<script type="WaveDrom">` tag
4. Add meaningful title and description
5. Save to `docs/spi_transfer_timing.html`
6. Ask if user wants to open it in browser

### Suggested File Locations

- Single diagrams: `docs/timing_[description].html`
- Protocol reference: `docs/protocol_timing.html`
- Interface-specific: `docs/[interface]_timing.html`
- Complete hardware reference: `docs/hardware_timing.html`

### Including Multiple Diagrams

When creating comprehensive timing documentation:

1. **Group related diagrams**: Organize by protocol, interface, or functional block
2. **Add navigation**: Consider adding a table of contents for pages with 5+ diagrams
3. **Include code references**: Link to specific functions or modules in descriptions
4. **Add context**: Explain timing requirements, constraints, and why they matter

### Validation Before Opening

Before generating HTML:
- Ensure WaveJSON is valid (proper JSON syntax)
- Test WaveJSON in online editor if uncertain
- Check that all required CDN scripts are included
- Verify `onload="WaveDrom.ProcessAll()"` is present in `<body>` tag
- Confirm `<script type="WaveDrom">` tags are properly formed

### WaveDrom CDN Ver

Related in Web Dev