Imported Upstream version 3.2.2
[debian/gnuradio] / gr-gpio / src / fpga / lib / integrator.v
1 // -*- verilog -*-
2 //
3 //  USRP - Universal Software Radio Peripheral
4 //
5 //  Copyright (C) 2003 Matt Ettus
6 //  Copyright (C) 2008 Corgan Enterprises LLC
7 //
8 //  This program is free software; you can redistribute it and/or modify
9 //  it under the terms of the GNU General Public License as published by
10 //  the Free Software Foundation; either version 2 of the License, or
11 //  (at your option) any later version.
12 //
13 //  This program is distributed in the hope that it will be useful,
14 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
15 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 //  GNU General Public License for more details.
17 //
18 //  You should have received a copy of the GNU General Public License
19 //  along with this program; if not, write to the Free Software
20 //  Foundation, Inc., 51 Franklin Street, Boston, MA  02110-1301  USA
21 //
22
23 // Integrate and dump decimation filter
24 // 
25 // Functionally equivalent to single-stage CIC decimator, simpler code
26 // Results in single sample impulse response at decimated rate
27
28 module integrator
29   ( clock,reset,enable,rate,strobe_in,strobe_out,signal_in,signal_out);
30    parameter bw = 16;
31    parameter maxbitgain = 8;
32    
33    input       clock;
34    input       reset;
35    input       enable;
36    input [7:0] rate;
37    input       strobe_in;
38    input       strobe_out;      
39
40    input  [bw-1:0] signal_in;
41    wire   [bw-1:0] signal_out_unreg;
42    output [bw-1:0] signal_out;
43    reg    [bw-1:0] signal_out;
44
45    wire [bw+maxbitgain-1:0] signal_in_ext;
46    reg  [bw+maxbitgain-1:0] accum;
47    reg  [bw+maxbitgain-1:0] dump;
48
49    sign_extend #(bw,bw+maxbitgain) 
50       ext_input (.in(signal_in),.out(signal_in_ext));
51    
52    // Integrate samples, dump on strobe out
53    always @(posedge clock)
54      if (reset | ~enable)
55        begin
56          accum <= 0;
57          dump <= 0;
58        end
59      else if (enable && strobe_in)
60         if (~strobe_out)
61            accum <= accum + signal_in_ext;
62         else
63            begin
64              dump <= accum;
65              accum <= signal_in_ext;
66            end
67    
68    // Normalize for integration bit gain
69    integ_shifter #(bw)
70         shifter(rate,dump,signal_out_unreg);
71
72    always @(posedge clock)
73      signal_out <= #1 signal_out_unreg;
74    
75 endmodule // integrator