Advertisement
gollub

PSDS zadatak 2.1 (brojac)

Nov 7th, 2018
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 4.22 KB | None | 0 0
  1. library IEEE;
  2. use IEEE.STD_LOGIC_1164.ALL;
  3.  
  4. entity i_kolo is
  5.     Port ( x1 : in STD_LOGIC;
  6.            x2 : in STD_LOGIC;
  7.            y : out STD_LOGIC);
  8. end i_kolo;
  9.  
  10. architecture Behavioral of i_kolo is
  11.  
  12. begin
  13.     process(x1, x2) is
  14.     begin
  15.    
  16.         y <= x1 and x2;
  17.        
  18.     end process;
  19. end Behavioral;
  20.  
  21.  
  22. -------------------------------------------------------------------------------------------------------------------------------------
  23.  
  24.  
  25. library IEEE;
  26. use IEEE.STD_LOGIC_1164.ALL;
  27. use IEEE.std_logic_unsigned.all;
  28. use ieee.std_logic_arith.all;
  29.  
  30. entity dec_counter is
  31.     Port ( en : in STD_LOGIC;
  32.            reset : in STD_LOGIC;
  33.            clk : in STD_LOGIC;
  34.            q : out STD_LOGIC_VECTOR (3 downto 0);
  35.            pulse : out STD_LOGIC);
  36. end dec_counter;
  37.  
  38. architecture Behavioral of dec_counter is
  39.     signal count_s: std_logic_vector(3 downto 0) := (others => '0');
  40. begin
  41.     cnt: process (clk) is
  42.     begin
  43.         if(clk'event and clk = '1') then
  44.             if(reset = '1') then
  45.                 count_s <= (others => '0');
  46.             else
  47.                 if(en = '1') then    
  48.                     if(count_s < conv_std_logic_vector(9, 4)) then
  49.                         count_s <= count_s + 1;
  50.                     else
  51.                         count_s <= (others => '0');
  52.                     end if;    
  53.                 end if;
  54.              end if;
  55.         end if;
  56.     end process;
  57.    
  58.     q <= count_s;
  59.     pulse <= '1' when  count_s =  "1001" and en = '1' else
  60.     '0';
  61.    
  62. end Behavioral;
  63.  
  64.  
  65. ---------------------------------------------------------------------------------------------------------------------------------------
  66.  
  67.  
  68. library IEEE;
  69. use IEEE.STD_LOGIC_1164.ALL;
  70. use IEEE.std_logic_unsigned.all;
  71. use ieee.std_logic_arith.all;
  72. use ieee.numeric_std.all;
  73.  
  74. entity top_level is
  75.     Port ( en : in STD_LOGIC;
  76.            reset : in STD_LOGIC;
  77.            clk : in STD_LOGIC;
  78.            q0 : out STD_LOGIC_VECTOR(3 downto 0);
  79.            q1 : out STD_LOGIC_VECTOR(3 downto 0);
  80.            q2 : out STD_LOGIC_VECTOR(3 downto 0));
  81. end top_level;
  82.  
  83. architecture Behavioral of top_level is
  84.     signal pom1, pom2: std_logic;
  85.     signal jed, des, stot: std_logic_vector(3 downto 0);
  86.     signal izlaz_i_kola: std_logic;
  87. begin
  88.     jedinice: entity work.dec_counter(Behavioral)
  89.               port map(
  90.                     clk => clk,
  91.                     reset => reset,
  92.                     en => en,
  93.                     pulse => pom1,
  94.                     q => jed);
  95.            
  96.     desetice: entity work.dec_counter(Behavioral)
  97.               port map(
  98.                     clk => clk,
  99.                     reset => reset,
  100.                     en => pom1,
  101.                     pulse => pom2,
  102.                     q => des);
  103.                        
  104.     i_kolo: entity work.i_kolo(Behavioral)
  105.              port map(
  106.                     x1 => pom1,
  107.                     x2 => pom2,
  108.                     y => izlaz_i_kola);
  109.                        
  110.     stotine: entity work.dec_counter(Behavioral)
  111.              port map(
  112.                     clk => clk,
  113.                     reset => reset,
  114.                     en => izlaz_i_kola,
  115.                     pulse => open,
  116.                     q => stot);
  117.      
  118.         q0 <= jed;
  119.         q1 <= des;
  120.         q2 <= stot;          
  121.  
  122. end Behavioral;
  123.  
  124.  
  125. ---------------------------------------------------------------------------------------------------------------------------------------
  126.  
  127.  
  128. library IEEE;
  129. use IEEE.STD_LOGIC_1164.ALL;
  130. use IEEE.std_logic_unsigned.all;
  131. use ieee.std_logic_arith.all;
  132.  
  133. entity test_benc is
  134. --  Port ( );
  135. end test_benc;
  136.  
  137. architecture Behavioral of test_benc is
  138.     signal en_s, clk_s, reset_s:std_logic;
  139.     signal  q_s0, q_s1, q_s2: std_logic_vector(3 downto 0);
  140. begin
  141.     brojac: entity work.top_level (Behavioral)
  142.         port map(
  143.             en => en_s,
  144.             clk => clk_s,
  145.             reset => reset_s,
  146.             q0 => q_s0,
  147.             q1 => q_s1,
  148.             q2 => q_s2);
  149.    
  150.     signali: process
  151.     begin
  152.         en_s <= '1';
  153.         reset_s <= '0';
  154.         clk_s <= '0', '1' after 100 ns ;
  155.             wait for 200 ns;
  156.     end process;                  
  157.  
  158. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement