Advertisement
Guest User

Untitled

a guest
Nov 7th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 3.11 KB | None | 0 0
  1. library IEEE;
  2. use IEEE.STD_LOGIC_1164.ALL;
  3. USE ieee.std_logic_arith.all;
  4.  
  5. entity lab92 is
  6. Port ( clk  : in STD_LOGIC;
  7.     srst : in STD_LOGIC;
  8.     x1   : in STD_LOGIC_VECTOR (2 downto 0);
  9.     x2   : in STD_LOGIC_VECTOR (2 downto 0);
  10.     btn  : in STD_LOGIC;
  11.     y    : out STD_LOGIC_VECTOR (7 downto 0));
  12. end lab92;
  13.  
  14. architecture Behavioral of lab92 is
  15. TYPE STATE_TYPE IS (s0,s1,s2,s3);--Declare current and next state signals
  16. SIGNAL current_state : STATE_TYPE;
  17. SIGNAL next_state : STATE_TYPE;--Declare any pre-registered internal signals
  18. SIGNAL y_cld : std_logic_vector(7 downto 0);
  19. signal sum   : std_logic_vector (7 downto 0) := (others => '0');
  20. signal mult  : std_logic_vector (7 downto 0) := (others => '0');
  21. signal x11 : std_logic_vector (4 downto 0) := (others => '0');
  22. signal gcntr : std_logic_vector (7 downto 0);
  23. signal cntr : std_logic_vector (25 downto 0) := (others => '0');
  24. signal cntr25d : std_logic;
  25. signal en : std_logic;
  26. signal d_y : std_logic_vector (7 downto 0);
  27. component lab72 is
  28. Port ( clk : in STD_LOGIC;
  29.     dout : out STD_LOGIC_VECTOR(7 downto 0));
  30. end component lab72;
  31. component gc is
  32. Port (  clk : in STD_LOGIC;
  33.     dout : out STD_LOGIC_VECTOR (7 downto 0));
  34. end component gc;
  35. begin
  36. process(clk) begin
  37.     if rising_edge(clk) then
  38.         cntr <= unsigned(cntr) +1;
  39.     end if;
  40. end process;
  41. process(clk) begin
  42.     if rising_edge(clk) then
  43.         cntr25d <= cntr(25);
  44.     end if;
  45. end process;
  46. en <= cntr(25) and (not cntr25d);
  47. clocked_proc : process(clk) begin
  48.     if rising_edge(clk) then
  49.         if srst = '1' then
  50.             current_state <= s0;
  51.         else
  52.             current_state <= next_state;
  53.         end if;
  54.     end if;
  55. end process;
  56. nextstate_proc : process(btn, current_state) begin
  57.     case current_state is
  58.         when s0 =>
  59.             if btn = '1' and en = '1' then
  60.                 next_state <= s1;
  61.             end if;
  62.         when s1 =>
  63.             if btn = '1' and en = '1' then
  64.                 next_state <= s2;
  65.             end if;
  66.         when s2 =>
  67.             if btn = '1' and en = '1' then
  68.                 next_state <= s3;
  69.             end if;
  70.         when s3 =>
  71.             if btn = '1' and en = '1' then
  72.                 next_state <= s0;
  73.             end if;
  74.         when others =>
  75.             next_state <= s0;
  76.     end case;    
  77. end process;
  78. waiting : lab72
  79.     port map( clk => clk,
  80.         dout => y_cld);
  81. gccntr : gc
  82.     port map( clk => clk,
  83.         dout => gcntr);
  84. output_proc : process(current_state) begin
  85.     if current_state = s1 then
  86.         x11(2 downto 0) <= x1;
  87.         sum <= sxt(unsigned(x11) + unsigned(x2),8);
  88.     elsif current_state = s2 then
  89.         x11(2 downto 0) <= x1;
  90.         mult <= sxt(unsigned(x11) * unsigned(x2),8);
  91.     end if;
  92. end process;
  93. out_proc : process(clk) begin
  94.     if rising_edge(clk) then
  95.         if current_state = s0 then
  96.             d_y <= y_cld;
  97.         elsif current_state = s1 then
  98.             d_y <= sum;
  99.         elsif current_state = s2 then
  100.             d_y <= mult;
  101.         else
  102.             d_y <= gcntr;
  103.         end if;
  104.     end if;
  105. end process;
  106. y <= d_y;
  107. end architecture;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement