Sitemap
Life is a SoC

Life is a SoC

An anime, Dance, Music, Comedy, Martial Arts nerd. So sharing some of concepts on a various levels as I go along my SoC Design Journey. Do what makes you happy.

Getting Started with RTL Design: Setup, Code, and Implement

3 min readAug 3, 2024

--

Introduction

Register-Transfer Level (RTL) design is a key step in digital circuit design, providing a detailed representation of a system’s data flow and logic operations. RTL designs are typically written in hardware description languages (HDLs) like Verilog or VHDL. This article will guide you through setting up an RTL design environment on your computer, writing a simple Verilog program, and simulating it.

Prerequisites

Before we begin, ensure that you have the following:

  • Verilog Compiler/Simulator: We’ll use Icarus Verilog, a popular open-source Verilog compiler and simulator.
  • GTKWave: A waveform viewer for visualizing simulation results.
  • Git: A version control system to clone repositories. You can download it from Git’s official website.

Setting Up the RTL Design Environment

Step 1: Install Icarus Verilog

  1. Linux:
  • You can install Icarus Verilog using your package manager. For example, on Ubuntu, use:
sudo apt update
sudo apt install iverilog

Windows:

  • Download the Windows installer from the Icarus Verilog website.
  • Follow the installation instructions provided.

macOS:

  • Use Homebrew to install Icarus Verilog:
brew install icarus-verilog

Step 2: Install GTKWave

  1. Linux:
  • Install GTKWave using your package manager. For example, on Ubuntu, use:
sudo apt install gtkwave

Windows:

  • Download the Windows installer from the GTKWave website.
  • Follow the installation instructions provided.

macOS:

  • Use Homebrew to install GTKWave:
brew install gtkwave

Writing and Simulating Your First RTL Design

Step 1: Write a Simple Verilog Program

Create a directory for your project and a file named simple_adder.v with the following code:

// A simple 2-bit adder module
module simple_adder (
input wire [1:0] a, // 2-bit input a
input wire [1:0] b, // 2-bit input b
output wire [2:0] sum // 3-bit output sum
);

assign sum = a + b; // Add inputs a and b

endmodule

Create a testbench file named testbench.v to simulate the simple_adder module:

`timescale 1ns/1ps

module testbench;

reg [1:0] a;
reg [1:0] b;
wire [2:0] sum;

// Instantiate the simple_adder module
simple_adder uut (
.a(a),
.b(b),
.sum(sum)
);

initial begin
// Initialize inputs
a = 2'b00;
b = 2'b00;

// Monitor changes to inputs and output
$monitor("Time: %0t | a: %b, b: %b, sum: %b", $time, a, b, sum);

// Stimulus for the test
#10 a = 2'b01; b = 2'b01;
#10 a = 2'b10; b = 2'b01;
#10 a = 2'b11; b = 2'b11;

#10 $finish; // End simulation
end

endmodule

Step 2: Compile and Simulate the Verilog Program

  1. Compile the Verilog Files: Use Icarus Verilog to compile the simple_adder and testbench:
iverilog -o simple_adder_tb simple_adder.v testbench.v
  • This command compiles the Verilog files and produces an output file named simple_adder_tb, which is the executable for simulation.

Run the Simulation: Execute the compiled testbench to simulate the design:

vvp simple_adder_tb

You should see output similar to this in the terminal

Time: 0 | a: 00, b: 00, sum: 000
Time: 10 | a: 01, b: 01, sum: 010
Time: 20 | a: 10, b: 01, sum: 011
Time: 30 | a: 11, b: 11, sum: 110

Step 3: View the Waveforms

  1. Generate the Waveform File: Modify the testbench to dump waveforms into a file named waveform.vcd by adding the following lines to the initial block:
initial begin
$dumpfile("waveform.vcd");
$dumpvars(0, testbench);
// Existing testbench code...
end

Recompile and Rerun the Simulation: Recompile the Verilog files and rerun the simulation to generate the VCD file:

iverilog -o simple_adder_tb simple_adder.v testbench.v
vvp simple_adder_tb

View the Waveforms with GTKWave: Open the waveform viewer and load the waveform.vcd file:

gtkwave waveform.vcd
  1. You can now view the waveforms for inputs a and b, and the output sum, providing a visual representation of the simulation results.

Conclusion

Congratulations! You have successfully set up an RTL design environment on your computer, written a simple Verilog program, and simulated it using Icarus Verilog. This guide provides a foundation for exploring more complex RTL designs and simulations. With RTL design, you can model and verify digital circuits at the logic gate level, enabling you to develop efficient and reliable hardware systems.

Get Life is a SoC’s stories in your inbox

Join Medium for free to get updates from this writer.

As you progress, consider exploring additional features of Verilog and experimenting with more complex designs and testbenches to deepen your understanding of RTL design.

Happy designing!

Want to know more about SystemC, Virtual Prototyping, HLS for next generation for SoC and performance modelling. Checkout my learn-systemc website for more details

--

--

Written by Life is a SoC

An anime, Dance, Music, Comedy, Martial Arts nerd. So sharing some of concepts on a various levels as I go along my SoC Design Journey. Do what makes you happy.