Advertisement
Mihailo21

A

Dec 2nd, 2023
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 1.90 KB | None | 0 0
  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3. use ieee.std_logic_unsigned.all;
  4.  
  5. entity zadatakA is
  6.     Port ( iCLK    : in  std_logic;
  7.            iRST    : in  std_logic;
  8.            iEN     : in  std_logic;
  9.               iDEC   : in std_logic_vector(2 downto 0);
  10.               oGREAT     : out std_logic;
  11.               oCNTP   : out std_logic_vector(3 downto 0);
  12.               oCNTN   : out std_logic_vector(3 downto 0)
  13.              );
  14. end entity;
  15.  
  16. architecture Behavioral of zadatakA is
  17.  
  18.     signal sDEC : std_logic_vector(7 downto 0);
  19.     signal sREG : std_logic_vector(7 downto 0);
  20.     signal sSHIFT : std_logic_vector(7 downto 0);
  21.     signal sENP : std_logic;
  22.     signal sENN : std_logic;
  23.     signal sCNTP : std_logic_vector(3 downto 0);
  24.     signal sCNTN : std_logic_vector(3 downto 0);
  25.  
  26. begin
  27.    
  28.     --dekoder
  29.     sDEC <= "00000001" when iDEC = 0 else
  30.               "00000010" when iDEC = 1 else
  31.               "00000100" when iDEC = 2 else
  32.               "00001000" when iDEC = 3 else
  33.               "00010000" when iDEC = 4 else
  34.               "00100000" when iDEC = 5 else
  35.               "01000000" when iDEC = 6 else
  36.               "10000000";
  37.              
  38.     --registar
  39.     process(iCLK, iRST)begin
  40.         if(iRST = '1')then
  41.             sREG <= "00000000";
  42.         elsif(rising_edge(iCLK))then
  43.             if(iEN = '1')then
  44.                 sREG <= sDEC;
  45.             end if;
  46.         end if;
  47.     end process;
  48.    
  49.     --pomerac
  50.     sSHIFT <= sREG(7) & sREG(7) & sREG(7 downto 2);
  51.    
  52.     --komparator
  53.     oGREAT <= '1' when sSHIFT > 3 else '0';
  54.    
  55.     --parnost
  56.     sENP <= '1' when sREG(0) = '0' else '0';
  57.     sENN <= not(sENP);
  58.    
  59.     --brojac parnih
  60.     process(iCLK, iRST)begin
  61.         if(iRST = '1')then
  62.             sCNTP <= (others => '0');
  63.         elsif(rising_edge(iCLK))then
  64.             if(sENP = '1')then
  65.                 sCNTP <= sCNTP + 1;
  66.             end if;
  67.         end if;
  68.     end process;
  69.    
  70.     --brojac neparnih
  71.     process(iCLK, iRST)begin
  72.         if(iRST = '1')then
  73.             sCNTN <= (others => '0');
  74.         elsif(rising_edge(iCLK))then
  75.             if(sENN = '1')then
  76.                 sCNTN <= sCNTN + 1;
  77.             end if;
  78.         end if;
  79.     end process;
  80.    
  81.     oCNTP <= sCNTP;
  82.     oCNTN <= sCNTN;
  83.  
  84. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement