How to implement transition coverage on non-consecutive sampling points?

384 views Asked by At

var_1 changes from value 0 to 1 then from 1 to 2 and so on till 15, but not on consecutive sampling points. I sample on every clock cycle, but the value might change after some arbitrary clk cycles. The transition coverage I write does not work. Can we write transition coverage for this case?

bit [3:0] var_1;
    var1: coverpoint var_1  
    {
    bins var_1_trans_bin = (0=>1=>2=>3=>4=>5=>6=>7=>8=>9=>10=>11=>12=>13=>14=>15);
    bins var_1_bin[] = {[0:15]};
    }

I see that the var_1_bin is getting covered 100% but not the var_1_trans_bin.

Here is the whole code:

module GRG_coverpoint;

  bit [3:0] var_1;
  bit Running;
  bit clk;

// Example showing bins and transitions
covergroup CG1 @(posedge clk);
  coverpoint var_1
  {
    bins var_1_trans_bin = (0=>1=>2=>3=>4=>5=>6=>7=>8=>9=>10=>11=>12=>13=>14=>15);
    bins var_1_bin[] = {[0:15]};
  }
endgroup

initial begin
  automatic CG1 cg1_inst = new;
  for (int j = 0; j < 16; j++)
  begin
    var_1 = j;
    #20;
  end
  $display ("CG1 Coverage = %.2f%%", cg1_inst.get_coverage());
  Running = 0;
end

initial begin
  clk = 0;
  Running = 1;
  while (Running) begin
    #5 clk = ~clk;
  end
  $display ("Finished!!");
end

endmodule
1

There are 1 answers

0
toolic On

As you realized, you do not want to sample coverage on every clock cycle. You want to sample it only when var_1 changes value. You can declare the covergroup without the optional coverage_event (@(posedge clk) in your case), then call the sample method in a separate procedural block every time the variable changes:

module GRG_coverpoint;

  bit [3:0] var_1;
  bit [3:0] var_2;
  bit Running;
  bit clk;

// Example showing bins and transitions
covergroup CG1;
  coverpoint var_1
  {
    bins var_1_trans_bin = (0=>1=>2=>3=>4=>5=>6=>7=>8=>9=>10=>11=>12=>13=>14=>15);
    bins var_1_bin[] = {[0:15]};
  }
endgroup

CG1 cg1_inst = new;

initial begin
    cg1_inst.sample(); // Sample the initial 0 value
    forever @(var_1) cg1_inst.sample();
end

initial begin
  for (int j = 0; j < 16; j++)
  begin
    var_1 = j;
    #20;
  end
  $display ("CG1 Coverage = %.2f%%", cg1_inst.get_coverage());
  Running = 0;
end

initial begin
  clk = 0;
  Running = 1;
  while (Running) begin
    #5 clk = ~clk;
  end
  $display ("Finished!!");
end

endmodule