Menu
Coddy logo textTech

Timescale Directive

Part of the Fundamentals section of Coddy's Verilog journey. Lesson 70 of 90.

The timescale directive sets the time unit and time precision for simulation. It tells the simulator how to interpret delay values like #10.

In previous lessons, we used delays like #10 without specifying what "10" means. Is it 10 nanoseconds? 10 picoseconds? The timescale directive answers this question.

Syntax:

`timescale time_unit / time_precision
PartMeaningExample
time_unitThe basic unit for delays1ns
time_precisionHow precise simulation should be1ps

The backtick ` before timescale means it is a compiler directive.

Example

`timescale 1ns / 1ps
  • time_unit = 1ns#10 means 10 nanoseconds
  • time_precision = 1ps → Simulation rounds to the nearest picosecond

Common Timescale Values

Time UnitPrecisionUse Case
1ns / 1nsNanosecondSimple simulations
1ns / 1psPicosecondMore precise
1ps / 1psPicosecondHigh-speed designs
1us / 1nsMicrosecondSlow simulations

How It Affects Delays

`timescale 1ns / 1ps

initial begin
  #10 a = 1;   // Waits 10 nanoseconds
end

Without timescale, some simulators assume a default (often 1ns). It is best to always specify it.

Important Rules

RuleExplanation
Must be outside modulesPlaced before any module definition
Backtick symbol`timescale not 'timescale 
Time unit ≥ time precision1ns / 1ps is fine, 1ps / 1ns is not
Affects all delays in the fileGeneral delays, gate delays, assignment delays
challenge icon

Challenge

What to do:

Add the missing timescale directive to make the delays represent 10ns, 20ns, and 30ns.

Try it yourself

// TODO: Add timescale directive (1ns / 1ps)

module timescale_challenge;
  
  initial begin
    $display("Time %0t", $time);
    #10 $display("Time %0t (10ns = 10000ps)", $time);
    #10 $display("Time %0t (20ns = 20000ps)", $time);
    #10 $display("Time %0t (30ns = 30000ps)", $time);
    $finish;
  end
endmodule
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals

Practice on your own: Online Verilog compiler