|
| 1 | +//-------------------------------------------------------------------------------- |
| 2 | +// dynamic_delay.v |
| 3 | +// Konstantin Pavlov, [email protected] |
| 4 | +//-------------------------------------------------------------------------------- |
| 5 | + |
| 6 | +// INFO -------------------------------------------------------------------------------- |
| 7 | +// |
| 8 | +// |
| 9 | +// WARNING! |
| 10 | +// This is an adapted verilog version of the Dynamic delay module |
| 11 | +// Please use original "dynamic_delay.sv" where it is posibble |
| 12 | + |
| 13 | + |
| 14 | +module dynamic_delay #( parameter |
| 15 | + LENGTH = 63, // maximum delay chain length |
| 16 | + WIDTH = 4, // data width |
| 17 | + |
| 18 | + SEL_W = $clog2( (LENGTH+1)*WIDTH ) // output selector width |
| 19 | + // plus one is for zero delay element |
| 20 | +)( |
| 21 | + input clk, |
| 22 | + input nrst, |
| 23 | + input ena, |
| 24 | + input [WIDTH-1:0] in, // input data |
| 25 | + // bit in[0] is the "oldest" one |
| 26 | + // bit in[WIDTH] is considered the most recent |
| 27 | + input [SEL_W-1:0] sel, // output selector |
| 28 | + output [WIDTH-1:0] out // output data |
| 29 | +); |
| 30 | + |
| 31 | + |
| 32 | +reg [(LENGTH+1)*WIDTH-1:WIDTH] data = 0; |
| 33 | + |
| 34 | +wire [(LENGTH+1)*WIDTH-1:0] pack_data; |
| 35 | +assign pack_data[(LENGTH+1)*WIDTH-1:0] = |
| 36 | + { data[(LENGTH+1)*WIDTH-1:WIDTH], in[WIDTH-1:0] }; |
| 37 | + |
| 38 | +integer i; |
| 39 | +always@(posedge clk) begin |
| 40 | + if( ~nrst ) begin |
| 41 | + // reset all data except zero element |
| 42 | + for( i=2; i<(LENGTH+2); i=i+1 ) begin |
| 43 | + data[i*WIDTH-1-:WIDTH] <= 0; |
| 44 | + end |
| 45 | + end else if (ena) begin |
| 46 | + for( i=3; i<(LENGTH+2); i=i+1 ) begin |
| 47 | + data[i*WIDTH-1-:WIDTH] <= data[(i-1)*WIDTH-1-:WIDTH]; |
| 48 | + end |
| 49 | + // zero element assignment |
| 50 | + data[2*WIDTH-1-:WIDTH] <= in[WIDTH-1:0]; |
| 51 | + end |
| 52 | +end |
| 53 | + |
| 54 | +// output selector, sel==0 gives non-delayed output |
| 55 | +assign out[WIDTH-1:0] = pack_data[sel[SEL_W-1:0]+:WIDTH]; |
| 56 | + |
| 57 | + |
| 58 | +endmodule |
0 commit comments