Hi, running the code below results incorrect 10ps clock period instead of 10ns
if i remove the localparam, the clock period is 10ns
if i add timescale directive in p.sv, the clock period is 10ns
if i remove the timescale directive in tb.sv, the period is 10ns
if i convert the class to a module, vsim raises error.
(vsim-3009) [TSCALE] - Module 'm' does not have a timeunit/timeprecision specification in effect, but other modules do.
Can you explain what is happening here. Is this behavior tool specific.
About error 3009. Do you still need to use timescale directive even if all delays use time riterals. (e.g. #(10ns); )
Why is the clock period 10ns when i remove the timescale directive from tb.sv?
Why the use of localparam changes the clock period?
Thanks in advance.
p.sv
// `timescale 1ps/1ps
package p;
class c;
virtual interface i i1;
localparam real T = 5ns;
// real T = 5ns;
task run();
forever begin
i1.clk <= 1;
#(T);
i1.clk <= 0;
#(T);
end
endtask
endclass
endpackage
interface i;
logic clk;
endinterface
tb.sv
`timescale 1ps/1ps
import p::*;
module tb;
i i1();
c c1;
initial begin
c1 = new();
c1.i1 = i1;
fork
begin
c1.run();
end
begin
repeat(10) @(posedge i1.clk) begin
$display("$time = %t", $time);
end
end
join_any
$finish;
end
endmodule
The code above is compiled and ran like this.
vlog p.sv
vlog tb.sv
vsim work.tb -voptargs=+acc -do ‘run -all;’