Attention

This documentation is a work in progress. Expect to see errors and unfinished things.

iirFilter Source File

 1// Infinite Impulse Response Filter
 2//
 3// Chain of biquad elements
 4//
 5module iirFilter #(
 6    parameter STAGES            = -1,
 7    parameter DATA_WIDTH        = -1,
 8    parameter DATA_COUNT        = -1,
 9    parameter COEFFICIENT_WIDTH = -1,
10    parameter DEBUG             = "false"
11) (
12    input        sysClk,
13    input        sysGPIO_Strobe,
14    input [31:0] sysGPIO_Out,
15
16    input                                                          dataClk,
17    (*mark_debug=DEBUG*) input       [(DATA_COUNT*DATA_WIDTH)-1:0] S_TDATA,
18    (*mark_debug=DEBUG*) input                                     S_TVALID,
19    (*mark_debug=DEBUG*) output wire                               S_TREADY,
20    (*mark_debug=DEBUG*) output wire [(DATA_COUNT*DATA_WIDTH)-1:0] M_TDATA,
21    (*mark_debug=DEBUG*) output wire                               M_TVALID,
22    (*mark_debug=DEBUG*) input                                     M_TREADY
23);
24
25// Can't use $clog2 in localparam expression with this version of the tools.
26parameter STAGE_ADDRESS_WIDTH = $clog2(STAGES);
27
28reg [STAGES-1:0]sysStageSelect;
29reg       [23:0]sysCoefficientValueHigh;
30reg        [2:0]sysCoefficientAddress;
31wire [24+31-1:0]sysCoefficientValue={sysCoefficientValueHigh,sysGPIO_Out[30:0]};
32wire            sysIsValue = sysGPIO_Out[31];
33
34always @(posedge sysClk) begin
35    if (sysGPIO_Strobe && !sysIsValue) begin
36        sysCoefficientAddress <= sysGPIO_Out[2:0];
37        sysStageSelect <= 1 << sysGPIO_Out[3+:STAGE_ADDRESS_WIDTH];
38        sysCoefficientValueHigh <= sysGPIO_Out[31:8];
39    end
40end
41
42///////////////////////////////////////////////////////////////////////////////
43// Instantiate stages
44
45localparam DW = DATA_COUNT*DATA_WIDTH;
46
47wire [((STAGES+1)*DW)-1:0] interStageData;
48wire [STAGES:0] interStageValid, interStageReady;
49
50assign interStageData[0+:DW] = S_TDATA;
51assign interStageValid[0] = S_TVALID;
52assign S_TREADY = interStageReady[0];
53assign M_TDATA = interStageData[STAGES*DW+:DW];
54assign M_TVALID = interStageValid[STAGES];
55assign interStageReady[STAGES] = M_TREADY;
56
57genvar i;
58generate
59for (i = 0 ; i < STAGES ; i = i + 1) begin
60  biquad #(.DATA_WIDTH(DATA_WIDTH),
61           .DATA_COUNT(DATA_COUNT),
62           .COEFFICIENT_WIDTH(COEFFICIENT_WIDTH))
63    biquad_i(
64      .sysClk(sysClk),
65      .sysCoefficientStrobe(sysGPIO_Strobe && sysIsValue && sysStageSelect[i]),
66      .sysCoefficientAddress(sysCoefficientAddress),
67      .sysCoefficientValue(sysCoefficientValue[COEFFICIENT_WIDTH-1:0]),
68      .dataClk(dataClk),
69      .S_TDATA(interStageData[i*DW+:DW]),
70      .S_TVALID(interStageValid[i]),
71      .S_TREADY(interStageReady[i]),
72      .M_TDATA(interStageData[(i+1)*DW+:DW]),
73      .M_TVALID(interStageValid[i+1]),
74      .M_TREADY(interStageReady[i+1]));
75
76end
77endgenerate
78endmodule