Method

what should be a method for scale down factor of timer? there are so many timers and I need to scale it down with some factor.

In reply to tech_savvy:

Not sure what you are referring to, or even what domain (design, or testbench). Perhaps: Timer/Counter Module - A Controller Independent Guide - EmbedJournal

In reply to dave_59:

I need to write uvm code for scale down factor of timer.

In reply to tech_savvy:

You should give us some more details for your task you have to implement. In which way you have to scale down etc …

In reply to chr_sue:
there are so many timers in my protocol, so i need to scale down its timeout value by scaledown factor. for it i need to write a method. So how to write that method?

In reply to tech_savvy:

Then you have to divide the timeout value by the scaledown factor. There is nothing magic.

In reply to chr_sue:

So do i need to set value of scaledown factor or just i should declare field (int scaledownfactor) in configuration class and user will set scaledown value accordingly.

In reply to tech_savvy:

I do not know how your environment looks like. There are several approaches posible. You can use simply a parameter or using a configuration object. This depends also what your objective is. Do you want to scale down with ranom values or not.

In reply to chr_sue:

yes i want to scale down with random values.

In reply to tech_savvy:

Then you can create a configuration object with the scaling factor and possibly some additional data mebers you might use, creat, randomize this object and pass it to the config_db. Then you can retrieve it in any place you need this object.

In reply to chr_sue:
I have written this code but not getting correct value

class scaling;
  int pclk;
  int scaledown;
  real polling_cnt;
  
  function pri(int pclk, scaledown);
    realtime polling = 0.6us;
    polling_cnt = (polling * pclk) / scaledown;
  endfunction
endclass
module priyanka();
  scaling s=new();
  //int pclk,scaledown;
  initial begin
    s.pclk = 500000000;
    s.scaledown = 1000;
    s.pri(s.pclk,s.scaledown);
    $display("%d ",s.polling_cnt);
 end
endmodule

In reply to tech_savvy:

Your code is not really clean. See my code below working:

class scaling;
  bit pclk;
 
  function realtime pri(int scaledown);
    realtime polling = 0.6us;
    $display("scaledown = %d ", scaledown);
    pri = polling / scaledown;
    $display("pri = %f ", pri);
    return pri;
  endfunction
endclass

module priyanka();
  int scaledown = 1;;
  realtime polling_cnt;
  scaling s=new();
  initial begin
    scaledown = 200;
    repeat (3) begin
      polling_cnt = s.pri(scaledown);
      $display("%f ",polling_cnt);
      scaledown = 10 * scaledown;
    end
 end
endmodule

In reply to chr_sue:
I have changed something in your code.
class scaling;
int pclk;
function realtime pri(int scaledown,pclk);
$display("scaledown = %d ", scaledown);
pri = 0.00000006*pclk / scaledown;
$display("pri = %f ", pri);
return pri;
endfunction
endclass

module priyanka();
int scaledown = 1;
int pclk = 1;
int polling_cnt;
scaling s=new();
initial begin
scaledown = 1000;
pclk = 500000000;
repeat (3) begin
polling_cnt = s.pri(scaledown,pclk);
$display("%f ",polling_cnt);
pclk = 0.5 *pclk;

end

end
endmodule

-Now the question is there are 3 different values of pclk: 500000000, 250000000, 125000000. So for this, i wrote pclk = 0.5*pclk. But driver will use one value at a time, so how to code this?

In reply to tech_savvy:

Again, I assume pclk is your clock signal. This signal has values 1’b1 and 1’b0.
What is in your eyes

pclk = 0.5 *pclk;

What you want to do is something like this in your clock generator:

always #scaledown pclk = ~pclk;

In reply to chr_sue:

actually realtime polling is timer, i need to change this timer value into counter. For this i have to multiply pclk and polling timer value (polling *pclk) and then i need to scaledown. So my query is should i take all three values of pclk in my configuration class or driver will take care of it?

In reply to tech_savvy:

Again, what is pclk?

In reply to chr_sue:

Pclk is A clock frequency… There are 3pclk: 500Mhz, 250Mhz and 125Mhz

In reply to tech_savvy:

I’m not sure if yiu are right. I believe pclk is a clock signal which can have 3 different frequencies. This is different what you are saying.

In reply to chr_sue:

Ya pclk is A clock signal with 3differenet frequency

In reply to tech_savvy:

Then you have to define pclk as data type bit (2 states) or logic (4 states).
The click generaror generating your clock signal has to be configurable for the 3 clock frequencies.
That’s it.