In reply to rgarcia07:
Thank you for your help.
On edaplayground VCS 2019 won’t compile that code because the one_hot was not supported yet
so I switched to using
Incisive 15.20
It compiles now but because of the $urandom it may take a long time to achieve
the one hot bit for mode:
00000001
00000010
00000100
00001000
00010000
00100000
01000000
10000000
Updated code below and added “-coverage functional” as option in edaplayground
module test();
parameter N = 8;
bit [N-1:0] values[N]; //this will contain the relevant values you want in your bins
bit [N-1:0] mode;
bit enable;
bit clk;
bit abc;
covergroup cg @(posedge clk);
enable_cp: coverpoint enable;
one_hot_mode_cp: coverpoint mode {
bins one_hot[N] = values;
}
cross enable_cp, one_hot_mode_cp;
endgroup
cg m_cg;
initial begin
forever #10 clk = ~clk;
end
initial begin
// foreach(values[i]) values[i] = 1 << i; //first populate with the one hot values
foreach(values[i]) begin values[i] = 1 << i; $display("values[%d] = %h, mode[%d] = %h", i, values[i], i, mode[i]); end //first populate with the one hot values
m_cg = new; //create the covergroup
// mode = 1;
repeat (N) begin
@(posedge clk);
mode = $urandom_range(2**N-1, 0);
// mode = mode << 1;
enable = $urandom_range(1, 0);
$display("@ %0t abc = %b, mode = %b enable = %b coverage = %f", $time, abc, mode, enable, m_cg.get_coverage());
end
$finish;
end
endmodule
Incisive Simulation run
Why is mode not one of “00000001, 00000010, 00000100, 00001000, 00010000, 00100000, 01000000, 10000000” and why is coverage incrementing when one_hot and enable is not correct ?
ncsim> run
values[ 0] = 01, mode[ 0] = 0
values[ 1] = 02, mode[ 1] = 0
values[ 2] = 04, mode[ 2] = 0
values[ 3] = 08, mode[ 3] = 0
values[ 4] = 10, mode[ 4] = 0
values[ 5] = 20, mode[ 5] = 0
values[ 6] = 40, mode[ 6] = 0
values[ 7] = 80, mode[ 7] = 0
@ 10 abc = 0, mode = 00011010 enable = 1 coverage = 0.000000
@ 30 abc = 0, mode = 00101010 enable = 1 coverage = 16.666667
@ 50 abc = 0, mode = 11110101 enable = 0 coverage = 16.666667
@ 70 abc = 0, mode = 10011101 enable = 1 coverage = 33.333333
@ 90 abc = 0, mode = 00110110 enable = 1 coverage = 33.333333
@ 110 abc = 0, mode = 11100100 enable = 1 coverage = 33.333333
@ 130 abc = 0, mode = 10001000 enable = 1 coverage = 33.333333
@ 150 abc = 0, mode = 00110101 enable = 0 coverage = 33.333333
Simulation complete via $finish(1) at time 150 NS + 0
./testbench.sv:46 $finish;
ncsim> exit