我试图用VHDL编写一个串行fir过滤器。我用DA来做。 这是我的代码:
LUT表:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
entity lut_table is
port(
x0,x1,x2,x3,x4,x5,x6,x7,x8 : in std_logic;
table_out : out std_logic_vector(13 downto 0)
);
end lut_table;
architecture arch of lut_table is
signal table_in : std_logic_vector( 8 downto 0);
begin
table_in <= x8 & x7 & x6 & x5 & x4 & x3 & x2 & x1 & x0;
with table_in select
table_out <= "00000000000000" when "000000000",
"00000001101110" when "000000001",
"11111110111011" when "000000010",
"00000000101001" when "000000011",
"11111011000000" when "000000100",
"11111100101110" when "000000101",
"11111001111011" when "000000110",
"11111011101001" when "000000111",
"00010001000101" when "000001000",
"00010010110011" when "000001001",
"00010000000000" when "000001010",
"00010001101110" when "000001011",
"00001100000101" when "000001100",
"00001101110011" when "000001101",
"00001011000000" when "000001110",
"00001100101110" when "000001111",
"00100110100110" when "000010000",
"00101000010100" when "000010001",
"00100101100001" when "000010010",
"00100111001111" when "000010011",
"00100001100110" when "000010100",
"00100011010100" when "000010101",
"00100000100001" when "000010110",
"00100010001111" when "000010111",
"00110111101011" when "000011000",
"00111001011001" when "000011001",
"00110110100110" when "000011010",
"00111000010100" when "000011011",
"00110010101011" when "000011100",
"00110100011001" when "000011101",
"00110001100110" when "000011110",
"00110011010100" when "000011111",
"00010001000101" when "000100000",
"00010010110011" when "000100001",
"00010000000000" when "000100010",
"00010001101110" when "000100011",
"00001100000101" when "000100100",
"00001101110011" when "000100101",
"00001011000000" when "000100110",
"00001100101110" when "000100111",
"00100010001010" when "000101000",
"00100011111000" when "000101001",
"00100001000101" when "000101010",
"00100010110011" when "000101011",
"00011101001010" when "000101100",
"00011110111000" when "000101101",
"00011100000101" when "000101110",
"00011101110011" when "000101111",
"00110111101011" when "000110000",
"00111001011001" when "000110001",
"00110110100110" when "000110010",
"00111000010100" when "000110011",
"00110010101011" when "000110100",
"00110100011001" when "000110101",
"00110001100110" when "000110110",
"00110011010100" when "000110111",
"01001000110000" when "000111000",
"01001010011110" when "000111001",
"01000111101011" when "000111010",
"01001001011001" when "000111011",
"01000011110000" when "000111100",
"01000101011110" when "000111101",
"01000010101011" when "000111110",
"01000100011001" when "000111111",
"11111011000000" when "001000000",
"11111100101110" when "001000001",
"11111001111011" when "001000010",
"11111011101001" when "001000011",
"11110110000000" when "001000100",
"11110111101110" when "001000101",
"11110100111011" when "001000110",
"11110110101001" when "001000111",
"00001100000101" when "001001000",
"00001101110011" when "001001001",
"00001011000000" when "001001010",
"00001100101110" when "001001011",
"00000111000101" when "001001100",
"00001000110011" when "001001101",
"00000110000000" when "001001110",
"00000111101110" when "001001111",
"00100001100110" when "001010000",
"00100011010100" when "001010001",
"00100000100001" when "001010010",
"00100010001111" when "001010011",
"00011100100110" when "001010100",
"00011110010100" when "001010101",
"00011011100001" when "001010110",
"00011101001111" when "001010111",
"00110010101011" when "001011000",
"00110100011001" when "001011001",
"00110001100110" when "001011010",
"00110011010100" when "001011011",
"00101101101011" when "001011100",
"00101111011001" when "001011101",
"00101100100110" when "001011110",
"00101110010100" when "001011111",
"00001100000101" when "001100000",
"00001101110011" when "001100001",
"00001011000000" when "001100010",
"00001100101110" when "001100011",
"00000111000101" when "001100100",
"00001000110011" when "001100101",
"00000110000000" when "001100110",
"00000111101110" when "001100111",
"00011101001010" when "001101000",
"00011110111000" when "001101001",
"00011100000101" when "001101010",
"00011101110011" when "001101011",
"00011000001010" when "001101100",
"00011001111000" when "001101101",
"00010111000101" when "001101110",
"00011000110011" when "001101111",
"00110010101011" when "001110000",
"00110100011001" when "001110001",
"00110001100110" when "001110010",
"00110011010100" when "001110011",
"00101101101011" when "001110100",
"00101111011001" when "001110101",
"00101100100110" when "001110110",
"00101110010100" when "001110111",
"01000011110000" when "001111000",
"01000101011110" when "001111001",
"01000010101011" when "001111010",
"01000100011001" when "001111011",
"00111110110000" when "001111100",
"01000000011110" when "001111101",
"00111101101011" when "001111110",
"00111111011001" when "001111111",
"11111110111011" when "010000000",
"00000000101001" when "010000001",
"11111101110110" when "010000010",
"11111111100100" when "010000011",
"11111001111011" when "010000100",
"11111011101001" when "010000101",
"11111000110110" when "010000110",
"11111010100100" when "010000111",
"00010000000000" when "010001000",
"00010001101110" when "010001001",
"00001110111011" when "010001010",
"00010000101001" when "010001011",
"00001011000000" when "010001100",
"00001100101110" when "010001101",
"00001001111011" when "010001110",
"00001011101001" when "010001111",
"00100101100001" when "010010000",
"00100111001111" when "010010001",
"00100100011100" when "010010010",
"00100110001010" when "010010011",
"00100000100001" when "010010100",
"00100010001111" when "010010101",
"00011111011100" when "010010110",
"00100001001010" when "010010111",
"00110110100110" when "010011000",
"00111000010100" when "010011001",
"00110101100001" when "010011010",
"00110111001111" when "010011011",
"00110001100110" when "010011100",
"00110011010100" when "010011101",
"00110000100001" when "010011110",
"00110010001111" when "010011111",
"00010000000000" when "010100000",
"00010001101110" when "010100001",
"00001110111011" when "010100010",
"00010000101001" when "010100011",
"00001011000000" when "010100100",
"00001100101110" when "010100101",
"00001001111011" when "010100110",
"00001011101001" when "010100111",
"00100001000101" when "010101000",
"00100010110011" when "010101001",
"00100000000000" when "010101010",
"00100001101110" when "010101011",
"00011100000101" when "010101100",
"00011101110011" when "010101101",
"00011011000000" when "010101110",
"00011100101110" when "010101111",
"00110110100110" when "010110000",
"00111000010100" when "010110001",
"00110101100001" when "010110010",
"00110111001111" when "010110011",
"00110001100110" when "010110100",
"00110011010100" when "010110101",
"00110000100001" when "010110110",
"00110010001111" when "010110111",
"01000111101011" when "010111000",
"01001001011001" when "010111001",
"01000110100110" when "010111010",
"01001000010100" when "010111011",
"01000010101011" when "010111100",
"01000100011001" when "010111101",
"01000001100110" when "010111110",
"01000011010100" when "010111111",
"11111001111011" when "011000000",
"11111011101001" when "011000001",
"11111000110110" when "011000010",
"11111010100100" when "011000011",
"11110100111011" when "011000100",
"11110110101001" when "011000101",
"11110011110110" when "011000110",
"11110101100100" when "011000111",
"00001011000000" when "011001000",
"00001100101110" when "011001001",
"00001001111011" when "011001010",
"00001011101001" when "011001011",
"00000110000000" when "011001100",
"00000111101110" when "011001101",
"00000100111011" when "011001110",
"00000110101001" when "011001111",
"00100000100001" when "011010000",
"00100010001111" when "011010001",
"00011111011100" when "011010010",
"00100001001010" when "011010011",
"00011011100001" when "011010100",
"00011101001111" when "011010101",
"00011010011100" when "011010110",
"00011100001010" when "011010111",
"00110001100110" when "011011000",
"00110011010100" when "011011001",
"00110000100001" when "011011010",
"00110010001111" when "011011011",
"00101100100110" when "011011100",
"00101110010100" when "011011101",
"00101011100001" when "011011110",
"00101101001111" when "011011111",
"00001011000000" when "011100000",
"00001100101110" when "011100001",
"00001001111011" when "011100010",
"00001011101001" when "011100011",
"00000110000000" when "011100100",
"00000111101110" when "011100101",
"00000100111011" when "011100110",
"00000110101001" when "011100111",
"00011100000101" when "011101000",
"00011101110011" when "011101001",
"00011011000000" when "011101010",
"00011100101110" when "011101011",
"00010111000101" when "011101100",
"00011000110011" when "011101101",
"00010110000000" when "011101110",
"00010111101110" when "011101111",
"00110001100110" when "011110000",
"00110011010100" when "011110001",
"00110000100001" when "011110010",
"00110010001111" when "011110011",
"00101100100110" when "011110100",
"00101110010100" when "011110101",
"00101011100001" when "011110110",
"00101101001111" when "011110111",
"01000010101011" when "011111000",
"01000100011001" when "011111001",
"01000001100110" when "011111010",
"01000011010100" when "011111011",
"00111101101011" when "011111100",
"00111111011001" when "011111101",
"00111100100110" when "011111110",
"00111110010100" when "011111111",
"00000001101110" when "100000000",
"00000011011100" when "100000001",
"00000000101001" when "100000010",
"00000010010111" when "100000011",
"11111100101110" when "100000100",
"11111110011100" when "100000101",
"11111011101001" when "100000110",
"11111101010111" when "100000111",
"00010010110011" when "100001000",
"00010100100001" when "100001001",
"00010001101110" when "100001010",
"00010011011100" when "100001011",
"00001101110011" when "100001100",
"00001111100001" when "100001101",
"00001100101110" when "100001110",
"00001110011100" when "100001111",
"00101000010100" when "100010000",
"00101010000010" when "100010001",
"00100111001111" when "100010010",
"00101000111101" when "100010011",
"00100011010100" when "100010100",
"00100101000010" when "100010101",
"00100010001111" when "100010110",
"00100011111101" when "100010111",
"00111001011001" when "100011000",
"00111011000111" when "100011001",
"00111000010100" when "100011010",
"00111010000010" when "100011011",
"00110100011001" when "100011100",
"00110110000111" when "100011101",
"00110011010100" when "100011110",
"00110101000010" when "100011111",
"00010010110011" when "100100000",
"00010100100001" when "100100001",
"00010001101110" when "100100010",
"00010011011100" when "100100011",
"00001101110011" when "100100100",
"00001111100001" when "100100101",
"00001100101110" when "100100110",
"00001110011100" when "100100111",
"00100011111000" when "100101000",
"00100101100110" when "100101001",
"00100010110011" when "100101010",
"00100100100001" when "100101011",
"00011110111000" when "100101100",
"00100000100110" when "100101101",
"00011101110011" when "100101110",
"00011111100001" when "100101111",
"00111001011001" when "100110000",
"00111011000111" when "100110001",
"00111000010100" when "100110010",
"00111010000010" when "100110011",
"00110100011001" when "100110100",
"00110110000111" when "100110101",
"00110011010100" when "100110110",
"00110101000010" when "100110111",
"01001010011110" when "100111000",
"01001100001100" when "100111001",
"01001001011001" when "100111010",
"01001011000111" when "100111011",
"01000101011110" when "100111100",
"01000111001100" when "100111101",
"01000100011001" when "100111110",
"01000110000111" when "100111111",
"11111100101110" when "101000000",
"11111110011100" when "101000001",
"11111011101001" when "101000010",
"11111101010111" when "101000011",
"11110111101110" when "101000100",
"11111001011100" when "101000101",
"11110110101001" when "101000110",
"11111000010111" when "101000111",
"00001101110011" when "101001000",
"00001111100001" when "101001001",
"00001100101110" when "101001010",
"00001110011100" when "101001011",
"00001000110011" when "101001100",
"00001010100001" when "101001101",
"00000111101110" when "101001110",
"00001001011100" when "101001111",
"00100011010100" when "101010000",
"00100101000010" when "101010001",
"00100010001111" when "101010010",
"00100011111101" when "101010011",
"00011110010100" when "101010100",
"00100000000010" when "101010101",
"00011101001111" when "101010110",
"00011110111101" when "101010111",
"00110100011001" when "101011000",
"00110110000111" when "101011001",
"00110011010100" when "101011010",
"00110101000010" when "101011011",
"00101111011001" when "101011100",
"00110001000111" when "101011101",
"00101110010100" when "101011110",
"00110000000010" when "101011111",
"00001101110011" when "101100000",
"00001111100001" when "101100001",
"00001100101110" when "101100010",
"00001110011100" when "101100011",
"00001000110011" when "101100100",
"00001010100001" when "101100101",
"00000111101110" when "101100110",
"00001001011100" when "101100111",
"00011110111000" when "101101000",
"00100000100110" when "101101001",
"00011101110011" when "101101010",
"00011111100001" when "101101011",
"00011001111000" when "101101100",
"00011011100110" when "101101101",
"00011000110011" when "101101110",
"00011010100001" when "101101111",
"00110100011001" when "101110000",
"00110110000111" when "101110001",
"00110011010100" when "101110010",
"00110101000010" when "101110011",
"00101111011001" when "101110100",
"00110001000111" when "101110101",
"00101110010100" when "101110110",
"00110000000010" when "101110111",
"01000101011110" when "101111000",
"01000111001100" when "101111001",
"01000100011001" when "101111010",
"01000110000111" when "101111011",
"01000000011110" when "101111100",
"01000010001100" when "101111101",
"00111111011001" when "101111110",
"01000001000111" when "101111111",
"00000000101001" when "110000000",
"00000010010111" when "110000001",
"11111111100100" when "110000010",
"00000001010010" when "110000011",
"11111011101001" when "110000100",
"11111101010111" when "110000101",
"11111010100100" when "110000110",
"11111100010010" when "110000111",
"00010001101110" when "110001000",
"00010011011100" when "110001001",
"00010000101001" when "110001010",
"00010010010111" when "110001011",
"00001100101110" when "110001100",
"00001110011100" when "110001101",
"00001011101001" when "110001110",
"00001101010111" when "110001111",
"00100111001111" when "110010000",
"00101000111101" when "110010001",
"00100110001010" when "110010010",
"00100111111000" when "110010011",
"00100010001111" when "110010100",
"00100011111101" when "110010101",
"00100001001010" when "110010110",
"00100010111000" when "110010111",
"00111000010100" when "110011000",
"00111010000010" when "110011001",
"00110111001111" when "110011010",
"00111000111101" when "110011011",
"00110011010100" when "110011100",
"00110101000010" when "110011101",
"00110010001111" when "110011110",
"00110011111101" when "110011111",
"00010001101110" when "110100000",
"00010011011100" when "110100001",
"00010000101001" when "110100010",
"00010010010111" when "110100011",
"00001100101110" when "110100100",
"00001110011100" when "110100101",
"00001011101001" when "110100110",
"00001101010111" when "110100111",
"00100010110011" when "110101000",
"00100100100001" when "110101001",
"00100001101110" when "110101010",
"00100011011100" when "110101011",
"00011101110011" when "110101100",
"00011111100001" when "110101101",
"00011100101110" when "110101110",
"00011110011100" when "110101111",
"00111000010100" when "110110000",
"00111010000010" when "110110001",
"00110111001111" when "110110010",
"00111000111101" when "110110011",
"00110011010100" when "110110100",
"00110101000010" when "110110101",
"00110010001111" when "110110110",
"00110011111101" when "110110111",
"01001001011001" when "110111000",
"01001011000111" when "110111001",
"01001000010100" when "110111010",
"01001010000010" when "110111011",
"01000100011001" when "110111100",
"01000110000111" when "110111101",
"01000011010100" when "110111110",
"01000101000010" when "110111111",
"11111011101001" when "111000000",
"11111101010111" when "111000001",
"11111010100100" when "111000010",
"11111100010010" when "111000011",
"11110110101001" when "111000100",
"11111000010111" when "111000101",
"11110101100100" when "111000110",
"11110111010010" when "111000111",
"00001100101110" when "111001000",
"00001110011100" when "111001001",
"00001011101001" when "111001010",
"00001101010111" when "111001011",
"00000111101110" when "111001100",
"00001001011100" when "111001101",
"00000110101001" when "111001110",
"00001000010111" when "111001111",
"00100010001111" when "111010000",
"00100011111101" when "111010001",
"00100001001010" when "111010010",
"00100010111000" when "111010011",
"00011101001111" when "111010100",
"00011110111101" when "111010101",
"00011100001010" when "111010110",
"00011101111000" when "111010111",
"00110011010100" when "111011000",
"00110101000010" when "111011001",
"00110010001111" when "111011010",
"00110011111101" when "111011011",
"00101110010100" when "111011100",
"00110000000010" when "111011101",
"00101101001111" when "111011110",
"00101110111101" when "111011111",
"00001100101110" when "111100000",
"00001110011100" when "111100001",
"00001011101001" when "111100010",
"00001101010111" when "111100011",
"00000111101110" when "111100100",
"00001001011100" when "111100101",
"00000110101001" when "111100110",
"00001000010111" when "111100111",
"00011101110011" when "111101000",
"00011111100001" when "111101001",
"00011100101110" when "111101010",
"00011110011100" when "111101011",
"00011000110011" when "111101100",
"00011010100001" when "111101101",
"00010111101110" when "111101110",
"00011001011100" when "111101111",
"00110011010100" when "111110000",
"00110101000010" when "111110001",
"00110010001111" when "111110010",
"00110011111101" when "111110011",
"00101110010100" when "111110100",
"00110000000010" when "111110101",
"00101101001111" when "111110110",
"00101110111101" when "111110111",
"01000100011001" when "111111000",
"01000110000111" when "111111001",
"01000011010100" when "111111010",
"01000101000010" when "111111011",
"00111111011001" when "111111100",
"01000001000111" when "111111101",
"00111110010100" when "111111110",
"01000000000010" when "111111111",
"00000000000000" when others;
end arch;
主要单位:
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use ieee.math_real.all;
entity filtr_fir_da is
port (
clk, rst : in std_logic;
data_in : in std_logic_vector(7 downto 0);
data_out : out std_logic_vector(27 downto 0)
);
end filtr_fir_da;
architecture arch of filtr_fir_da is
signal acc_reg, acc_next : signed(27 downto 0);
signal data_out_reg,data_out_next : signed(27 downto 0);
signal tableout : std_logic_vector(13 downto 0);
signal adress_reg, adress_next : unsigned (3 downto 0);
signal d0_reg,d1_reg,d2_reg,d3_reg,d4_reg,d5_reg,d6_reg,d7_reg,d8_reg : std_logic;
signal d0_next,d1_next,d2_next,d3_next,d4_next,d5_next,d6_next,d7_next,d8_next : std_logic;
type x_table is array (0 to 8) of std_logic_vector(7 downto 0);
signal datat_reg,datat_next : x_table;
type STYPE is (load,count,result);
signal state_reg, state_next : STYPE;
component lut_table
port(
x0,x1,x2,x3,x4,x5,x6,x7,x8 : in std_logic;
table_out : out std_logic_vector(13 downto 0)
);
end component;
begin
lut: lut_table port map(
x0 => d0_reg,x1 => d1_reg,x2 => d2_reg,x3 => d3_reg,x4 => d4_reg,x5 => d5_reg,x6 => d6_reg,x7 => d7_reg,x8 => d8_reg,
table_out => tableout
);
process(rst,clk)
begin
if rst = '1' then
state_reg <= load;
elsif rising_edge(clk) then
state_reg <= state_next;
end if;
end process;
process(rst, clk)
begin
if rst = '1' then
adress_reg <= "0000";
data_out_reg <= (others => '0');
acc_reg <= (others => '0');
datat_reg <= (others => (others => '0'));
d0_reg <= '0'; d1_reg <= '0'; d2_reg <= '0'; d3_reg <= '0'; d4_reg <= '0'; d5_reg <= '0'; d6_reg <= '0'; d7_reg <= '0'; d8_reg <= '0';
elsif rising_edge(clk) then
adress_reg <= adress_next;
acc_reg <= acc_next;
data_out_reg <= data_out_next;
datat_reg <= datat_next;
d0_reg <= d0_next;d1_reg <= d1_next;d2_reg <= d2_next;d3_reg <= d3_next;d4_reg <= d4_next;d5_reg <= d5_next;d6_reg <= d6_next;d7_reg <= d7_next;d8_reg <= d8_next;
end if;
end process;
process(state_reg,adress_reg,data_out_reg,d0_reg,d1_reg,d2_reg,d3_reg,d4_reg,d5_reg,d6_reg,d7_reg,d8_reg,acc_reg,datat_reg,datat_next,tableout,data_in)
begin
state_next <= state_reg;
adress_next <= adress_reg;
acc_next <= acc_reg;
data_out_next <= data_out_reg;
datat_next <= datat_reg;
d0_next <= d0_reg;d1_next <= d1_reg;d2_next <= d2_reg;d3_next <= d3_reg;d4_next <= d4_reg;d5_next <= d5_reg;d6_next <= d6_reg;d7_next <= d7_reg;d8_next <= d8_reg;
case state_reg is
when load =>
datat_next(8) <= datat_reg(7);
datat_next(7) <= datat_reg(6);
datat_next(6) <= datat_reg(5);
datat_next(5) <= datat_reg(4);
datat_next(4) <= datat_reg(3);
datat_next(3) <= datat_reg(2);
datat_next(2) <= datat_reg(1);
datat_next(1) <= datat_reg(0);
datat_next(0) <= data_in;
state_next <= count;
when count =>
if adress_reg < "0111" then
d0_next <= datat_reg(0)(to_integer(adress_reg));
d1_next <= datat_reg(1)(to_integer(adress_reg));
d2_next <= datat_reg(2)(to_integer(adress_reg));
d3_next <= datat_reg(3)(to_integer(adress_reg));
d4_next <= datat_reg(4)(to_integer(adress_reg));
d5_next <= datat_reg(5)(to_integer(adress_reg));
d6_next <= datat_reg(6)(to_integer(adress_reg));
d7_next <= datat_reg(7)(to_integer(adress_reg));
d8_next <= datat_reg(8)(to_integer(adress_reg));
acc_next <= (shift_left(signed(tableout),to_integer(adress_reg))) + acc_reg;
adress_next <= adress_reg + "0001";
state_next <= count;
elsif adress_reg = "0111" then
d0_next <= datat_reg(0)(to_integer(adress_reg));
d1_next <= datat_reg(1)(to_integer(adress_reg));
d2_next <= datat_reg(2)(to_integer(adress_reg));
d3_next <= datat_reg(3)(to_integer(adress_reg));
d4_next <= datat_reg(4)(to_integer(adress_reg));
d5_next <= datat_reg(5)(to_integer(adress_reg));
d6_next <= datat_reg(6)(to_integer(adress_reg));
d7_next <= datat_reg(7)(to_integer(adress_reg));
d8_next <= datat_reg(8)(to_integer(adress_reg));
acc_next <= -(shift_left(signed(tableout),to_integer(adress_reg))) + acc_reg;
adress_next <= "0000";
state_next <= result;
end if;
when result =>
data_out_next <= acc_reg;
state_next <= load;
acc_next <= (others => '0');
when others =>
state_next <= load;
end case;
end process;
data_out <= std_logic_vector(data_out_reg);
end arch;
我的比例系数是
[110,-69,-320,1093,2470,1093,-320,-69,110]
例如,当输入信号为
时[1,0,0,0,0,0,0,0,0]
我的系统将reuslt重复两次,结果是
[220,-138,-640,2186,4940,2186,-640,-138,220]
代替
[110,-69,-320,1093,2470,1093,-320,-69,110]。
有人帮忙吗?