0

Please help me to understand some simulator behavior related to timescale. This is my top module:  

module top; //timeunit 1ns; //timeprecision 1ps; bit clk_62p5; // PCI write clock always #8 clk_62p5++; DPSRAM_64X4096 u_MEM ( .clka(clk_62p5), …. ); … endmodule `timescale 1 ns/1 ps module DPSRAM_64X4096 (…); … endmodule 

This is my simulation script:

irun \ … -timescale 1ns/1ps \ … 

When I run the simulation, I see that the clk_62p5 clock period is 16ps and not 16ns. Can you explain why I have this behavior?

A 2nd question: what is the difference between timeunit, timeprecision and timescale?

2
  • To not answer your first question: I could not reproduce your problem. Here is my attempt. Please could you post an MCVE. However, I notice you have written timescale 1 ns/1 ps . This should be timescale 1ns/1ps . Perhaps that is your problem? Commented Mar 2, 2017 at 9:12
  • Yes I think you should remove the spaces in timescale and check again Commented Mar 3, 2017 at 5:13

1 Answer 1

2

To answer your second question:

`timescale is a compiler directive. Using compiler directives can cause compile order dependencies, that is different behaviour or problems that are caused by the actual order you compile your files in. Suppose you have three files:

fileA.v `timescale 1ns/1ps fileB.v `timescale 10ns/10ps fileC.v // no timescale directive 

If you compile in this order

fileA.v fileB.v fileC.v 

then the precision will be 1ps - the smallest the compile found - the timeunit for each file will be:

fileA.v 1ns because of the `timescale directive fileB.v 10ns because of the `timescale directive fileC.v 10ns because the `timescale directive from fileB.v continues to have an effect 

If you compile in this order

fileA.v fileC.v fileB.v 

then the precision will be 1ps - the smallest the compile found - the timeunit for each file will be:

fileA.v 1ns because of the `timescale directive fileB.v 10ns because of the `timescale directive fileC.v 1ns because the `timescale directive from fileA.v continues to have an effect 

If you compile in this order

fileC.v fileA.v fileB.v 

then you will get an error, because it is illegal to have a file with no timescale directive appearing before any file with a timescale directive. (Though it is OK if no file has a `timescale directive).

timeunit and timeprecision are newer, System-Verilog ways of achieving the same thing. As they are not compiler directives, they do not suffer from the related problems. They only apply to the scope ($unit/package/module/program/interface) that they are used in (and must come first in that scope).

If you use timeunit and timeprecision as well as a timescale directive, then timeunit and timeprecision take priority.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.