Thursday, November 13, 2025

Fifo depth , randc function using rand

Calculate the depth of FIFO :

Writing frequency = fA = 80MHz. Reading Frequency = fB = 50MHz. Burst Length = No. of data items to be transferred = 120. There are no idle cycles in both reading and writing which means that, all the items in the burst will be written and read in consecutive clock cycles.

====================================================================

Ans:  1 write = 80 MHZ = 12.5 ns   (  1MHz is 1000 ns) 

        120 writes = 120*12.5 ns = 1500 ns 

        reading 1 = 50 MHz = 20 ns  

       in 1500 ns how many reads = 1500/20 = 75 

  deapth = wrire -read = 120-75 = 45  

=============================================

Question 

 Writing Side = 80 words in 100 clocks • Reading Side = 8 words in 10 clocks • BURST wr 160 

What will be the FIFO depth 

=======================================================

Solution : • Worst scenario of overflow of data is when there is 160 clocks of continuous write. Lets assume first 20 cycle is idle and then 80 clock cycle writing. Other set of writing starts at 101 clock cycle. Worst scenario : 160 words are written in 160 clocks Reading possibility : 8*16 = 128 words can be read So depth of FIFO : 160-128 = 32


================

constraint for a rand variable to behave like a randc.

credit https://www.linkedin.com/pulse/constraint-45-mohamed-irsath-i-qs58c/ 

In order to achieve the requested constraint, we first need to understand the difference between rand and randc variables.

Rand: By defining a variable as rand, it becomes an active variable when you randomize the object created for the class where the variable is defined. While randomizing, it will take possible values that obey the constraints written for that variable. If no constraints are specified, it can generate any value in its range and may repeat the same value multiple times without producing all possible values.

Randc: randc behaves similarly to rand, but with an additional feature denoted by the "c" for cyclic. This cyclic behavior allows the variable to generate all possible values, but without repeating any value until it has generated all possible values at least once.

For example, consider a 3-bit variable a. If a is declared as rand, it can take any value from 0 to 7 while randomizing. It may repeat values before generating all values from 0 to 7. On the other hand, if a is declared as randc, it won't repeat any generated value until it has generated all values from 0 to 7.

class sample;
  rand  bit [2:0] rand_a;
  bit [2:0] rand_q[$];
  
  constraint rand_a_c {
    unique{rand_a,rand_q}; 
  }
  
  function void post_randomize();
    if(rand_q.size() == 7) rand_q.delete();
    rand_q.push_back(rand_a);
  endfunction
endclass

module top;
  sample s=new();
  initial begin
    $display("############## OUTPUT ###############");
    $display("the Behvariablef rand variable as randc");
  	repeat(10) begin
    	s.randomize();
      $display(" rand_a = %0d",s.rand_a);
      $display(" rand_q = %p",s.rand_q);
  	end
    $display("see there is no repetition till \n it generate 0 to 7 \n even though it is a rand variable ");
    $display("################ END ################");
  end
endmodule

No comments:

Post a Comment