0

I have a stuck Clocking Block in SystemVerilog that i try to understand but I could not. I have just a normal Clocking Block like this, and I just drive one signal to understand.

`timescale 1ns/100ps
module quiz();
    bit clk;
    logic reset;
    
    
    default clocking cb @(posedge clk);
    default input #1step output #5;
    output reset;
    endclocking
    
    always #5 clk = ~clk;
    
    initial begin
    cb.reset <= '0;
    ##2 cb.reset <= '1;
    ##3 cb.reset <= '0;
    end
endmodule

As I expected that after first rising_edge clk + 5ns, reset will turn from X to 0. Then reset = 0 will last for next 2 rising_edge. At that time + 5ns, reset will turn from 0 to 1 and last for next 3 rising_edge. But it doesn't work like i thought, reset = 0 only lasted for a single rising_edge. Otherwise that reset = 1 still lasted for 3 rising_edge.

enter image description here

In fact, I have already found how to fix this problem, just by adding @(cb) in the very beginning of "initial block" so it will be:

    initial begin
    @(cb);
    cb.reset <= '0;
    ##2 cb.reset <= '1;
    ##3 cb.reset <= '0;
    end

enter image description here

After i added that, It will run as I expected. But in the understanding problem, I still have no idea, what is going on? What is mission of "@(cb)", this problem causes because of my code or compiler???. I would be appriciated, if someone can explain in detail. Thanks

toolic
  • 57,801
  • 17
  • 75
  • 117

1 Answers1

0
Section 14.11 Cycle Delay

The cycle delay timing control shall wait for the specified number of clocking block events. This implies that for a ##1 statement that is executed at a simulation time that is not coincident with the associated clocking block event, the calling process shall be delayed a fraction of the associated clock cycle.

IEEE 1800-2017 SystemVerilog LRM

This means the period between time 0 and the first posedge of the clock consumes a clock cycle.

A practice I recommend is always putting an @(cb) first in the procedural thread of your code before referencing any clocking block construct. Ensure the procedural flow remains synchronized to the clocking block by excluding all other blocking statements like a wait() or @(something_else) unless you resynchronize the thread with another @(cb)

dave_59
  • 39,096
  • 3
  • 24
  • 63