Skip to content

Commit e583c9f

Browse files
committed
Added reference souce code dir
1 parent 864a690 commit e583c9f

File tree

2 files changed

+130
-0
lines changed

2 files changed

+130
-0
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
//--------------------------------------------------------------------------------
2+
// dynamic_delay.sv
3+
// published as part of https://github.com/pConst/basic_verilog
4+
// Konstantin Pavlov, pavlovconst@gmail.com
5+
//--------------------------------------------------------------------------------
6+
7+
// INFO --------------------------------------------------------------------------------
8+
// Dynamic delay for arbitrary signal.
9+
//
10+
// Incoming data elements have WIDTH bits each. Module does serialization of
11+
// input data and outputs flattened bits, based on provided selector value.
12+
// You can perform delays bit-wize, not just element-wize.
13+
//
14+
// CAUTION: Be careful selecting last, most-delayed "WIDTH" number of bits.
15+
// The module intentionally does NOT implement "out of range"
16+
// checks. Please handle them externally.
17+
18+
19+
20+
/* --- INSTANTIATION TEMPLATE BEGIN ---
21+
22+
dynamic_delay #(
23+
.LENGTH( 3 ),
24+
.WIDTH( 4 )
25+
) M (
26+
.clk( clk ),
27+
.nrst( nrst ),
28+
.ena( 1'b1 ),
29+
.in( in_data[3:0] ),
30+
.sel( sel[3:0] ),
31+
.out( out_data[3:0] )
32+
);
33+
34+
--- INSTANTIATION TEMPLATE END ---*/
35+
36+
37+
module dynamic_delay #( parameter
38+
LENGTH = 63, // maximum delay chain length
39+
WIDTH = 4, // data width
40+
41+
SEL_W = $clog2( (LENGTH+1)*WIDTH ) // output selector width
42+
// plus one is for zero delay element
43+
)(
44+
input clk,
45+
input nrst,
46+
input ena,
47+
input [WIDTH-1:0] in, // input data
48+
// bit in[0] is the "oldest" one
49+
// bit in[WIDTH] is considered the most recent
50+
input [SEL_W-1:0] sel, // output selector
51+
output logic [WIDTH-1:0] out // output data
52+
);
53+
54+
55+
56+
logic [(LENGTH+1)-1:0][WIDTH-1:0] data = '0;
57+
58+
// packed vector includes extra bits
59+
logic [(LENGTH+1)*WIDTH-1:0] pack_data;
60+
assign pack_data[(LENGTH+1)*WIDTH-1:0] = data;
61+
62+
integer i;
63+
always_ff @(posedge clk) begin
64+
if( ~nrst ) begin
65+
// reset all data except zero element
66+
for( i=1; i<(LENGTH+1); i=i+1 ) begin
67+
data[i][WIDTH-1:0] <= '0;
68+
end
69+
end else if (ena) begin
70+
for( i=1; i<(LENGTH+1); i=i+1 ) begin
71+
data[i][WIDTH-1:0] <= data[i-1][WIDTH-1:0];
72+
end
73+
end
74+
end
75+
76+
integer j;
77+
always_comb begin
78+
// zero element assignment
79+
data[0][WIDTH-1:0] <= in[WIDTH-1:0];
80+
81+
// output selector, sel==0 gives non-delayed output
82+
for( j=0; j<WIDTH; j=j+1 ) begin
83+
out[j] <= pack_data[sel[SEL_W-1:0]+j];
84+
end
85+
end
86+
87+
endmodule
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//------------------------------------------------------------------------------
2+
// main.sv
3+
// published as part of https://github.com/pConst/basic_verilog
4+
// Konstantin Pavlov, pavlovconst@gmail.com
5+
//------------------------------------------------------------------------------
6+
7+
// INFO ------------------------------------------------------------------------
8+
// Reference benchmark project
9+
//
10+
// This project uses dynamic_delay.sv module to model both high-register count and
11+
// combinational-intensive design. See "Messages" tab for TOTAL time
12+
// spent for compilation. This will give you some quantitive charachteristic
13+
// of your environment processing power
14+
15+
`define WIDTH 16
16+
`define LENGTH 1024
17+
`define SEL_W $clog2(`LENGTH)
18+
19+
20+
module main(
21+
22+
input clk,
23+
input nrst,
24+
25+
input [`WIDTH-1:0] id,
26+
input [`SEL_W-1:0] sel,
27+
output [`WIDTH-1:0] od
28+
);
29+
30+
dynamic_delay #(
31+
.LENGTH( `LENGTH ),
32+
.WIDTH( 1 ),
33+
.SEL_W( `SEL_W )
34+
) dd [`WIDTH-1:0] (
35+
.clk( {`WIDTH{clk}} ),
36+
.nrst( {`WIDTH{nrst}} ),
37+
.ena( {`WIDTH{1'b1}} ),
38+
.in( id[`WIDTH-1:0] ),
39+
.sel( {`WIDTH{sel[`SEL_W-1:0]}} ),
40+
.out( od[`WIDTH-1:0] )
41+
);
42+
43+
endmodule

0 commit comments

Comments
 (0)