How to print `timescale in Verilog, SystemVerilog and VHDL

Sometimes you need to make sure the correct time unit and precision are applied for each module down the instance tree, especially when there are different timescale directives in different modules and timescale arguments are used.

Print `timescale in Verilog, SystemVerilog

Use $printtimescale(path) simulator directive:

// timescale
`timescale 1ns/10ps

// top testbench module
module tb();

   // DUT instance
   dut dut_i();

   initial begin
      $printtimescale($root.tb); // prints the timescale of this module
      $printtimescale($root.tb.dut_i);// prints the timescale dut_i module instance
      $printtimescale($root.tb.dut_i.cpu_i);// prints the timescale dut_i.cpu_i module instance
   end 

endmodule

Print `timescale in VHDL

For VHDL you need to wrap the initial begin end statement in a dummy module:


module timescale_printer();
   initial begin
      $printtimescale($root.tb); // prints the timescale of this module
      $printtimescale($root.tb.dut_i);// prints the timescale dut_i module instance
      $printtimescale($root.tb.dut_i.cpu_i);// prints the timescale dut_i.cpu_i module instance
   end
endmodule

and instantiate it:



-- VHDL library declarations
library ieee;
use ieee.std_logic_1164.all;

LIBRARY DUT;
USE DUT.ALL;

LIBRARY tb;
USE tb.all;

-- declaration of tb entity
ENTITY tb IS
END;

-- implementation of the testbench
architecture rtl of tb is

-- declaration of timescale_printer component
COMPONENT timescale_printer is PORT ();
END COMPONENT timescale_printer;

-- declaration of dut component
COMPONENT dut is PORT ();
END COMPONENT dut;

begin

-- instance of the DUT; I skipped signal connections for the example's simplicity sake
dut_i : dut PORT_MAP();

-- instance of the timescale_printer component
timescale_printer_i : timescale_printer PORT MAP();

end rtl;

Results

The output of a run should be similar to:

Time scale of (tb) is  1ps /  1fs
Time scale of (tb.dut_i) is  1ps /  1ps
Time scale of (tb.dut_i.cpu_i) is  1ns /  10ps

Notes

If you are not at ease with timescales, you can take a 2 minute tutorial here.

I omitted DUT’s port declarations and connections for brevity.

Comments

4 Responses

  1. Hi, is it supported in Xilinx Vivado. I have tried something similar but had the message below:

    ERROR: [XSIM 43-3138] “D:/Enman/fpga/programmer_beginner/vhdl/hello_world/tb/modules.sv” Line 3. Cross Language Hierarchical name($root.tb) is not supported in this context.
    ERROR: [XSIM 43-4615] “D:/Enman/fpga/programmer_beginner/vhdl/hello_world/tb/modules.sv” Line 3. Unsupported hierarchical reference $root.tb to VHDL object. We currently have limited support to hierarchical reference to VHDL from Verilog code.

    1. Hello, Emmanuel.

      It seems that your simulator does not support referencing a SystemVerilog code from a VHDL testbench.

      I assume it is best to contact your simulator provider for more details and advice.

      Regards,
      Aurelian

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Subscribe to our newsletter

Do you want to be up to date with our latest articles?