1
0
mirror of https://github.com/aolofsson/oh.git synced 2025-01-17 20:02:53 +08:00
oh/common/hdl/oh_delay.v
Andreas.Olofsson 412fb61519 Changing delay function to take a clock
-The combinatorial delay elemement doesn't belong in this library, too specific!
2020-03-13 11:04:08 -04:00

34 lines
1011 B
Verilog

//#############################################################################
//# Function: Delays input signal by N clock cycles #
//#############################################################################
//# Author: Andreas Olofsson #
//# License: MIT (see LICENSE file in OH! repository) #
//#############################################################################
module oh_delay #(parameter DW = 1, // width of data
parameter N = 1 // clock cycle delay by
)
(
input [DW-1:0] in, // input
input clk,//clock input
output [DW-1:0] out // output
);
reg [DW-1:0] sync_pipe[N-1:0];
genvar i;
generate
always @ (posedge clk)
sync_pipe[0]<=in[DW-1:0];
for(i=1;i<N;i=i+1)
always @ (posedge clk)
sync_pipe[i]<=sync_pipe[i-1];
endgenerate
assign out[DW-1:0] = sync_pipe[N-1];
endmodule // oh_delay