2017-04-03 12:38:50 +00:00
|
|
|
// ***************************************************************************
|
|
|
|
// ***************************************************************************
|
2023-07-06 13:54:40 +00:00
|
|
|
// Copyright (C) 2014-2023 Analog Devices, Inc. All rights reserved.
|
2017-01-31 14:21:39 +00:00
|
|
|
//
|
2017-05-31 15:15:24 +00:00
|
|
|
// In this HDL repository, there are many different and unique modules, consisting
|
|
|
|
// of various HDL (Verilog or VHDL) components. The individual modules are
|
|
|
|
// developed independently, and may be accompanied by separate and unique license
|
|
|
|
// terms.
|
|
|
|
//
|
|
|
|
// The user should read each of these license terms, and understand the
|
2018-03-14 14:45:47 +00:00
|
|
|
// freedoms and responsibilities that he or she has by using this source/core.
|
2017-05-31 15:15:24 +00:00
|
|
|
//
|
|
|
|
// This core is distributed in the hope that it will be useful, but WITHOUT ANY
|
2017-05-29 06:55:41 +00:00
|
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
|
|
|
// A PARTICULAR PURPOSE.
|
2017-01-31 14:21:39 +00:00
|
|
|
//
|
2017-05-29 06:55:41 +00:00
|
|
|
// Redistribution and use of source or resulting binaries, with or without modification
|
|
|
|
// of this file, are permitted under one of the following two license terms:
|
2017-01-31 14:21:39 +00:00
|
|
|
//
|
2017-05-17 08:44:52 +00:00
|
|
|
// 1. The GNU General Public License version 2 as published by the
|
2017-05-31 15:15:24 +00:00
|
|
|
// Free Software Foundation, which can be found in the top level directory
|
|
|
|
// of this repository (LICENSE_GPL2), and also online at:
|
|
|
|
// <https://www.gnu.org/licenses/old-licenses/gpl-2.0.html>
|
2017-05-17 08:44:52 +00:00
|
|
|
//
|
|
|
|
// OR
|
|
|
|
//
|
2017-05-31 15:15:24 +00:00
|
|
|
// 2. An ADI specific BSD license, which can be found in the top level directory
|
|
|
|
// of this repository (LICENSE_ADIBSD), and also on-line at:
|
2017-05-29 06:55:41 +00:00
|
|
|
// https://github.com/analogdevicesinc/hdl/blob/master/LICENSE_ADIBSD
|
|
|
|
// This will allow to generate bit files and not release the source code,
|
|
|
|
// as long as it attaches to an ADI device.
|
2017-01-31 14:21:39 +00:00
|
|
|
//
|
2017-04-03 12:38:50 +00:00
|
|
|
// ***************************************************************************
|
|
|
|
// ***************************************************************************
|
2017-01-31 14:21:39 +00:00
|
|
|
|
|
|
|
`timescale 1 ns / 1 ns
|
|
|
|
|
2017-04-03 12:38:50 +00:00
|
|
|
module cic_decim (
|
|
|
|
input clk,
|
|
|
|
input clk_enable,
|
2017-04-03 17:28:02 +00:00
|
|
|
input [4:0] filter_enable,
|
2017-04-03 12:38:50 +00:00
|
|
|
input reset,
|
|
|
|
input [11:0] filter_in,
|
|
|
|
input [2:0] rate_sel,
|
2017-04-03 17:28:02 +00:00
|
|
|
output [11:0] filter_out,
|
2017-04-03 12:38:50 +00:00
|
|
|
output ce_out
|
2022-04-08 10:21:52 +00:00
|
|
|
);
|
2017-04-03 12:38:50 +00:00
|
|
|
|
|
|
|
localparam NUM_STAGES = 6;
|
|
|
|
localparam DATA_WIDTH = 106;
|
|
|
|
|
|
|
|
reg [11:0] filter_input_stage = 'h00;
|
|
|
|
wire signed [DATA_WIDTH-1:0] data_stage[0:NUM_STAGES*2];
|
|
|
|
wire signed [DATA_WIDTH-1:0] data_final_stage;
|
|
|
|
|
|
|
|
reg [16:0] counter = 'h00;
|
|
|
|
reg ce_comb = 1'b0;
|
|
|
|
|
|
|
|
reg ce_out_reg = 1'b0;
|
2017-04-03 17:28:02 +00:00
|
|
|
reg [11:0] data_out = 'h00;
|
2017-04-03 12:38:50 +00:00
|
|
|
|
|
|
|
reg [15:0] rate;
|
|
|
|
|
2017-05-16 16:26:30 +00:00
|
|
|
wire [4:0] enable = (clk_enable == 1'b1) ? filter_enable : 5'b0;
|
2017-04-03 17:28:02 +00:00
|
|
|
|
2017-04-03 12:38:50 +00:00
|
|
|
always @(*) begin
|
|
|
|
case (rate_sel)
|
|
|
|
3'h1: rate <= 16'd5 - 1;
|
|
|
|
3'h2: rate <= 16'd50 - 1;
|
|
|
|
3'h3: rate <= 16'd500 - 1;
|
|
|
|
3'h6: rate <= 16'd5000 - 1;
|
|
|
|
default: rate <= 16'd50000 - 1;
|
2017-01-31 14:21:39 +00:00
|
|
|
endcase
|
|
|
|
end
|
|
|
|
|
2017-04-03 12:38:50 +00:00
|
|
|
wire [15:0] counter_in = counter[16] == 1'b1 ? rate : counter[15:0];
|
2017-01-31 14:21:39 +00:00
|
|
|
|
2017-04-03 12:38:50 +00:00
|
|
|
always @(posedge clk) begin
|
|
|
|
if (reset == 1'b1) begin
|
|
|
|
counter <= {1'b1,16'h00};
|
2017-04-03 17:28:02 +00:00
|
|
|
end else if (clk_enable == 1'b1 && enable[0] == 1'b1) begin
|
2017-04-03 12:38:50 +00:00
|
|
|
counter <= counter_in - 1'b1;
|
|
|
|
end
|
|
|
|
end
|
2017-01-31 14:21:39 +00:00
|
|
|
|
2017-04-03 12:38:50 +00:00
|
|
|
always @(posedge clk) begin
|
|
|
|
if (reset == 1'b1) begin
|
|
|
|
ce_comb <= 1'b0;
|
|
|
|
end else begin
|
2017-04-03 17:28:02 +00:00
|
|
|
ce_comb <= enable[0] & counter[16];
|
2017-04-03 12:38:50 +00:00
|
|
|
end
|
|
|
|
end
|
2017-01-31 14:21:39 +00:00
|
|
|
|
2017-04-03 12:38:50 +00:00
|
|
|
always @(posedge clk) begin
|
2017-04-03 17:28:02 +00:00
|
|
|
if (enable[0] == 1'b1) begin
|
2017-04-03 12:38:50 +00:00
|
|
|
filter_input_stage <= filter_in;
|
|
|
|
end
|
|
|
|
end
|
2017-01-31 14:21:39 +00:00
|
|
|
|
2017-04-03 12:38:50 +00:00
|
|
|
assign data_stage[0] = $signed(filter_input_stage);
|
|
|
|
|
|
|
|
generate
|
|
|
|
genvar i;
|
|
|
|
for (i = 0; i < NUM_STAGES; i = i + 1) begin
|
|
|
|
cic_int #(
|
2017-04-03 17:28:02 +00:00
|
|
|
.DATA_WIDTH(DATA_WIDTH),
|
|
|
|
.NUM_STAGES(5),
|
|
|
|
.STAGE_WIDTH(20)
|
2017-04-03 12:38:50 +00:00
|
|
|
) i_int (
|
|
|
|
.clk(clk),
|
2017-04-03 17:28:02 +00:00
|
|
|
.ce(enable),
|
2017-04-03 12:38:50 +00:00
|
|
|
.data_in(data_stage[i]),
|
2022-04-08 10:21:52 +00:00
|
|
|
.data_out(data_stage[i+1]));
|
2017-04-03 12:38:50 +00:00
|
|
|
end
|
|
|
|
endgenerate
|
|
|
|
|
2017-04-03 14:38:25 +00:00
|
|
|
cic_comb #(
|
|
|
|
.DATA_WIDTH(DATA_WIDTH),
|
2017-04-03 17:28:02 +00:00
|
|
|
.SEQ(5),
|
|
|
|
.NUM_STAGES(5),
|
|
|
|
.STAGE_WIDTH(20)
|
2017-04-03 14:38:25 +00:00
|
|
|
) i_comb0 (
|
|
|
|
.clk(clk),
|
|
|
|
.ce(ce_comb),
|
2017-04-03 17:28:02 +00:00
|
|
|
.enable(filter_enable),
|
2017-04-03 14:38:25 +00:00
|
|
|
.data_in(data_stage[6]),
|
2022-04-08 10:21:52 +00:00
|
|
|
.data_out(data_stage[11]));
|
2017-04-03 14:38:25 +00:00
|
|
|
|
|
|
|
cic_comb #(
|
|
|
|
.DATA_WIDTH(DATA_WIDTH),
|
2017-04-03 17:28:02 +00:00
|
|
|
.SEQ(1),
|
|
|
|
.NUM_STAGES(5),
|
|
|
|
.STAGE_WIDTH(20)
|
2017-04-03 14:38:25 +00:00
|
|
|
) i_comb1 (
|
|
|
|
.clk(clk),
|
|
|
|
.ce(ce_comb),
|
2017-04-03 17:28:02 +00:00
|
|
|
.enable(filter_enable),
|
2017-04-03 14:38:25 +00:00
|
|
|
.data_in(data_stage[11]),
|
2022-04-08 10:21:52 +00:00
|
|
|
.data_out(data_stage[12]));
|
2017-04-03 14:38:25 +00:00
|
|
|
|
2017-04-03 12:38:50 +00:00
|
|
|
assign data_final_stage = data_stage[2*NUM_STAGES];
|
|
|
|
|
|
|
|
always @(posedge clk) begin
|
|
|
|
if (ce_comb == 1'b1) begin
|
|
|
|
case (rate_sel)
|
2017-04-03 17:28:02 +00:00
|
|
|
'h1: data_out <= data_final_stage[25:14];
|
|
|
|
'h2: data_out <= data_final_stage[45:34];
|
|
|
|
'h3: data_out <= data_final_stage[65:54];
|
|
|
|
'h6: data_out <= data_final_stage[85:74];
|
|
|
|
default: data_out <= data_final_stage[105:94];
|
2017-04-03 12:38:50 +00:00
|
|
|
endcase
|
|
|
|
end
|
|
|
|
ce_out_reg <= ce_comb;
|
|
|
|
end
|
2017-01-31 14:21:39 +00:00
|
|
|
|
|
|
|
assign ce_out = ce_out_reg;
|
2017-04-03 12:38:50 +00:00
|
|
|
assign filter_out = data_out;
|
|
|
|
|
2017-01-31 14:21:39 +00:00
|
|
|
endmodule // cic_decim
|