Regarding Multiple instance of covergroup

Hello,
I craeted one below covergroup,Now i want to use that coveragroup instance 20 times ,then how i have to do??
class MyClass;
int m_a;
covergroup Cov @(posedge clk);
coverpoint m_a;
endgroup
function new();
Cov = new;
endfunction
endclass

You can do it like this. Here is the code that i have used.


covergroup configuration(string name_ ,ref int data); // covergroup should be outside of coverage class

type_option.comment = "Covergroup for data no in data";

option.name = name_; // gives different name of every instance
option.per_instance = 1; // here is the most important thing

no_in_data : coverpoint data[31:24]
{
bins rng_0 = {[0:127]} ;
bins rng_1 = {[128:255]} ;
}

endgroup : configuration

class coverage_class;

int data[25];

configuration cfg[25];

function new(string name="coverage class", uvm_component parent= null);
foreach(cfg)
cfg = new($sformatf("cg_%d",i),data);
endfunction : new

task give_data();

for(int i=0; i<25; i++)
begin
data= i*i;
cfg.sample();
end

endtask : give_data

endclass : coverage_class


covergroup cov (ref int m_a)@(posedge clk)
{
 option.per_instance=1;
 coverpoint m_a;
}
endgroup:cov

class my_class;
 int m_a[20];
 cov c1[20];
 
 function new();
  foreach(m_a[i]) 
    begin
     c1[i]=new(m_a[i]);
     c1[i].sample;
    end
 endfunction:new

endclass:my_class
  



Please Edit the above code…Corrected code is below:


covergroup cov (ref int m_a)@(posedge clk)
{
 option.per_instance=1;
 coverpoint m_a;
}
endgroup:cov
 
class my_class;
 int m_a[20];
 cov c1[20];
 
 function new();
  foreach(c1[i]) 
    begin
     c1[i]=new(m_a[i]);
     c1[i].sample;
    end
 endfunction:new
 
endclass:my_class

Why you have used both @(posedge clk) and .sample method? You should use either one of them.

Right Mansi…Below is corrected one.


covergroup cov (ref int m_a);
 option.per_instance=1;
 coverpoint m_a;
endgroup:cov
 
class my_class;
 int m_a[20];
 cov c1[20];
 
 function new();
  foreach(c1[i]) 
    begin
     c1[i]=new(m_a[i]);
     c1[i].sample;
    end
 endfunction:new
 
endclass:my_class