Verilog basics

Learn Verilog

Build a practical foundation in digital design, simulation, and self-checking testbenches.

What you will learn

Work through the lessons in order. Each lesson introduces one idea, shows a focused example, explains the important lines, and gives you a practical exercise.

Start with the learning path

Verilog describes hardware behavior. You will learn how modules, signals, combinational logic, sequential logic, and testbenches work together before moving into SystemVerilog and UVM.

Lesson 6 of 7: Write a Verilog Testbench

Instantiate a design, generate a clock, apply inputs, and finish a simulation.

module counter_tb;
  reg clk = 0;
  reg reset;
  wire [3:0] count;

  counter dut (.clk(clk), .reset(reset), .count(count));

  always #5 clk = ~clk;

  initial begin
    reset = 1;
    #10 reset = 0;
    #80 $finish;
  end
endmodule

What to notice

  • dut is an instance of the counter module.
  • The clock toggles every five simulation time units.
  • initial runs once to apply reset and stop the simulation.
Practice: Use $display to print count after reset is released and after four clock cycles.

How to study each lesson

  1. Read the concept before copying the example.
  2. Predict the output or waveform before running the simulator.
  3. Change one input, parameter, or statement and observe the result.
  4. Use a self-checking assertion or comparison whenever possible.
  5. Keep the smallest working example as evidence for the next lesson.