Você está na página 1de 9

Código lavador

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_unsigned.ALL;
use IEEE.numeric_std.ALL;

entity lavadora_1 is
Port ( reset,clk : in STD_LOGIC;
C,L,d_l : in STD_LOGIC;
estados_bits : out STD_LOGIC_vector(4 downto 0));
end lavadora_1;

architecture Behavioral of lavadora_1 is

type estados is(inicio, llenado, lavado1,lavado2,enjuague1,enjuague2,centrifugado,puerta);


signal ep:estados;
signal clk_1Hz_s: STD_LOGIC;
signal t: integer range 0 to 15;
begin

process(clk,reset)
variable T: integer range 0 to 50;
begin
if reset='1' then
clk_1Hz_s<='1';
elsif (rising_edge(clk)) then
T:=T+1;
if(T<=1) then
clk_1Hz_s<='1';
elsif (T<50) then
clk_1Hz_s<='0';
else
T:=0;
end if;
end if;
end process;

process(clk_1Hz_s,reset)
begin
if reset='1' then
ep<= inicio;
elsif(rising_edge(clk_1Hz_s) and C='1') then
case ep is
when inicio=>
ep<=llenado;
when llenado=>
t<=t+1;
if t=5 then
ep<=lavado1;
t<=0;
else
ep<=llenado;
end if;
when lavado1=>
t<=t+1;
if (t=15) then
ep<=enjuague1;
t<=0;
else
ep<=lavado1;
end if;
when enjuague1=>
t<=t+1;
if (t=15 and d_l='1') then
ep<=lavado2;
t<=0;
elsif (t=15 and d_l='0') then
ep<=centrifugado;
t<=0;
else
ep<=enjuague1;
end if;
when lavado2 =>
t<=t+1;
if t=10 then
ep <= enjuague2;
t<=0;
else
ep<=lavado2;
end if;
when enjuague2=>
t<=t+1;
if t=10 then
ep<=centrifugado;
t<=0;
else
ep<=enjuague2;
end if;
when centrifugado =>
if L='0' and t<3 then
t<=t+1; ep<= centrifugado;
elsif t=3 and L='0' then
ep<= inicio;
t<=0;
elsif L='1' then
ep<= puerta;
end if;
when puerta=>
if L='1' then
ep<=puerta;
else
ep<=centrifugado;
end if;
when others =>
ep <=inicio;
end case;
end if;
end process;

process(ep)
begin
case ep is
when inicio =>
estados_bits <= "00001";
when llenado =>
estados_bits <= "00010";
when lavado1 =>
estados_bits <= "00100";
when enjuague1 =>
estados_bits <= "01000";
when lavado2 =>
estados_bits <= "01100";
when enjuague2 =>
estados_bits <= "01110";
when centrifugado =>
estados_bits <= "10000";
when others =>
estados_bits <= "11111";
end case;
end process;
end Behavioral;

CASOS:
1: C= ‘1’, doble lavado= ‘0’, puerta = ‘0’.
Caso 2: doble lavado= ‘1’
Caso 3: Puerta abierta

Você também pode gostar