Simulation files of Polyphase Filter in VHDL for FPGA.
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

105 linhas
3.9KB

  1. LIBRARY ieee;
  2. USE ieee.std_logic_1164.ALL;
  3. USE ieee.numeric_std.ALL;
  4. USE work.POLY_FIR_PKG.ALL;
  5. ENTITY PARTIAL_FIR IS
  6. PORT(i_clk : IN std_logic;
  7. i_coeffs : IN vect_fir_coeffs_in;
  8. i_data : IN vect_fir_data_in;
  9. o_data : OUT smpl_fir_adder_data_out
  10. );
  11. END PARTIAL_FIR;
  12. ARCHITECTURE Adder_Tree OF PARTIAL_FIR IS
  13. SIGNAL matrix_adder_tree : matrix_adder_generic := (OTHERS => (OTHERS => (OTHERS => '0')));
  14. --SIGNAL matrix_adder_tree_signed : matrix_adder_generic_signed := (OTHERS => (OTHERS => (OTHERS => '0')));
  15. SIGNAL vect_i_coeffs : vect_fir_coeffs_in;
  16. SIGNAL mult_out : vect_mult_data_out := (OTHERS => (OTHERS => '0'));
  17. FUNCTION add (
  18. w_smpl : IN natural;
  19. in1, in2 : IN smpl_adder_generic)
  20. RETURN smpl_adder_generic IS
  21. VARIABLE smpl_stages_out : smpl_adder_generic := (OTHERS => '0');
  22. VARIABLE isigned : smpl_adder_generic_signed;
  23. BEGIN
  24. isigned(w_smpl DOWNTO 0) := signed(in1(w_smpl-1)&in1(w_smpl-1 DOWNTO 0))+signed(in2(w_smpl-1)&in2(w_smpl-1 DOWNTO 0));
  25. smpl_stages_out(w_smpl DOWNTO 0) := std_logic_vector(unsigned(isigned(w_smpl DOWNTO 0)));
  26. RETURN smpl_stages_out;
  27. END FUNCTION;
  28. BEGIN
  29. -- purpose: assign the filter in a decreasing order
  30. in_assignment : FOR i IN 0 TO cst_nb_coeffs_subfilter_in-1 GENERATE
  31. vect_i_coeffs(i) <= i_coeffs(cst_nb_coeffs_subfilter_in-1-i);
  32. END GENERATE in_assignment;
  33. -- instanciation of MULT_BLK(Mult_Path), multiplying each element from i_data
  34. -- with the correct coefficient in vect_i_coeffs
  35. mult_inst : ENTITY work.MULT_BLK(Mult_Path)
  36. PORT MAP(i_clk => i_clk,
  37. i_data => i_data,
  38. i_coeffs => vect_i_coeffs,
  39. o_data => mult_out
  40. );
  41. -- purpose: fill the input (which is the result of multiplication) of the addition tree matrix
  42. -- inputs: mult_out
  43. -- outputs: matrix_adder_tree(0)
  44. mult_out_wire : FOR i IN 0 TO cst_nb_coeffs_subfilter_in-1 GENERATE
  45. matrix_adder_tree(0)(i)(cst_w_mult_out-1 DOWNTO 0) <= mult_out(i)(cst_w_mult_out-1 DOWNTO 0);
  46. END GENERATE mult_out_wire;
  47. -- purpose: wiring: construct the adder tree. Construction:
  48. --
  49. -- 0-+--+----+->
  50. -- 1/ / /
  51. -- 2-+/ /
  52. -- 3/ /
  53. -- 4-+--+/
  54. -- 5/ /
  55. -- 6-+/
  56. -- 7/
  57. --
  58. -- inputs: matrix_adder_tree(0)
  59. -- outputs: matrix_adder_tree(cst_log2_adder_stages)
  60. --tree_generation : PROCESS (i_clk) IS
  61. --BEGIN -- PROCESS tree_generation
  62. --IF(rising_edge(i_clk)) THEN
  63. stages_loop : FOR stage IN 1 TO cst_log2_adder_stages GENERATE
  64. cell_loops : FOR cell IN 0 TO 2**(cst_log2_adder_stages-stage)-1 GENERATE
  65. matrix_adder_tree(stage)((2**stage)*cell) <= add(w_smpl => cst_w_mult_out+stage-1, in1 => matrix_adder_tree(stage-1)((2**(stage-1))*2*cell), in2 => matrix_adder_tree(stage-1)((2**(stage-1))*(2*cell+1)));
  66. END GENERATE cell_loops;
  67. END GENERATE stages_loop;
  68. --END IF;
  69. --END PROCESS tree_generation;
  70. --stages_loop : FOR stage IN 1 TO cst_log2_adder_stages GENERATE
  71. -- cell_loops : FOR cell IN 0 TO 2**(cst_log2_adder_stages-stage)-1 GENERATE
  72. -- matrix_adder_tree_signed(stage)((2**stage)*cell)(cst_w_mult_out+stage-1 DOWNTO 0) <= signed(matrix_adder_tree(stage-1)((2**stage)*cell)(cst_w_mult_out+stage-2)&matrix_adder_tree(stage-1)((2**stage)*cell)(cst_w_mult_out+stage-2 DOWNTO 0))+signed(matrix_adder_tree(stage-1)((2**(stage-1))*(2*cell+1))(cst_w_mult_out+stage-2)&matrix_adder_tree(stage-1)((2**(stage-1))*(2*cell+1))(cst_w_mult_out+stage-2 DOWNTO 0));
  73. -- matrix_adder_tree(stage)((2**stage)*cell)(cst_w_mult_out+stage-1 DOWNTO 0) <= std_logic_vector(unsigned(matrix_adder_tree_signed(stage)((2**stage)*cell)(cst_w_mult_out+stage-1 DOWNTO 0)));
  74. -- END GENERATE cell_loops;
  75. --END GENERATE stages_loop;
  76. -- take the result when adder tree finished
  77. o_data <= matrix_adder_tree(cst_log2_adder_stages)(0);
  78. END Adder_Tree;