1- library ieee;
2- use ieee.std_logic_1164.all ;
3- use ieee.numeric_std.all ;
1+ -- library ieee;
2+ -- use ieee.std_logic_1164.all;
3+ -- use ieee.numeric_std.all;
44
5- package ClariFi is
6- type CoeffiecientArray is array (natural range <> ) of integer ;
7- type RegArray is array (natural range <> ) of signed ;
8- type SLVArray is array (natural range <> ) of std_logic_vector ;
9- end package ;
5+ -- package ClariFi is
6+ -- type CoeffiecientArray is array(natural range <>) of integer;
7+ -- type RegArray is array(natural range <>) of signed;
8+ -- type SLVArray is array(natural range <>) of std_logic_vector;
9+ -- end package;
1010
1111library ieee;
1212use ieee.std_logic_1164.all ;
1313use ieee.numeric_std.all ;
14+ use IEEE.math_real.all ;
1415use work.ClariFi.all ;
1516
1617entity BasicFIR is
1718 generic (
1819 RESOLUTION : natural
1920 ; NUM_TAPS : natural
20- ; COEFFICIENTS : CoeffiecientArray(0 to NUM_TAPS- 1 )
21+ -- ; COEFFICIENTS : CoeffiecientArray(0 to NUM_TAPS-1)
2122 );
2223 port (
2324 clk, rst, en : in std_logic
2425 ; sample : in std_logic_vector (RESOLUTION- 1 downto 0 )
26+ ; coefficients : RegArray(0 to NUM_TAPS- 1 )
2527 ; filtered : out std_logic_vector (RESOLUTION- 1 downto 0 )
2628 );
2729end entity ;
@@ -30,7 +32,7 @@ architecture SingleOrder of BasicFIR is
3032 signal taps : RegArray(0 to NUM_TAPS- 1 )(RESOLUTION- 1 downto 0 );
3133 signal multiplies : RegArray(0 to NUM_TAPS- 1 )((RESOLUTION* 2 )- 1 downto 0 );
3234 signal multiplySLVs : SLVArray(0 to NUM_TAPS- 1 )((RESOLUTION* 2 )- 1 downto 0 );
33- signal accumulator : signed ((RESOLUTION* 2 ) - 1 downto 0 );
35+ signal accumulator : signed ((RESOLUTION * 2 ) + natural ( ceil ( log2 ( real (NUM_TAPS)))) - 1 downto 0 );
3436begin
3537 LoadTaps: process (clk, rst, en)
3638 begin
@@ -44,30 +46,40 @@ begin
4446 end loop ;
4547 end if ;
4648 end process ;
47-
49+
4850 uMultipliers: for i in 0 to NUM_TAPS- 1 generate
4951 uMultiplier: entity work.SignedMultDSP
5052 port map (
5153 CLK => clk
5254 , A => std_logic_vector (taps(i))
53- , B => std_logic_vector (to_signed ( COEFFICIENTS(i), RESOLUTION ))
55+ , B => std_logic_vector (COEFFICIENTS(i))
5456 , P => multiplySLVs(i)
5557 );
5658
5759 multiplies(i) <= signed (multiplySLVs(i));
5860 end generate ;
5961
60- process (multiplies)
61- variable acc : signed (accumulator'range ) := (others => '0' );
62- begin
63- acc := (others => '0' );
62+ -- proc_accumulator: process (multiplies)
63+ -- variable acc : signed(accumulator'range) := (others => '0');
64+ -- begin
65+ -- acc := (others => '0');
6466
65- for i in 0 to NUM_TAPS- 1 loop
66- acc := acc + multiplies(i);
67- end loop ;
67+ -- for i in 0 to NUM_TAPS-1 loop
68+ -- acc := acc + multiplies(i);
69+ -- end loop;
6870
69- accumulator <= acc;
70- end process ;
71+ -- accumulator <= acc;
72+ -- end process;
73+
74+ uAdderTree: entity work.AdderTree
75+ generic map (
76+ WIDTH => RESOLUTION* 2
77+ , NUM_OPERANDS => NUM_TAPS
78+ )
79+ port map (
80+ operands => multiplies
81+ , sum => accumulator
82+ );
7183
7284 filtered <= std_logic_vector (accumulator(accumulator'high downto accumulator'high - (RESOLUTION - 1 )));
7385end architecture ;
0 commit comments