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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
//
// Copyright 2011 Ettus Research LLC
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
module hb_tb();
localparam SWIDTH = 17;
localparam CWIDTH = 18;
localparam TWIDTH = 20;
localparam ACC_WIDTH = 40;
reg clk = 0, rst = 1;
wire strobe_in, strobe_out;
reg [SWIDTH-1:0] sample_in;
wire signed [SWIDTH:0] sample_out;
reg set_stb;
reg [7:0] set_addr;
reg [31:0] set_data;
localparam DECIM = 3;
initial $dumpfile("hb_tb.vcd");
initial $dumpvars(0,hb_tb);
always #5 clk <= ~clk;
initial
begin
@(posedge clk);
@(negedge clk);
rst <= 0;
end
reg [7:0] stb_counter;
always @(posedge clk)
if(rst)
stb_counter <= 0;
else
if(stb_counter == 0)
stb_counter <= DECIM;
else
stb_counter <= stb_counter - 1;
assign strobe_in = (stb_counter == 0);
hb_decim #(.SWIDTH(SWIDTH),.CWIDTH(CWIDTH),
.TWIDTH(TWIDTH),.ACC_WIDTH(ACC_WIDTH)) hb_decim
(.clk(clk), .rst(rst),
.set_stb(set_stb), .set_addr(set_addr), .set_data(set_data),
.sample_in(sample_in),
.strobe_in(strobe_in),
.sample_out(sample_out),
.strobe_out(strobe_out)
);
initial
begin : load_coeffs
@(negedge rst);
@(posedge clk);
set_addr <= 124; // load coeffs
set_stb <= 1;
set_data <= -18'd49;
@(posedge clk);
set_data <= 18'd165;
@(posedge clk);
set_data <= -18'd412;
@(posedge clk);
set_data <= 18'd873;
@(posedge clk);
set_data <= -18'd1681;
@(posedge clk);
set_data <= 18'd3135;
@(posedge clk);
set_data <= -18'd6282;
@(posedge clk);
set_data <= 18'd20628;
@(posedge clk);
set_addr <=125; // load table
// { stb_out, accum, load_accum, done, even_addr, odd_addr_a, odd_addr_b, coeff_addr }
set_data <= {1'b1,1'b1,1'b0,1'b1,4'd15,4'd15,4'd0,4'd0}; // Phase 8
@(posedge clk);
set_data <= {1'b0,1'b1,1'b0,1'b0,4'd15,4'd14,4'd1,4'd1}; // Phase 7
@(posedge clk);
set_data <= {1'b0,1'b1,1'b0,1'b0,4'd15,4'd13,4'd2,4'd2}; // Phase 6
@(posedge clk);
set_data <= {1'b0,1'b1,1'b0,1'b0,4'd15,4'd12,4'd3,4'd3}; // Phase 5
@(posedge clk);
set_data <= {1'b0,1'b1,1'b0,1'b0,4'd15,4'd11,4'd4,4'd4}; // Phase 4
@(posedge clk);
set_data <= {1'b0,1'b1,1'b0,1'b0,4'd15,4'd10,4'd5,4'd5}; // Phase 3
@(posedge clk);
set_data <= {1'b0,1'b1,1'b0,1'b0,4'd15,4'd9,4'd6,4'd6}; // Phase 2
@(posedge clk);
set_data <= {1'b0,1'b0,1'b1,1'b0,4'd15,4'd8,4'd7,4'd7}; // Phase 1
@(posedge clk);
set_data <= {1'b0,1'b0,1'b0,1'b0,4'd15,4'd8,4'd7,4'd7}; // Phase 0
@(posedge clk);
set_stb <= 0;
end // block: load_coeffs
initial
begin
sample_in <= 0;
repeat(40)
@(posedge strobe_in);
$display("EVEN");
sample_in <= 0;
repeat(10)
@(posedge strobe_in);
sample_in <= 1;
@(posedge strobe_in);
sample_in <= 0;
repeat(40)
@(posedge strobe_in);
sample_in <= 1;
repeat(40)
@(posedge strobe_in);
sample_in <= 0;
repeat(60)
@(posedge strobe_in);
sample_in <= 1;
repeat(2)
@(posedge strobe_in);
sample_in <= 0;
repeat(60)
@(posedge strobe_in);
$display("ODD");
sample_in <= 0;
repeat(10)
@(posedge strobe_in);
sample_in <= 1;
@(posedge strobe_in);
sample_in <= 0;
repeat(40)
@(posedge strobe_in);
sample_in <= 1;
repeat(40)
@(posedge strobe_in);
sample_in <= 0;
repeat(60)
@(posedge strobe_in);
sample_in <= 1;
repeat(2)
@(posedge strobe_in);
sample_in <= 0;
repeat(60)
@(posedge strobe_in);
$finish;
end
always @(posedge clk)
if(strobe_in)
$display(sample_in);
always @(posedge clk)
if(strobe_out)
$display("\t",sample_out);
endmodule // hb_tb
|