Coverage_For_FSM

Hi,

I have trying to take the coverage for the sequence detector of 1011 without overlap. I have written the covergroup to take the coverage. Without applying proper stimulus I am getting 100% coverage. Can someone help me solve this issue.

Link : Functional_coverage_FSM(1) - EDA Playground

Thanks,
Naren

In reply to narendrareddy:

The problem is you are not sampling the DUT, you need to connect somehow to the coverage, in your code you are sampling the enum values

      repeat(3)
        begin
          inp=$urandom_range(0,1);
          $display("The input is %0d",inp);
          cov_inst.sample(s0);
     	   cov_inst.sample(s1);
     	   cov_inst.sample(s2);
     	   cov_inst.sample(s3);
     	   @(posedge clk);
          
        end

So you are getting s0->s1, s1->s2, s2->s3 I ran your code and actually I get 75%, but again you are not sampling the DUT

You should sample the fsm current state instead, keep in mind there are differences in your design is declared as reg[1:0] and in your coverage is a typpedef

in your top file you could do

  state_machine state_machine_tb(clk,rst,inp, out);
  tb tb_test(clk,rst,inp, out, state_machine_tb.current_state); //this a quck work around

and in your tb program

module tb(clk,rst,inp, out, current_state);
  
  typedef enum {s0,s1,s2,s3} state;
  
  input clk;
  output rst;
  output inp;
  input [1:0] current_state;
  input out;
  
  reg rst;
  reg inp;
 
  covergroup my_cov with function sample(state curr_state);
  cp1:coverpoint curr_state{
    bins s0_s1=(s0=>s1)iff(inp==1);
    bins s1_s2=(s1=>s2)iff(inp==0);
    bins s2_s3=(s2=>s3)iff(inp==1);
    bins s3_s0=(s3=>s0)iff(inp==1);
  }
endgroup
  my_cov cov_inst;
  
  initial
    begin
      cov_inst=new;
     #2 rst=1'b1;
      
      @(posedge clk);
      rst=1'b0;
      repeat(3)
        begin
          inp=$urandom_range(0,1);
          $display("The input is %0d",inp);
          cov_inst.sample(state'(current_state));
     	   @(posedge clk);
          
        end
      
      $display("coverage = %0.2f%%",cov_inst.get_coverage());
    end

endmodule

That gives me

# KERNEL: ASDB file was created in location /home/runner/dataset.asdb
# KERNEL: The input is 1
# KERNEL: The input is 0
# KERNEL: The input is 0
# KERNEL: coverage = 25.00%
# RUNTIME: Info: RUNTIME_0068 program.sv (42): $finish called.

HTH,

-R

In reply to rgarcia07:

Thank you, The solution is very clear…

I have one more question:
When I use the $set_coverage_db_name(name) and $load_coverage_db(name) to load the coverage. I am getting the error like unable to find the directory to load the coverage.

Link: Functional_coverage_FSM(1) - EDA Playground

Please help me with this issue…

Thanks,
Naren