# Signal delay by X clock cycles in System Verilog

**URL:** <https://verificationacademy.com/forums/t/signal-delay-by-x-clock-cycles-in-system-verilog/31432>\
**Category:** SystemVerilog\
**Tags:** SystemVerilog, Delay, Verilog, clock, signal\
**Created:** [January 26, 2016, 2:15pm UTC](https://verificationacademy.com/forums/t/signal-delay-by-x-clock-cycles-in-system-verilog/31432 "2016-01-26T14:15:49Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![RenéPi](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/r/e47c2d/32.png) [@RenéPi](https://verificationacademy.com/forums/u/Ren%C3%A9Pi)\
**Post date:** [January 26, 2016, 2:15pm UTC](https://verificationacademy.com/forums/t/signal-delay-by-x-clock-cycles-in-system-verilog/31432/1 "2016-01-26T14:15:49Z")

</div>

Hello everyone,

I am new to Verilog.

I’d like to delay a signal by 5 clock cycles. Right now I am doing this by just copying a signal 5 times, but isn’t there a more comfortable way?

```
fs_shift1_model_o <= fs_model_o; //Delay for 5 clock cycles 
fs_shift2_model_o <= fs_shift1_model_o; //to compare the frame syncs
fs_shift3_model_o <= fs_shift2_model_o; //of the DUT & the model
fs_shift4_model_o <= fs_shift3_model_o; //1 copy = 1 cycle
fs_shift5_model_o <= fs_shift4_model_o;

```

I found that there is a function named buf(x,x) (out,in) but there’s a limit, I think 1 cycle.

Thanks in advance,  
René

---

<div class="post-metadata">

**Author:** ![dave\_59](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/dave_59/32/4499_2.png) [@dave\_59](https://verificationacademy.com/forums/u/dave_59)\
**Post date:** [January 26, 2016, 5:05pm UTC](https://verificationacademy.com/forums/t/signal-delay-by-x-clock-cycles-in-system-verilog/31432/2 "2016-01-26T17:05:03Z")

</div>

_In reply to [RenéPi](https://verificationacademy.com/forums/t/signal-delay-by-x-clock-cycles-in-system-verilog/31432):_

```verilog
fs_shift5_model_o <= repeat (5) @(posedge clk) fs_model_o;

```

buf() is not a function, it is a gate-level primitive that instantiates a process.

---

<div class="post-metadata">

**Author:** ![RenéPi](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/r/e47c2d/32.png) [@RenéPi](https://verificationacademy.com/forums/u/Ren%C3%A9Pi)\
**Post date:** [January 27, 2016, 7:52am UTC](https://verificationacademy.com/forums/t/signal-delay-by-x-clock-cycles-in-system-verilog/31432/3 "2016-01-27T07:52:34Z")

</div>

_In reply to [dave\_59](https://verificationacademy.com/forums/t/signal-delay-by-x-clock-cycles-in-system-verilog/31432/2):_

thanks a lot for your answer. really appreciate your support! This works perfect, but somehow I just had to use:

fs\_shift\_model\_o \<= repeat( **4** ) @(posedge clk) fs\_model\_o;

to give me the expected result! This is way more comfortable than making several copies for a delay!

Many thank and have a nice day :)

---

<div class="post-metadata">

**Author:** ![FaisalAwan](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/f/3ab097/32.png) [@FaisalAwan](https://verificationacademy.com/forums/u/FaisalAwan)\
**Post date:** [December 8, 2022, 6:04pm UTC](https://verificationacademy.com/forums/t/signal-delay-by-x-clock-cycles-in-system-verilog/31432/4 "2022-12-08T18:04:58Z")

</div>

Hope you are doing well,I have a question that if we want to make synthesizable design for N cycle delay of 32 bit signal at output then what will be the verilog code for this. I will really appreciate your answer

Thank you

---

<div class="post-metadata">

**Author:** ![dave\_59](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/dave_59/32/4499_2.png) [@dave\_59](https://verificationacademy.com/forums/u/dave_59)\
**Post date:** [December 8, 2022, 8:15pm UTC](https://verificationacademy.com/forums/t/signal-delay-by-x-clock-cycles-in-system-verilog/31432/5 "2022-12-08T20:15:40Z")

</div>

_In reply to [Faisal Saeed Awan](https://verificationacademy.com/forums/t/signal-delay-by-x-clock-cycles-in-system-verilog/31432/4):_

You can use a fifo for this.

```verilog
typedef logic [31:0] uint_t;
parameter N = 5;
wire uint_t in, out;

var uint_t fifo[N];

always @(posedge clk)
     fifo[N-1] <= in;

for(genvar i=0;i<N-1;i++)
  always @(posedge clk)
     fifo[i] <= fifo[i+1];

assign out = fifo[0];

```

If N is not a parameter, you will have to define a maximum number of cycle delays for the size of the fifo, and then add a mux to select where the input to each stage of the fifo comes from.

```verilog
typedef logic [31:0] uint_t;
parameter Max= 5;
int N;
wire uint_t in, out;
var uint_t fifo[N];

for(genvar i=0;i<Max;i++)
  always @(posedge clk)
     fifo[i] <= (i==(N-1))? in : fifo[i+1];

assign out = fifo[0];

```

---

<div class="post-metadata">

**Author:** ![FaisalAwan](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/f/3ab097/32.png) [@FaisalAwan](https://verificationacademy.com/forums/u/FaisalAwan)\
**Post date:** [December 9, 2022, 5:35am UTC](https://verificationacademy.com/forums/t/signal-delay-by-x-clock-cycles-in-system-verilog/31432/6 "2022-12-09T05:35:50Z")

</div>

Thank you Dave, the design code working perfectly :)
