Advertisement
Guest User

Untitled

a guest
Aug 1st, 2014
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 3.39 KB | None | 0 0
  1. ----------------------------------------------------------------------------------
  2. -- Company: Cal Poly SLO
  3. -- Engineer: Louie Thiros
  4. --
  5. -- Create Date:    19:32:33 08/01/2014
  6. -- Design Name:
  7. -- Module Name:    Exp12 - Behavioral
  8. -- Project Name:
  9. -- Target Devices: Nexys3
  10. -- Tool versions:
  11. -- Description: A module that will dislpay the signed sum or difference of two
  12. -- signed numbers as long as the result is valid.
  13. --
  14. -- Dependencies:
  15. --
  16. -- Revision:
  17. -- Revision 0.01 - File Created
  18. -- Additional Comments:
  19. --
  20. ----------------------------------------------------------------------------------
  21. library IEEE;
  22. use IEEE.STD_LOGIC_1164.ALL;
  23.  
  24. -- Uncomment the following library declaration if using
  25. -- arithmetic functions with Signed or Unsigned values
  26. --use IEEE.NUMERIC_STD.ALL;
  27.  
  28. -- Uncomment the following library declaration if instantiating
  29. -- any Xilinx primitives in this code.
  30. --library UNISIM;
  31. --use UNISIM.VComponents.all;
  32.  
  33. entity Exp12 is
  34.     Port ( A : in  STD_LOGIC_VECTOR (3 downto 0);
  35.            B : in  STD_LOGIC_VECTOR (3 downto 0);
  36.            ADD : in  STD_LOGIC;
  37.            digit : out  STD_LOGIC_VECTOR (7 downto 0);
  38.            anode : out  STD_LOGIC_VECTOR (3 downto 0);
  39.            clk : in std_logic);
  40. end Exp12;
  41.  
  42. architecture Behavioral of Exp12 is
  43.  
  44.     component RippleCarryAdder is
  45.         Port ( A : in  STD_LOGIC_VECTOR (3 downto 0);
  46.            B : in  STD_LOGIC_VECTOR (3 downto 0);
  47.            SUM : out  STD_LOGIC_VECTOR (3 downto 0);
  48.            Cout : out  STD_LOGIC);
  49.     end component;
  50.    
  51.     component signed_unsigned_dec is
  52.         Port ( signed_4 : in  STD_LOGIC_VECTOR (3 downto 0);
  53.            unsigned_4 : out  STD_LOGIC_VECTOR (3 downto 0));
  54.     end component;
  55.    
  56.     component sseg_dec is
  57.         Port (      ALU_VAL : in std_logic_vector(7 downto 0);
  58.                         SIGN : in std_logic;
  59.                         VALID : in std_logic;
  60.                     CLK : in std_logic;
  61.                 DISP_EN : out std_logic_vector(3 downto 0);
  62.                SEGMENTS : out std_logic_vector(7 downto 0));
  63.     end component;
  64.    
  65.     component signed_inverter is
  66.         Port( SIGNED_IN : in std_logic_vector(3 downto 0);
  67.             SIGNED_OUT : out std_logic_vector (3 downto 0));
  68.     end component;
  69.    
  70.     component signed_addition_validator is
  71.         Port ( A : in  STD_LOGIC;
  72.            B : in  STD_LOGIC;
  73.            SUM : in  STD_LOGIC;
  74.            VALID : out  STD_LOGIC);
  75.     end component;
  76.    
  77.     signal SELECTED_B, INVERTED_B, SUM, ABS_OF_SUM : std_logic_vector (3 downto 0);
  78.     signal VALID : std_logic;
  79.  
  80. begin
  81.  
  82.     si0 : signed_inverter port map( SIGNED_IN => B,
  83.         SIGNED_OUT => INVERTED_B);
  84.    
  85.     -- Mult the input by -1 when add isn't selected
  86.     with ADD select
  87.         SELECTED_B <= B when '1',
  88.         INVERTED_B when others;
  89.        
  90.     rca0 : RippleCarryAdder port map( A => A,
  91.         B => SELECTED_B,
  92.         SUM => SUM);
  93.    
  94.     -- finds abs value of the added numbers for display
  95.     sud0 : signed_unsigned_dec port map(signed_4 => SUM,
  96.         unsigned_4 => ABS_OF_SUM);
  97.    
  98.     sav0 : signed_addition_validator port map(A => A(3),
  99.         B => B(3),
  100.         SUM => SUM(3),
  101.         VALID => VALID);
  102.    
  103.     sd0 : sseg_dec port map(ALU_VAL => "0000" & ABS_OF_SUM,
  104.         SIGN => SUM(3),
  105.         VALID => '1',
  106.         CLK => clk,
  107.         DISP_EN => anode,
  108.         SEGMENTS => digit);
  109. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement