Advertisement
quczmil

Untitled

Nov 26th, 2014
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 2.92 KB | None | 0 0
  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3.  
  4. entity lab21 is
  5. port(
  6.     sclr, clr, clk : in std_logic; --zerowanie synchroniczne, asynchroniczne i zegar
  7.     a, b : in std_logic;
  8.     Y : out std_logic;
  9.     W, ST : out std_logic_vector(2 downto 0)
  10. );
  11. end entity;
  12.  
  13. architecture lab of lab21 is
  14.     --signal st_r, st_n, : std_logic_vector(2 downto 0);
  15.     --zakodowanie stanow automatu
  16.     --constant s1 : std_logic_vector(2 downto 0) := "000";
  17.     --constant s2 : std_logic_vector(2 downto 0) := "001";
  18.     --constant s3 : std_logic_vector(2 downto 0) := "010";
  19.     --constant s4 : std_logic_vector(2 downto 0) := "011";
  20.     --constant s5 : std_logic_vector(2 downto 0) := "100";
  21.     --constant s6 : std_logic_vector(2 downto 0) := "101";
  22.     --constant s7 : std_logic_vector(2 downto 0) := "110";
  23.     --kod stanu don`t care
  24.     --constant sn : std_logic_vector(2 downto 0) := "---";
  25.     --signal xwe : std_logic_vector(1 downto 0);
  26.     --typy wyliczeniowe
  27.     type st_t is (s1, s2, s3, s4, s5, s6, s7);
  28.     signal st_r, st_n, STx : st_t;
  29.     constant sn : st_t := s1;
  30.     attribute syn_encoding : string;
  31.     attribute syn_encoding of st_t : type is "000 001 010 011 100 101 110";
  32.     signal xwe : std_logic_vector(1 downto 0);
  33.     signal Wx : std_logic_vector(2 downto 0);
  34.  
  35. begin  
  36.     --aktualny stan automatu
  37.     p1i:
  38.         process(clr, clk)
  39.         begin
  40.             if(clr = '0') then
  41.                 st_r <= s1;
  42.             elsif(rising_edge(clk)) then
  43.                 st_r <= st_n;
  44.             end if;
  45.         end process p1i;
  46.        
  47.     --segment opisujacy tablice przejsc i wyjsc
  48.     xwe <= a&b;
  49.     p2i:
  50.         process(st_r, xwe)
  51.         begin
  52.             case st_r is
  53.                 when s1 =>
  54.                     Y <= '0';
  55.                     STx <= s1;
  56.                     case xwe is
  57.                         when "10" => st_n <= s2;  Wx <= "000";
  58.                         when "11" => st_n <= s5; Wx <= "000";
  59.                         when others => st_n <= sn; Wx <= "000";
  60.                     end case;
  61.                 when s2 =>
  62.                     Y <= '0';
  63.                     STx <= s2;
  64.                     case xwe is
  65.                         when ("00" or "10") => st_n <= s3; Wx <= "000";
  66.                         when others => st_n <= s5; Wx <= "000";
  67.                     end case;
  68.                 when s3 =>
  69.                     Y <= '0';
  70.                     STx <= s3;
  71.                     case xwe is
  72.                         when ("00" or "10") => st_n <= s3; Wx <= "000";
  73.                         when others => st_n <= s4; Wx <= "100";
  74.                     end case;
  75.                 when s4 =>
  76.                     Y <= '1';
  77.                     STx <= s4;
  78.                     case xwe is
  79.                         when ("00" or "01") => st_n <= s1; Wx <= "000";
  80.                         when "10" => st_n <= s2; Wx <= "000";
  81.                         when others => st_n <= sn; Wx <= "000";
  82.                     end case;
  83.                 when s5 =>
  84.                     Y <= '0';
  85.                     STx <= s5;
  86.                     case xwe is
  87.                         when ("01" or "11") => st_n <= s6; Wx <= "000";
  88.                         when others => st_n <= s7; Wx <= "000";
  89.                     end case;
  90.                 when s6 =>
  91.                     Y <= '0';
  92.                     STx <= s6;
  93.                     case xwe is
  94.                         when ("00" or "10") => st_n <= s4; Wx <= "010";
  95.                         when others => st_n <= s6; Wx <= "000";
  96.                     end case;
  97.                 when s7 =>
  98.                     Y <= '0';
  99.                     STx <= s7;
  100.                     case xwe is
  101.                         when ("01" or "11") => st_n <= s5; Wx <= "000";
  102.                         when others => st_n <= s4; Wx <= "001";
  103.                     end case;
  104.             end case;
  105.             W <= Wx;
  106.             ST <= STx;
  107.         end process;
  108. end lab;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement