1 | library ieee;
|
2 |
|
3 | use ieee.std_logic_1164.all;
|
4 | use ieee.std_logic_arith.all;
|
5 | use ieee.std_logic_signed.all;
|
6 | --use ieee.std_logic_unsigned.all;
|
7 |
|
8 | package FILTER_PACK is
|
9 | constant K: integer := 6; -- Anzahl Filterkoeffizienten
|
10 | constant EIN_SIZE: integer := 9; -- Bitbreite Eingang
|
11 | constant AUS_SIZE: integer := 11; -- Biltbreite Ausgang
|
12 | constant MULT_SIZE: integer := 18; -- Multiplizierer Bitbreite 2*EIN_SIZE
|
13 | constant ADD_SIZE: integer := 19; -- Addierer Bitbreite MULT_SIZE + ld(K)-1
|
14 | constant PIPE: integer := 5; -- Anzahl von Stufen im Multiplizierer-Pipeline
|
15 | constant FACTOR: integer := 8; -- Ergebnis geteilt durch 2^FACTOR
|
16 | end FILTER_PACK;
|
17 |
|
18 | library ieee;
|
19 |
|
20 | use ieee.std_logic_1164.all;
|
21 | use ieee.std_logic_arith.all;
|
22 | use ieee.std_logic_signed.all;
|
23 | --use ieee.std_logic_unsigned.all;
|
24 |
|
25 | library work;
|
26 | use work.FILTER_PACK.all;
|
27 |
|
28 | entity FILTER is
|
29 | port (clk: in std_logic;
|
30 | load_x: in std_logic;
|
31 | data_in: in std_logic_vector(EIN_SIZE - 1 downto 0);
|
32 | koeff_in: in std_logic_vector(EIN_SIZE - 1 downto 0);
|
33 | data_out: out std_logic_vector(AUS_SIZE - 1 downto 0));
|
34 | end FILTER;
|
35 |
|
36 | architecture arch of filter is
|
37 | subtype EIN_BIT is std_logic_vector(EIN_SIZE - 1 downto 0);
|
38 | subtype MULT_BIT is std_logic_vector(MULT_SIZE - 1 downto 0);
|
39 | subtype ADD_BIT is std_logic_vector(ADD_SIZE - 1 downto 0);
|
40 | type ARRAY_EIN_BIT is array (0 to K - 1) of EIN_BIT;
|
41 | type ARRAY_MULT_BIT is array (0 to K - 1) of MULT_BIT;
|
42 | type ARRAY_ADD_BIT is array (0 to K - 1) of ADD_BIT;
|
43 |
|
44 | signal ein: EIN_BIT;
|
45 | signal aus: ADD_BIT;
|
46 | signal koeff: ARRAY_EIN_BIT; -- Koeffizient array
|
47 | signal prod: ARRAY_MULT_BIT; -- Produkt array
|
48 | signal sum: ARRAY_ADD_BIT; -- Addierer array
|
49 |
|
50 | component pipelined_multiplier is
|
51 | generic (
|
52 | size: integer;
|
53 | level: integer);
|
54 |
|
55 | port (
|
56 | a : in std_logic_vector (size-1 downto 0) ;
|
57 | b : in std_logic_vector (size-1 downto 0) ;
|
58 | clk : in std_logic;
|
59 | res : out std_logic_vector (2*size-1 downto 0));
|
60 |
|
61 | end component pipelined_multiplier ;
|
62 |
|
63 |
|
64 | begin
|
65 |
|
66 | LOAD: process -- Data oder Koeffizienten werden geladen
|
67 |
|
68 | begin
|
69 | wait until clk = '1';
|
70 | if (load_x = '1') then
|
71 | koeff(K - 1) <= koeff_in; -- Koeffizient in den Register speichern
|
72 | for i in K-2 downto 0 loop
|
73 | koeff(i) <= koeff(i + 1);
|
74 | end loop;
|
75 | else
|
76 | ein <= data_in; -- sonst Data laden
|
77 | end if;
|
78 | end process LOAD;
|
79 |
|
80 | SUMM: process (clk) -- in diesem Pozess wird die Summe gebildet
|
81 | begin
|
82 | if clk'event and (clk = '1') then
|
83 | for i in 0 to k - 2 loop
|
84 | sum(i) <= (prod(i)(MULT_SIZE - 1) & prod(i)) + sum(i + 1);
|
85 | --sum(i) <= "0" & prod(i) + sum(i + 1);
|
86 | end loop;
|
87 | sum(k - 1) <= prod(k - 1)(MULT_SIZE - 1) & prod(k - 1);
|
88 | --sum(k - 1) <= "0" & prod(k - 1);
|
89 | end if;
|
90 | aus <= sum(0);
|
91 | end process SUMM;
|
92 |
|
93 | MUL_GEN: for i in 0 to k - 1 generate
|
94 | mul: pipelined_multiplier
|
95 | generic map (size => EIN_SIZE,
|
96 | level => PIPE)
|
97 | port map (a => ein,
|
98 | b => koeff(i),
|
99 | clk => clk,
|
100 | res => prod(i));
|
101 | end generate;
|
102 |
|
103 | data_out <= aus(ADD_SIZE - 1 downto FACTOR);
|
104 |
|
105 | end arch;
|