-
Notifications
You must be signed in to change notification settings - Fork 383
/
delay.v
69 lines (56 loc) · 1.72 KB
/
delay.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//------------------------------------------------------------------------------
// delay.v
// published as part of https://github.com/pConst/basic_verilog
// Konstantin Pavlov, [email protected]
//------------------------------------------------------------------------------
// INFO -------------------------------------------------------------------------
// Static Delay for arbitrary signal
// (simplified Verilog version, see ./delay.sv for advanced features)
//
// Another equivalent names for this module:
// conveyor.sv
// synchronizer.sv
//
// Tip for Xilinx-based implementations: Leave nrst=1'b1 and ena=1'b1 on
// purpose of inferring Xilinx`s SRL16E/SRL32E primitives
//
// CAUTION: delay module is widely used for synchronizing signals across clock
// domains. When synchronizing, please exclude input data paths from timing
// analysis manually by writing appropriate set_false_path SDC constraint
//
/* --- INSTANTIATION TEMPLATE BEGIN ---
delay #(
.LENGTH( 2 ),
.WIDTH( 1 )
) S1 (
.clk( clk ),
.nrst( 1'b1 ),
.ena( 1'b1 ),
.in( ),
.out( )
);
--- INSTANTIATION TEMPLATE END ---*/
module delay #( parameter
LENGTH = 2, // delay/synchronizer chain length
WIDTH = 1 // signal width
)(
input clk,
input nrst,
input ena,
input [WIDTH-1:0] in,
output [WIDTH-1:0] out
);
reg [LENGTH:1][WIDTH-1:0] data = 0;
always @(posedge clk) begin
integer i;
if( ~nrst ) begin
data <= 0;
end else if( ena ) begin
for( i=LENGTH-1; i>0; i=i-1 ) begin
data[i+1][WIDTH-1:0] <= data[i][WIDTH-1:0];
end
data[1][WIDTH-1:0] <= in[WIDTH-1:0];
end
end
assign out[WIDTH-1:0] = data[LENGTH][WIDTH-1:0];
endmodule