Advertisement
Guest User

Untitled

a guest
Jan 21st, 2020
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 3.50 KB | None | 0 0
  1. ----------------------------------------------------------------------------------
  2.  
  3. ----------------------------------------------------------------------------------
  4. library IEEE;
  5. use IEEE.STD_LOGIC_1164.ALL;
  6. use IEEE.STD_LOGIC_UNSIGNED.ALL;
  7.  
  8. -- entity
  9. entity Zmywarka is
  10.     Port ( reset : in  STD_LOGIC;
  11.            clk : in  STD_LOGIC;
  12.            program : in  STD_LOGIC;
  13.            woda_max : in  STD_LOGIC;
  14.            woda_min : in  STD_LOGIC;
  15.            zawor : out  STD_LOGIC;
  16.            grzalka : out  STD_LOGIC;
  17.            pompa : out  STD_LOGIC;
  18.            nablyszczacz : out  STD_LOGIC;
  19.               tabletka : out STD_LOGIC
  20.               );
  21. end Zmywarka;
  22.  
  23.         -- stan, w jakim znajduje się automat
  24.         -- "00" - START/STOP
  25.         -- "01" - WODA
  26.         -- "10" - ZMYWANIE
  27.         -- "11" - WYPOMPOWANIE WODY
  28.  
  29. -- architektura
  30. architecture Zmywarka_arch of Zmywarka is
  31.  
  32. type MOJE_STANY is (START_STOP, WODA, ZMYWANIE, WYPOMPOWANIE); -- deklaracja typu MOJE_STANY o wartościach: (moje stany)
  33.  
  34. signal stan, stan_nastepny : MOJE_STANY;
  35. signal czasomierz : std_logic_vector (3 downto 0); -- wyjscie licznika czasu zmywania
  36. signal postep : std_logic_vector (2 downto 0); -- licznik cykli zmywarki
  37. signal wyjscie : std_logic_vector (1 downto 0); -- wyjscie, informujace o stanie zmywarki
  38.  
  39. begin
  40.  
  41. zmyw: process (stan, program, woda_max, woda_min, czasomierz, postep)
  42.  
  43.     begin
  44.         stan_nastepny <= stan;
  45.        
  46.     case stan is
  47.         when START_STOP =>
  48.             if program = '1' and postep = "000" then
  49.                 stan_nastepny <= WODA;
  50.             end if;
  51.        
  52.         when WODA =>
  53.             if program = '0' then
  54.                 stan_nastepny <= START_STOP;
  55.             elsif woda_max = '1' then
  56.                 if postep = "000" then
  57.                     stan_nastepny <= WYPOMPOWANIE;
  58.                 else
  59.                     stan_nastepny <= ZMYWANIE;
  60.                 end if;
  61.             end if;
  62.            
  63.         when ZMYWANIE =>
  64.             if program = '0' then
  65.                 stan_nastepny <= START_STOP;
  66.             elsif czasomierz = "1111" then
  67.                 stan_nastepny <= WYPOMPOWANIE;
  68.             end if;
  69.            
  70.         when WYPOMPOWANIE =>
  71.             if program = '0' then
  72.                 stan_nastepny <= START_STOP;
  73.             elsif woda_min = '1' then
  74.                 if postep /= "000" then
  75.                     stan_nastepny <= START_STOP;
  76.                 else
  77.                     stan_nastepny <= WODA;
  78.                 end if;
  79.             end if;
  80.            
  81.         when others =>
  82.             stan_nastepny <= START_STOP;
  83.         end case;
  84.        
  85. end process zmyw;
  86.  
  87.     rejestr_stanu_wewnetrznego: process (reset, clk)
  88.         begin
  89.             if reset = '0' then
  90.                 stan <= START_STOP;
  91.             elsif clk'event and clk = '1' then
  92.                 stan <= stan_nastepny;
  93.             end if;
  94.     end process rejestr_stanu_wewnetrznego;
  95.    
  96.     licznik_czasu_zmywania: process (reset, clk)
  97.         begin
  98.             if reset = '0' then
  99.                 czasomierz <= (others => '0');
  100.             elsif clk'event and clk = '1' then
  101.                 if stan = ZMYWANIE then
  102.                     czasomierz <= czasomierz + "01";
  103.                 else
  104.                     czasomierz <= (others => '0');
  105.                 end if;
  106.             end if;
  107.         end process licznik_czasu_zmywania;
  108.        
  109.     licznik_cykli: process (reset, clk)
  110.         begin
  111.             if reset = '0' then
  112.                 postep <= (others => '0');
  113.             elsif clk'event and clk = '1' then
  114.                 if stan = WYPOMPOWANIE and stan_nastepny = WODA then
  115.                     postep <= postep + "01";
  116.                 else
  117.                     postep <= postep;
  118.                 end if;
  119.             end if;
  120.         end process licznik_cykli;
  121.        
  122.     zawor <= '1' when stan = WODA else '0';
  123.     grzalka <= '1' when stan = ZMYWANIE else '0';
  124.     pompa <= '1' when stan = WYPOMPOWANIE else '0';
  125.     nablyszczacz <= '1' when stan = ZMYWANIE else '0';
  126.     tabletka <= '1' when stan = ZMYWANIE else '0';
  127.     wyjscie <=  "00" when stan = START_STOP else
  128.                     "01" when stan = WODA else
  129.                     "10" when stan = ZMYWANIE else
  130.                     "11";
  131.  
  132. end Zmywarka_arch;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement