Learn MYHDL with Real Code Examples

Updated Nov 27, 2025

Explain

MyHDL uses Python to model digital logic, finite state machines, and synchronous/asynchronous circuits.

Supports simulation, testing, and verification of hardware designs before synthesis.

Can convert Python-based designs to synthesizable VHDL or Verilog for FPGA or ASIC implementation.

Enables testbench creation and automated verification using standard Python libraries.

Widely used for teaching digital design, rapid prototyping, and bridging software-hardware development.

Core Features

Signals and signal types for hardware modeling

@always, @always_comb, @always_seq decorators for processes

Conversion functions to generate VHDL/Verilog

Simulation engine with time-based event scheduling

Testbench creation using Python scripts and assertions

Basic Concepts Overview

Signal - represents a wire, register, or variable in hardware

Process - a block of hardware logic triggered by signals

Decorators - `@always`, `@always_comb`, `@always_seq` to define processes

Simulation - execution of design over time to validate behavior

Conversion - transforming Python design into VHDL or Verilog

Project Structure

Python source files (.py) for hardware modules

Testbench files for simulation and verification

Scripts to convert designs to HDL

Optional simulation logs and waveform output files

Integration with version control and CI pipelines

Building Workflow

Define signals and modules representing hardware components

Use decorators to define combinational/sequential logic

Write Python-based testbenches to validate behavior

Run simulation to verify design correctness

Convert to VHDL/Verilog for FPGA or ASIC implementation

Difficulty Use Cases

Beginner: Model simple combinational logic

Intermediate: Sequential circuits with finite state machines

Advanced: Multi-module FPGA designs with testbenches

Expert: Generate optimized HDL for synthesis

Architect: Large-scale digital systems and verification automation

Comparisons

MyHDL vs VHDL/Verilog: Python-based, faster prototyping, automatic conversion

MyHDL vs Cocotb: MyHDL for design + simulation, Cocotb mainly for testbenches

Python vs traditional HDL: Higher-level abstraction, easier verification

MyHDL vs SystemVerilog: Less feature-rich, more Pythonic

Simulation speed: native HDL simulators faster, MyHDL easier for rapid prototyping

Versioning Timeline

2003 - MyHDL development started by Jan Decaluwe

2005 - Early Python-based HDL simulation features introduced

2010 - Conversion to VHDL and Verilog added

2015 - Enhanced testbench and simulation support

2020 - Improved Python 3 compatibility and library integration

2025 - Continued updates for FPGA prototyping and verification workflows

Glossary

MyHDL - Python-based hardware description language

Signal - Wire, register, or bus in hardware design

Process - Block of hardware logic executed on signal events

Decorator - Python syntax for defining combinational/sequential blocks

Conversion - Translation from Python to VHDL/Verilog