Python VCD File Support

0.4.1 · active · verified Fri Apr 17

pyvcd is a Python library designed for working with Value Change Dump (VCD) files. It provides functionalities for both reading and writing these standard files used to record signal activity in digital logic simulations. The current version is 0.4.1, and releases are generally made on an as-needed basis for bug fixes or minor enhancements.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to create a VCD file, define a module scope, declare signals (wires), and record their value changes over time using `VCDWriter`.

from datetime import datetime
from pyvcd import VCDWriter

# Create a VCD file named 'test.vcd'
with VCDWriter(open('test.vcd', 'w'), timescale='1 ns', date=datetime.now()) as writer:
    # Enter a scope named 'top' of type 'module'
    scope = writer.scope_stack.enter_scope('top', 'module')
    
    # Define a 1-bit 'clk' wire and change its value over time
    writer.change(scope.var('clk', 'wire', 1), 0, 0)   # At time 0, clk is 0
    writer.change(scope.var('clk', 'wire', 1), 1, 100) # At time 100 ns, clk is 1
    writer.change(scope.var('clk', 'wire', 1), 0, 200) # At time 200 ns, clk is 0
    
    # Define another 1-bit 'rst_n' wire
    writer.change(scope.var('rst_n', 'wire', 1), 1, 0)
    writer.change(scope.var('rst_n', 'wire', 1), 0, 100)
    writer.change(scope.var('rst_n', 'wire', 1), 1, 200)
    
    # Leave the current scope
    writer.scope_stack.leave_scope()

print("VCD file 'test.vcd' generated successfully.")

view raw JSON →