dtung

fir.v

Jun 23rd, 2021
883
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. `timescale 1ns / 1ps
  2. //////////////////////////////////////////////////////////////////////////////////
  3. // Company:
  4. // Engineer:
  5. //
  6. // Create Date: 06/22/2021 04:40:09 PM
  7. // Design Name:
  8. // Module Name: fir
  9. // Project Name:
  10. // Target Devices:
  11. // Tool Versions:
  12. // Description:
  13. //
  14. // Dependencies:
  15. //
  16. // Revision:
  17. // Revision 0.01 - File Created
  18. // Additional Comments:
  19. //
  20. //////////////////////////////////////////////////////////////////////////////////
  21.  
  22.  
  23. module fir #(parameter COEFF_WIDTH = 8, DATA_WIDTH = 16, OUT_WIDTH = 32, FIR_LENGTH = 16) (
  24.         input clk,
  25.         input reset,
  26.         input coeff_en,
  27.         input signed [COEFF_WIDTH-1:0] coeff,
  28.         input data_en,
  29.         input signed [DATA_WIDTH-1:0] data,
  30.         output reg out_en,
  31.         output reg signed [OUT_WIDTH-1:0] out
  32.     );
  33.    
  34.     reg signed [COEFF_WIDTH-1:0] w[FIR_LENGTH-1:0];
  35.     reg signed [DATA_WIDTH-1:0] x[FIR_LENGTH-1:0];
  36.     reg signed [OUT_WIDTH-1:0] y[FIR_LENGTH-1:0], sum;
  37.     reg mult_en, sum_en;
  38.    
  39.     reg [$clog2(FIR_LENGTH):0] i;
  40.  
  41.     always @(posedge clk, posedge reset) begin
  42.         if (reset) begin
  43.             for (i = 0; i < FIR_LENGTH; i = i+1) begin
  44.                 w[i] <= 0; x[i] <= 0; y[i] <= 0;
  45.             end
  46.             mult_en <= 0; sum_en <= 0; out_en <= 0; out <= 0;
  47.         end else begin
  48.             if (coeff_en) begin
  49.                 w[0] <= coeff;
  50.                 for (i = 1; i < FIR_LENGTH; i = i+1)
  51.                     w[i] <= w[i-1];
  52.             end  
  53.             if (data_en) begin
  54.                 x[0] <= data;
  55.                 for (i = 1; i < FIR_LENGTH; i = i+1)
  56.                     x[i] <= x[i-1];
  57.             end          
  58.             if (mult_en)
  59.                 for (i = 0; i < FIR_LENGTH; i = i+1)
  60.                     y[i] <= x[i]*w[i];
  61.                    
  62.             mult_en <= data_en; sum_en <= mult_en; out_en <= sum_en;        
  63.             if (sum_en) out <= sum;
  64.         end
  65.     end
  66.          
  67.     always @(*) begin
  68.         sum = 0;
  69.         for (i = 0; i < FIR_LENGTH; i = i+1)
  70.             sum = sum + y[i];
  71.     end
  72.  
  73. endmodule
RAW Paste Data