# Clocking block in UVM TB

**URL:** <https://verificationacademy.com/forums/t/clocking-block-in-uvm-tb/36008>\
**Category:** UVM\
**Tags:** UVM, Clocking-Block\
**Created:** [April 23, 2019, 8:27pm UTC](https://verificationacademy.com/forums/t/clocking-block-in-uvm-tb/36008 "2019-04-23T20:27:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![uvmsd](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/u/b9bd4f/32.png) [@uvmsd](https://verificationacademy.com/forums/u/uvmsd)\
**Post date:** [April 23, 2019, 8:27pm UTC](https://verificationacademy.com/forums/t/clocking-block-in-uvm-tb/36008/1 "2019-04-23T20:27:23Z")

</div>

I had raised a question in below post regarding clocking block. I got great inputs. I have updated my TB now.  
Old post is here:  
[https://verificationacademy.com/forums/uvm/effect-clocking-block-uvm-driver/monitor](https://verificationacademy.com/forums/uvm/effect-clocking-block-uvm-driver/monitor)  
Sorry, now I am kind of stuck with some other issue. I have many other modules to be updated. So wanted to have a clear understanding before making any changes.

interface updn\_counter\_if(input logic clk, reset, clk\_en);  
logic [ABSOLUTE\_DATA\_WIDTH-1:0] count\_value;  
logic load\_counter;  
logic up\_counter;  
logic [1:0] inc;  
logic [ABSOLUTE\_DATA\_WIDTH-1:0] current\_value;  
logic count\_reached;

clocking counter\_cb @(posedge clk);  
default input #1step output #1;  
inout load\_counter;  
inout count\_value;  
inout up\_counter;  
inout inc;  
input current\_value;  
input count\_reached;  
endclocking  
endinterface

**DRIVER**  
virtual task drive();  
@( counter\_vif.counter\_cb);  
if (counter\_vif.clk\_en == 1 && counter\_vif.reset) begin  
counter\_vif.counter\_cb.count\_value \<= req.count\_value;  
counter\_vif.counter\_cb.load\_counter \<= req.load\_counter;  
counter\_vif.counter\_cb.up\_counter \<= req.up\_counter;  
counter\_vif.counter\_cb.inc \<= req.inc;  
end //if  
endtask

**MONITOR**  
virtual task run\_phase(uvm\_phase phase);  
super.run\_phase(phase);  
forever begin  
@(counter\_vif.counter\_cb);  
//@(posedge counter\_vif.clk);  
if (counter\_vif.clk\_en && counter\_vif.reset == 1) begin  
seq\_item\_collected.count\_value = counter\_vif.count\_value;  
seq\_item\_collected.load\_counter = counter\_vif.load\_counter;  
seq\_item\_collected.up\_counter = counter\_vif.up\_counter;  
seq\_item\_collected.inc = counter\_vif.inc;

```
 seq_item_collected.current_value = counter_vif.counter_cb.current_value;
 seq_item_collected.count_reached = counter_vif.counter_cb.count_reached;

 trans_collected_port.write(seq_item_collected);
end //    

```

end //forever  
endtask : run\_phase

If i specify input skew in clocking clock to be zero, my data integrity looks fine. If i specify it to be non-zero, there is an offset of 1 value between RTL and TB.

1. IS it because the RTL value is sampled just before the clock edge and takes the previous value? Do we update our TB accordingly?
2. Should things change if input skew is zero amd non-zero? I mean, for non-zero it gets the value from previous clock?
3. Do we have take any precautions while handling clk\_en which is not part of clocking block?  
Please let me know. Thank you!

---

<div class="post-metadata">

**Author:** ![cgales](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/c/ccd318/32.png) [@cgales](https://verificationacademy.com/forums/u/cgales)\
**Post date:** [April 23, 2019, 8:47pm UTC](https://verificationacademy.com/forums/t/clocking-block-in-uvm-tb/36008/2 "2019-04-23T20:47:41Z")

</div>

_In reply to [uvmsd](https://verificationacademy.com/forums/t/clocking-block-in-uvm-tb/36008):_

Chapter 14 of the [IEEE SystemVerilog Language Standard](https://standards.ieee.org/standard/1800-2017.html) provides all the information you need:

The clocking\_skew determines how many time units away from the clock event a signal is to be sampled or driven. Input skews are implicitly negative, that is, they always refer to a time before the clock, whereas output skews always refer to a time after the clock (see 14.4). When the clocking event specifies a simple edge, instead of a number, the skew can be specified as the specific edge of the signal. A single skew can be specified for the entire block by using a default clocking item.

---

<div class="post-metadata">

**Author:** ![uvmsd](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/u/b9bd4f/32.png) [@uvmsd](https://verificationacademy.com/forums/u/uvmsd)\
**Post date:** [April 23, 2019, 9:24pm UTC](https://verificationacademy.com/forums/t/clocking-block-in-uvm-tb/36008/3 "2019-04-23T21:24:25Z")

</div>

_In reply to [cgales](https://verificationacademy.com/forums/t/clocking-block-in-uvm-tb/36008/2):_  
@cgales

Does “A single skew can be specified for the entire block by using a default clocking item.”  
mean, @( counter\_vif.counter\_cb); would apply to the following driving/sampling instructions, right?  
I think, I still need some clarification.  
My question was:  
Is that expected behavior, if current\_value from counter gives previous value when input sklew is non-zero?

With input skew =0, I have no issues.  
I am facing data integrity issue in TB with non-zero skew since TB counter increments on every clock and RTL also does the same. But when i sample RTL value, I am getting previous value with non-zero skew.  
Do i need to adjust my data integrity checking accordingly? or am i missing something?
