| 1 |
2 |
digish |
-- Copyright (C) 2004-2005 Digish Pandya <digish.pandya@gmail.com>
|
| 2 |
|
|
|
| 3 |
|
|
-- This program is free software; you can redistribute it and/or modify
|
| 4 |
|
|
-- it under the terms of the GNU General Public License as published by
|
| 5 |
|
|
-- the Free Software Foundation; either version 2 of the License, or
|
| 6 |
|
|
-- (at your option) any later version.
|
| 7 |
|
|
--
|
| 8 |
|
|
-- This program is distributed in the hope that it will be useful,
|
| 9 |
|
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 10 |
|
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 11 |
|
|
-- GNU General Public License for more details.
|
| 12 |
|
|
--
|
| 13 |
|
|
-- You should have received a copy of the GNU General Public License
|
| 14 |
|
|
-- along with this program; if not, write to the Free Software
|
| 15 |
|
|
-- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
| 16 |
|
|
|
| 17 |
|
|
-- A.8
|
| 18 |
|
|
-- unit program module of filter core
|
| 19 |
|
|
-- we have to cascade instance of this module to make multi tap filter
|
| 20 |
|
|
|
| 21 |
|
|
|
| 22 |
|
|
library IEEE;
|
| 23 |
|
|
use IEEE.STD_LOGIC_1164.ALL;
|
| 24 |
|
|
use IEEE.STD_LOGIC_ARITH.ALL;
|
| 25 |
|
|
use IEEE.STD_LOGIC_SIGNED.ALL;
|
| 26 |
|
|
|
| 27 |
|
|
|
| 28 |
|
|
entity unit_calc is
|
| 29 |
|
|
Port ( x_in : in std_logic_vector(7 downto 0);
|
| 30 |
|
|
x_N_in : in std_logic_vector(7 downto 0);
|
| 31 |
|
|
ue_in : in std_logic_vector(7 downto 0);
|
| 32 |
|
|
y_in : in std_logic_vector(7 downto 0);
|
| 33 |
|
|
x_out : out std_logic_vector(7 downto 0);
|
| 34 |
|
|
x_N_out : out std_logic_vector(7 downto 0);
|
| 35 |
|
|
ue_out : out std_logic_vector(7 downto 0);
|
| 36 |
|
|
y_out: out std_logic_vector(7 downto 0);
|
| 37 |
|
|
clock : in std_logic);
|
| 38 |
|
|
|
| 39 |
|
|
end unit_calc;
|
| 40 |
|
|
|
| 41 |
|
|
architecture standard of unit_calc is
|
| 42 |
|
|
-- component declarations
|
| 43 |
|
|
-- 8 bit multiplier
|
| 44 |
|
|
component mul8
|
| 45 |
|
|
Port ( d1_in : in std_logic_vector(7 downto 0);
|
| 46 |
|
|
d2_in : in std_logic_vector(7 downto 0);
|
| 47 |
|
|
d_out : out std_logic_vector(15 downto 0));
|
| 48 |
|
|
|
| 49 |
|
|
end component;
|
| 50 |
|
|
-- 16 bit adder
|
| 51 |
|
|
component add16
|
| 52 |
|
|
Port ( d1_in : in std_logic_vector(15 downto 0);
|
| 53 |
|
|
d2_in : in std_logic_vector(15 downto 0);
|
| 54 |
|
|
d_out : out std_logic_vector(15 downto 0));
|
| 55 |
|
|
|
| 56 |
|
|
end component;
|
| 57 |
|
|
|
| 58 |
|
|
-- saturation circuit
|
| 59 |
|
|
component saturation
|
| 60 |
|
|
Port ( d_in : in std_logic_vector(15 downto 0);
|
| 61 |
|
|
d_out : out std_logic_vector(15 downto 0));
|
| 62 |
|
|
end component;
|
| 63 |
|
|
|
| 64 |
|
|
-- u scaling circuit
|
| 65 |
|
|
component u_scaling
|
| 66 |
|
|
Port ( d_in : in std_logic_vector(15 downto 0);
|
| 67 |
|
|
d_out : out std_logic_vector(15 downto 0);
|
| 68 |
|
|
clock : in std_logic);
|
| 69 |
|
|
end component;
|
| 70 |
|
|
|
| 71 |
|
|
-- truncation circuit
|
| 72 |
|
|
component truncation
|
| 73 |
|
|
Port ( d_in : in std_logic_vector(15 downto 0);
|
| 74 |
|
|
d_out : out std_logic_vector(7 downto 0));
|
| 75 |
|
|
end component;
|
| 76 |
|
|
-- one sample delay
|
| 77 |
|
|
component shift_1d
|
| 78 |
|
|
Port ( xin : in std_logic_vector(7 downto 0);
|
| 79 |
|
|
xout : out std_logic_vector(7 downto 0);
|
| 80 |
|
|
clock : in std_logic);
|
| 81 |
|
|
end component;
|
| 82 |
|
|
|
| 83 |
|
|
-- shift regester
|
| 84 |
|
|
component shift_1d_16
|
| 85 |
|
|
Port ( xin : in std_logic_vector(15 downto 0);
|
| 86 |
|
|
xout : out std_logic_vector(15 downto 0);
|
| 87 |
|
|
clock : in std_logic);
|
| 88 |
|
|
end component;
|
| 89 |
|
|
|
| 90 |
|
|
|
| 91 |
|
|
signal shiftx: std_logic_vector(31 downto 0);
|
| 92 |
|
|
signal shiftxn: std_logic_vector(31 downto 0);
|
| 93 |
|
|
signal shiftue: std_logic_vector(23 downto 0);
|
| 94 |
|
|
signal shifty: std_logic_vector(15 downto 0);
|
| 95 |
|
|
|
| 96 |
|
|
signal coeff8: std_logic_vector(7 downto 0);
|
| 97 |
|
|
signal coeff16:std_logic_vector(15 downto 0);
|
| 98 |
|
|
signal xnin_ue:std_logic_vector(15 downto 0);
|
| 99 |
|
|
signal xnin_ue_scaled:std_logic_vector(15 downto 0);
|
| 100 |
|
|
signal new_coeff_true:std_logic_vector(15 downto 0);
|
| 101 |
|
|
signal delayed_new_coeff_true:std_logic_vector(15 downto 0);
|
| 102 |
|
|
signal y_out16:std_logic_vector(15 downto 0);
|
| 103 |
|
|
signal y_out8:std_logic_vector(7 downto 0);
|
| 104 |
|
|
begin
|
| 105 |
|
|
-- basic pipelining
|
| 106 |
|
|
unit_process:
|
| 107 |
|
|
process (clock)
|
| 108 |
|
|
begin
|
| 109 |
|
|
if(clock'event and clock = '1') then
|
| 110 |
|
|
|
| 111 |
|
|
shiftx <= x_in & shiftx(31 downto 8);
|
| 112 |
|
|
shiftxn <= x_N_in & shiftxn(31 downto 8);
|
| 113 |
|
|
shiftue <= ue_in & shiftue(23 downto 8);
|
| 114 |
|
|
shifty <= y_in & shifty(15 downto 8);
|
| 115 |
|
|
|
| 116 |
|
|
end if;
|
| 117 |
|
|
end process;
|
| 118 |
|
|
|
| 119 |
|
|
x_out <= shiftx(7 downto 0);
|
| 120 |
|
|
x_N_out <= shiftxn(7 downto 0);
|
| 121 |
|
|
ue_out <= shiftue(7 downto 0);
|
| 122 |
|
|
|
| 123 |
|
|
mul_xnin_ue: mul8 -- no delay
|
| 124 |
|
|
port map( d1_in => x_N_in,
|
| 125 |
|
|
d2_in => ue_in,
|
| 126 |
|
|
d_out => xnin_ue);
|
| 127 |
|
|
|
| 128 |
|
|
u1:u_scaling -- 1 clock cycle
|
| 129 |
|
|
port map( d_in => xnin_ue,
|
| 130 |
|
|
d_out => xnin_ue_scaled,
|
| 131 |
|
|
clock => clock
|
| 132 |
|
|
);
|
| 133 |
|
|
|
| 134 |
|
|
add1:add16 -- no delay
|
| 135 |
|
|
port map( d1_in => xnin_ue_scaled,
|
| 136 |
|
|
d2_in => coeff16,
|
| 137 |
|
|
d_out => new_coeff_true
|
| 138 |
|
|
);
|
| 139 |
|
|
|
| 140 |
|
|
delay_2:shift_1d_16 -- each clock
|
| 141 |
|
|
port map( clock => clock,
|
| 142 |
|
|
xin => new_coeff_true,
|
| 143 |
|
|
xout => delayed_new_coeff_true
|
| 144 |
|
|
);
|
| 145 |
|
|
|
| 146 |
|
|
|
| 147 |
|
|
sat_1:saturation
|
| 148 |
|
|
port map( d_in => delayed_new_coeff_true,
|
| 149 |
|
|
d_out => coeff16
|
| 150 |
|
|
);
|
| 151 |
|
|
trunc_1:truncation
|
| 152 |
|
|
port map(
|
| 153 |
|
|
d_in => coeff16,
|
| 154 |
|
|
d_out => coeff8
|
| 155 |
|
|
);
|
| 156 |
|
|
|
| 157 |
|
|
mul_coeff_x_in:mul8
|
| 158 |
|
|
port map( d1_in => coeff8,
|
| 159 |
|
|
d2_in => shiftx(31 downto 24),
|
| 160 |
|
|
d_out => y_out16
|
| 161 |
|
|
);
|
| 162 |
|
|
trunc_2:truncation
|
| 163 |
|
|
port map(
|
| 164 |
|
|
d_in => y_out16,
|
| 165 |
|
|
d_out => y_out8
|
| 166 |
|
|
);
|
| 167 |
|
|
y_out <= y_out8 + shifty(7 downto 0);
|
| 168 |
|
|
end standard;
|
| 169 |
|
|
|