Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
315
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 1.67 KB | None | 0 0
  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3. use ieee.std_logic_unsigned.all;
  4.  
  5. entity z1 is
  6. port(
  7.     iCLK : in std_logic;
  8.     inRST : in std_logic;
  9.     iLOAD : in std_logic;
  10.     iD : in std_logic_vector(7 downto 0);
  11.     oONES : out std_logic_vector(7 downto 0);
  12.     oEVEN : out std_logic_vector(2 downto 0);
  13.     oODD : out std_logic_vector(2 downto 0)
  14.     );
  15. end entity;
  16.  
  17. architecture bod of z1 is
  18.     signal sREG : std_logic_vector(7 downto 0);
  19.     signal sCOPY : std_logic_vector(7 downto 0);
  20.     signal sBRJ : std_logic_vector(7 downto 0);
  21.     signal sPAR : std_logic_vector(2 downto 0);
  22.     signal sNEPAR : std_logic_vector(2 downto 0);
  23.     signal sSTOP : std_logic;
  24.  
  25. begin
  26.  
  27.     process(iCLK, inRST) begin ---------------------- pravi reg i broji jedinice
  28.         if(inRST = '0') then
  29.             sREG <= (others => '0');
  30.             sBRJ <= (others => '0');
  31.         elsif(rising_edge(iCLK)) then
  32.             if(iLOAD = '1') then
  33.                 sREG <= sREG(6 downto 0) & sCOPY(7);
  34.                 sCOPY <= sCOPY(6 downto 0) & '0';
  35.             else
  36.                 sCOPY <= iD;
  37.                 if(sREG(0) = '1') then
  38.                     sBRJ <= sBRJ + 1;
  39.                 end if;
  40.                 sREG <= '0' & sREG(7 downto 1);
  41.             end if;
  42.         end if;
  43.     end process;
  44.    
  45.     process(icLK, inRST) begin ---------------------- broji par i nepar
  46.         if(inRST = '0') then
  47.             sPAR <= (others => '0');
  48.             sNEPAR <= (others => '0');
  49.             sSTOP <= '0';
  50.         elsif(rising_edge(iCLK)) then
  51.             if(iLOAD = '1') then
  52.                 if(sSTOP = '0') then
  53.                     if(iD(0) = '0') then
  54.                         sPAR <= sPAR + 1;
  55.                         sSTOP <= '1';
  56.                     else
  57.                         sNEPAR <= sNEPAR + 1;
  58.                         sSTOP <= '1';
  59.                     end if;
  60.                 end if;
  61.             else
  62.                 sSTOP <= '0';
  63.             end if;
  64.         end if;
  65.     end process;
  66.                
  67.        
  68.    
  69.     oONES <= sBRJ;
  70.     oEVEN <= sPAR;
  71.     oODD <= sNEPAR;
  72.    
  73. end architecture;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement