Advertisement
Gatzky

Untitled

Dec 17th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 1.12 KB | None | 0 0
  1. library ieee;
  2. use IEEE.std_logic_1164.all;
  3. use IEEE.std_logic_unsigned.all;
  4.  
  5. entity SUM_main is
  6. port (CLK : in std_logic;
  7.       A : in std_logic_vector (3 downto 0);
  8.       B : in std_logic;
  9.       SUM : out std_logic_vector (3 downto 0)
  10.   );
  11. end SUM_main;
  12.  
  13. architecture behavioral of SUM_main is
  14.  
  15. component COUNT_main is
  16.     Port ( CLK : in STD_LOGIC;
  17.     C : inout STD_LOGIC_VECTOR (1 downto 0));
  18. end component;
  19.  
  20. signal nexts, current: STD_LOGIC_VECTOR (3 downto 0);
  21. signal Cin: STD_LOGIC;
  22. signal C: STD_LOGIC_VECTOR (1 downto 0);
  23.  
  24. begin
  25.  
  26. mapping: COUNT_main PORT MAP (CLK=>CLK, C=>C);
  27.  
  28. process (CLK)
  29. begin
  30. if (rising_edge(clk)) then
  31.     if B ='0' and Cin='0' then
  32.         Cin <= '0';
  33.         nexts <= current;
  34.     elsif B='1' xor Cin='0' then
  35.         Cin <= '0';
  36.         nexts <= current+1;
  37.     elsif B ='1' and Cin='1' then
  38.         Cin <= '1';
  39.         nexts <= current;      
  40.     end if;  
  41.  current <= nexts;   --state change.
  42. end if;
  43. end process;
  44.  
  45. process (C)
  46. begin
  47.     if C = "00" then
  48.     current <= A;
  49.     elsif C = "11" then
  50.     SUM <= nexts;
  51. end if;
  52. end process;
  53.  
  54. end behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement