1 |
c62f5734
|
Christian Daniel
|
---------------------------------------------------------------------------------------------------
|
2 |
|
|
-- Filename : mt_fil_mac_slow.vhd
|
3 |
|
|
-- Project : maintech filter toolbox
|
4 |
|
|
-- Purpose : MAC cell for FIR-like filters
|
5 |
|
|
-- - version for 'slow' filter versions
|
6 |
|
|
---------------------------------------------------------------------------------------------------
|
7 |
|
|
|
8 |
|
|
-----------------------------------------------------------------------------------
|
9 |
|
|
-- Copyright (C) 2012 maintech GmbH, Otto-Hahn-Str. 15, 97204 Hoechberg, Germany --
|
10 |
|
|
-- written by Matthias Kleffel --
|
11 |
|
|
-- --
|
12 |
|
|
-- This program is free software; you can redistribute it and/or modify --
|
13 |
|
|
-- it under the terms of the GNU General Public License as published by --
|
14 |
|
|
-- the Free Software Foundation as version 3 of the License, or --
|
15 |
|
|
-- --
|
16 |
|
|
-- This program is distributed in the hope that it will be useful, --
|
17 |
|
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of --
|
18 |
|
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the --
|
19 |
|
|
-- GNU General Public License V3 for more details. --
|
20 |
|
|
-- --
|
21 |
|
|
-- You should have received a copy of the GNU General Public License --
|
22 |
|
|
-- along with this program. If not, see <http://www.gnu.org/licenses/>. --
|
23 |
|
|
-----------------------------------------------------------------------------------
|
24 |
|
|
|
25 |
|
|
-------------------------------------------------------------------------------
|
26 |
|
|
-- mt_fil_mac_slow ------------------------------------------------------------
|
27 |
|
|
-------------------------------------------------------------------------------
|
28 |
|
|
|
29 |
|
|
library ieee;
|
30 |
|
|
use ieee.std_logic_1164.all;
|
31 |
|
|
use ieee.numeric_std.all;
|
32 |
|
|
library work;
|
33 |
|
|
use work.all;
|
34 |
|
|
use work.mt_toolbox.all;
|
35 |
|
|
use work.mt_filter.all;
|
36 |
|
|
|
37 |
|
|
entity mt_fil_mac_slow is
|
38 |
|
|
port (
|
39 |
|
|
-- common
|
40 |
|
|
clk : in std_logic;
|
41 |
|
|
reset : in std_logic;
|
42 |
|
|
|
43 |
|
|
-- control-path
|
44 |
|
|
start : in std_logic;
|
45 |
|
|
active : in std_logic;
|
46 |
|
|
presub : in std_logic;
|
47 |
|
|
|
48 |
|
|
-- data input
|
49 |
|
|
smp1 : in fir_dataword18;
|
50 |
|
|
smp2 : in fir_dataword18;
|
51 |
|
|
coeff : in fir_dataword18;
|
52 |
|
|
|
53 |
|
|
-- data output
|
54 |
|
|
dnew : out std_logic;
|
55 |
|
|
dout : out fir_dataword18
|
56 |
|
|
);
|
57 |
|
|
end mt_fil_mac_slow;
|
58 |
|
|
|
59 |
|
|
architecture rtl of mt_fil_mac_slow is
|
60 |
|
|
|
61 |
|
|
-- rounding constant (16 bits will get truncated)
|
62 |
|
|
constant RNDVAL : natural := (2**16/2);
|
63 |
|
|
|
64 |
|
|
-- control signals
|
65 |
|
|
signal done : std_logic;
|
66 |
|
|
signal active_del : std_logic_vector(2 downto 0);
|
67 |
|
|
signal start_del : std_logic_vector(2 downto 0);
|
68 |
|
|
signal done_del : std_logic_vector(2 downto 0);
|
69 |
|
|
|
70 |
|
|
-- data registers
|
71 |
|
|
signal psreg : std_logic;
|
72 |
|
|
signal dreg : signed(17 downto 0);
|
73 |
|
|
signal b0reg : signed(17 downto 0);
|
74 |
|
|
signal b1reg : signed(18 downto 0);
|
75 |
|
|
signal a0reg : signed(17 downto 0);
|
76 |
|
|
signal a1reg : signed(17 downto 0);
|
77 |
|
|
signal mreg : signed(35 downto 0);
|
78 |
|
|
signal preg : signed(35 downto 0);
|
79 |
|
|
|
80 |
|
|
begin
|
81 |
|
|
|
82 |
|
|
-- create done-flag after 'active' goes low or 'start' is set while still active
|
83 |
|
|
done <= (start or (not active)) and active_del(0);
|
84 |
|
|
|
85 |
|
|
-- create delayed control-signals
|
86 |
|
|
process(clk)
|
87 |
|
|
begin
|
88 |
|
|
if rising_edge(clk) then
|
89 |
|
|
active_del <= active_del(active_del'left-1 downto 0) & active;
|
90 |
|
|
start_del <= start_del(start_del'left-1 downto 0) & start;
|
91 |
|
|
done_del <= done_del(done_del'left-1 downto 0) & done;
|
92 |
|
|
end if;
|
93 |
|
|
end process;
|
94 |
|
|
|
95 |
|
|
-- do math
|
96 |
|
|
process(clk)
|
97 |
|
|
begin
|
98 |
|
|
if rising_edge(clk) then
|
99 |
|
|
-- simple storage registers
|
100 |
|
|
psreg <= presub;
|
101 |
|
|
dreg <= smp1;
|
102 |
|
|
b0reg <= smp2;
|
103 |
|
|
a0reg <= coeff;
|
104 |
|
|
a1reg <= a0reg;
|
105 |
|
|
|
106 |
|
|
-- pre-adder
|
107 |
|
|
if psreg='1'
|
108 |
|
|
then b1reg <= resize(b0reg,19) - resize(dreg,19);
|
109 |
|
|
else b1reg <= resize(b0reg,19) + resize(dreg,19);
|
110 |
|
|
end if;
|
111 |
|
|
|
112 |
|
|
-- multiplier
|
113 |
|
|
mreg <= a1reg * b1reg(18 downto 1);
|
114 |
|
|
|
115 |
|
|
-- post-adder / accumulator
|
116 |
|
|
if active_del(2)='1' then
|
117 |
|
|
if start_del(2)='1'
|
118 |
|
|
then preg <= mreg + to_signed(RNDVAL,36);
|
119 |
|
|
else preg <= mreg + preg;
|
120 |
|
|
end if;
|
121 |
|
|
end if;
|
122 |
|
|
end if;
|
123 |
|
|
end process;
|
124 |
|
|
|
125 |
|
|
-- update output
|
126 |
|
|
process(reset, clk)
|
127 |
|
|
begin
|
128 |
|
|
if reset='1' then
|
129 |
|
|
dnew <= '0';
|
130 |
|
|
dout <= (others=>'0');
|
131 |
|
|
elsif rising_edge(clk) then
|
132 |
|
|
if done_del(2)='1' then
|
133 |
|
|
dnew <= '1';
|
134 |
|
|
if preg(35)='0' and preg(34 downto 33)/="00" then
|
135 |
|
|
dout <= to_signed(2**17-1,18);
|
136 |
|
|
elsif preg(35)='1' and preg(34 downto 33)/="11" then
|
137 |
|
|
dout <= to_signed(-(2**17),18);
|
138 |
|
|
else
|
139 |
|
|
dout <= preg(33 downto 16);
|
140 |
|
|
end if;
|
141 |
|
|
else
|
142 |
|
|
dnew <= '0';
|
143 |
|
|
end if;
|
144 |
|
|
end if;
|
145 |
|
|
end process;
|
146 |
|
|
end rtl;
|