Advertisement
Simone_Monaco

Untitled

May 18th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 2.75 KB | None | 0 0
  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3. use ieee.numeric_std.all;
  4.  
  5. entity eq_calculator is
  6.     port (data_in : in signed (7 downto 0);
  7.             clk, addfilter_sub_h, regfilter_rst_h, mux2to1_sign_h, mux2to1_maxmin, mux2to1_v_h : in std_logic;
  8.             mux4to1_sel : in std_logic_vector (1 downto 0);
  9.             add_v_h, msb_sum : out std_logic;
  10.             data_out : out signed (7 downto 0));
  11.     end eq_calculator;
  12.    
  13. architecture behavior of eq_calculator is
  14.  
  15. component F_adder is
  16.     generic (N: integer :=10);
  17.     port (x, y : in signed (N-1 downto 0);
  18.             sub   : in std_logic;
  19.             S    : out signed (N-1 downto 0));
  20. end component;
  21.  
  22. component generic_mux2to1 IS
  23.     GENERIC ( N : POSITIVE := 8) ;
  24.     PORT ( w0, w1  : IN STD_LOGIC_VECTOR( ( N - 1 ) DOWNTO 0 ) ;
  25.                   s         :   IN STD_LOGIC ;
  26.                   f        :     OUT STD_LOGIC_VECTOR( ( N - 1 ) DOWNTO 0 ) ) ;
  27. END component;
  28.  
  29. component mux4to1 IS
  30.     GENERIC ( N : POSITIVE := 10) ;
  31.     PORT ( w0, w1, w2, w3  :      IN STD_LOGIC_VECTOR( ( N - 1 ) DOWNTO 0 ) ;
  32.                   s           :       IN STD_LOGIC_VECTOR (1  DOWNTO 0) ;
  33.                   f           :     OUT STD_LOGIC_VECTOR( ( N - 1 ) DOWNTO 0 ) ) ;
  34. END component;
  35.  
  36. COMPONENT regist IS
  37.  GENERIC ( N : integer:=10);
  38.  PORT (R                : IN SIGNED(N-1 DOWNTO 0);
  39.          Clock, Resetn, Enable : IN STD_LOGIC;
  40.          Q              : OUT SIGNED(N-1 DOWNTO 0));
  41. END COMPONENT;
  42.  
  43. signal mux_n_1, mux_n, mux_n_3, sum, reg_sum : signed (9 downto 0);
  44. signal A, B : std_logic_vector (9 downto 0);
  45. signal maxmin,d_out : std_logic_vector (7 downto 0);
  46.  
  47. begin
  48.  
  49.     mux_n_1 <= data_in(7) & data_in(7) & data_in; -- data in 10 bit
  50.     mux_n   <= data_in(7) & data_in(7) & data_in(7) & data_in(7) & data_in(7 downto 2); -- data in 10 bit divided by 4
  51.     mux_n_3 <= data_in(7)& data_in & '0'; -- data in 10 bit multiplied by 2
  52.    
  53.     muxB_select: mux4to1 port map (w0 => std_logic_vector(mux_n_1), w1 => std_logic_vector(mux_n), w2 => std_logic_vector(mux_n_3), w3 => std_logic_vector(reg_sum), s => mux4to1_sel, f => B);
  54.     muxA_select: generic_mux2to1 generic map (N => 10)
  55.                                  port map (w0 => std_logic_vector(reg_sum), w1 => (others => '0'), s => mux2to1_sign_h, f => A);
  56.                                  
  57.     adder        : F_adder port map (x => signed(A), y => signed(B), sub => addfilter_sub_h, S => sum);
  58.     sum_regist: regist port map (R => sum, Clock => clk, Resetn => regfilter_rst_h, Enable => '1', Q => reg_sum);
  59.    
  60.     add_v_h <= (reg_sum(9) xor reg_sum(8)) or (reg_sum(9) xor reg_sum(7)) or (reg_sum(8) xor reg_sum(7));
  61.    
  62.     msb_sum <= reg_sum(9);
  63.    
  64.     maxmin_mux: generic_mux2to1 port map (w0 => "01111111", w1 => "10000000", s => mux2to1_maxmin, f => maxmin);
  65.     res_mux  :  generic_mux2to1 port map (w0 => std_logic_vector(reg_sum(7 downto 0)), w1 => maxmin, s => mux2to1_v_h, f => d_out);
  66.     data_out <= signed( d_out ) ;
  67. end behavior;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement