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