Advertisement
Guest User

Untitled

a guest
Jul 17th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 2.60 KB | None | 0 0
  1. library IEEE;
  2. use IEEE.STD_LOGIC_1164.ALL;
  3. use IEEE.STD_LOGIC_ARITH.ALL;
  4. use IEEE.STD_LOGIC_UNSIGNED.ALL;
  5.  
  6. entity MinMax is
  7.     Port ( clk : in  STD_LOGIC;
  8.            reset : in  STD_LOGIC;
  9.            data : in  STD_LOGIC_VECTOR (7 downto 0);
  10.            enable : in  STD_LOGIC;
  11.            min : out  STD_LOGIC_VECTOR (7 downto 0);
  12.            min_line : out  STD_LOGIC_VECTOR (7 downto 0);
  13.            max : out  STD_LOGIC_VECTOR (7 downto 0);
  14.            max_line : out  STD_LOGIC_VECTOR (7 downto 0));
  15. end MinMax;
  16.  
  17. architecture Behavioral of MinMax is
  18. signal cnt,qmin,qmax : std_logic_vector(7 downto 0);
  19. begin
  20.  
  21.         process (clk,enable)
  22.         begin
  23.                 if rising_edge(clk) then
  24.                         if reset = '1' then
  25.                                 cnt <= (others => '0');
  26.                         elsif enable = '1' then
  27.                                 cnt <= cnt + 1;
  28.                         end if;
  29.                 end if;
  30.         end process;
  31.  
  32. -----------------------------------------------------------------------------------------------
  33.  
  34.         process (clk,reset,enable,data)
  35.         begin
  36.                 if rising_edge(clk) then
  37.                         if reset = '1' then
  38.                                 qmin <= (others => '1');
  39.                         elsif enable = '1' then
  40.                                 if data <= qmin then
  41.                                     qmin <= data;
  42.                                 end if;
  43.                         end if;
  44.                 end if;
  45.         end process;
  46.         min <= qmin;
  47.         process (clk,reset,enable,data)
  48.         begin
  49.                 if rising_edge(clk) then
  50.                         if reset = '1' then
  51.                                 min_line <= (others => '0');
  52.                         elsif enable = '1' then
  53.                                 if data <= qmin then
  54.                                     min_line <= cnt;
  55.                                 end if;
  56.                         end if;
  57.                 end if;
  58.         end process;
  59.        
  60. -----------------------------------------------------------------------------------------------
  61.        
  62.         process (clk,reset,enable,data)
  63.         begin
  64.                 if rising_edge(clk) then
  65.                         if reset = '1' then
  66.                                 qmax <= (others => '0');
  67.                         elsif enable = '1' then
  68.                                 if data >= qmax then
  69.                                     qmax <= data;
  70.                                 end if;
  71.                         end if;
  72.                 end if;
  73.         end process;       
  74.         max <= qmax;
  75.        
  76.         -- proces ma wygenerowac rejestr, ktory zatrzaskuje numer linijki z wartoscia max
  77.         -- proces dziala synchronicznie wzgledem sygnalu zegarowego clk,
  78.         -- wiec jest ustawiany poprzednimi wartosciami (z przed taktu zegara), ktore juz nie sa aktualne)
  79.         -- dlatego wartosc max_line jest o 1 mniejsza niz cnt - co jest rzecza porzadana, poniewaz numeracja lini jest od 0 do n-1 (gdzie n to liczba lini).
  80.         process (clk,reset,enable,data)
  81.         begin
  82.                 if rising_edge(clk) then
  83.                         if reset = '1' then
  84.                                 max_line <= (others => '0');
  85.                         elsif enable = '1' then
  86.                                 if data >= qmax then
  87.                                     max_line <= cnt;
  88.                                 end if;
  89.                         end if;
  90.                 end if;
  91.         end process;
  92.  
  93.  
  94. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement