library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_arith.all; use ieee.std_logic_unsigned.all; entity es_ups is Port ( clk,reset : in std_logic; v_ok : in std_logic; ups_on : out std_logic; screen_on : out std_logic; client_off : out std_logic_vector(1 downto 0); server_off : out std_logic_vector(1 downto 0) ); end es_ups; architecture beh of es_ups is type state is (allright,nopower,noscreen,spegni1,spegni2,spegni3,spegni4); signal cs,ns : state; signal count,ncount : unsigned(4 downto 0); begin process(clk,reset) begin if reset = '1' then cs <= allright; count <= conv_unsigned(0,5); else if clk'event and clk='1' then cs <= ns; count <= ncount; end if; end if; end process; process(cs,v_ok,count) begin case cs is when allright => -- Automa di Moore, scelta delle uscite ups_on <= '0'; screen_on <= '0'; client_off <= "11"; server_off <= "11"; -- Calcolo stato futuro if v_ok='0' then ns <= nopower; else ns <= allright; end if; when nopower => -- Selezione delle uscite ups_on <= '1'; screen_on <= '1'; client_off <= "11"; server_off <= "11"; -- Calcolo stato futuro if v_ok='1' then ns <= allright; elsif (count>=conv_unsigned(10,5) ) then ns <= noscreen; else ns <= nopower; end if; when noscreen => -- Selezione delle uscite ups_on <= '1'; screen_on <= '0'; client_off <= "11"; server_off <= "11"; -- Calcolo stato futuro if v_ok='1' then ns <= allright; elsif (count>=conv_unsigned(20,5) ) then ns <= spegni1; else ns <= noscreen; end if; when spegni1 => -- Selezione delle uscite ups_on <= '1'; screen_on <= '0'; client_off <= "10"; server_off <= "11"; ns <= spegni2; when spegni2 => -- Selezione delle uscite ups_on <= '1'; screen_on <= '0'; client_off <= "00"; server_off <= "11"; ns <= spegni3; when spegni3 => -- Selezione delle uscite ups_on <= '1'; screen_on <= '0'; client_off <= "00"; server_off <= "10"; ns <= spegni4; when spegni4 => -- Selezione delle uscite ups_on <= '1'; screen_on <= '0'; client_off <= "00"; server_off <= "00"; ns <= spegni4; when others => ups_on <= '0'; screen_on <= '0'; client_off <= "11"; server_off <= "11"; ns <= allright; end case; end process; -- contatore a 20. Per come e' definita la macchina a stati non appena a 20 -- cs diventa /= noscreen e il contatore viene resettato process(cs,count) begin if (cs=nopower or cs=noscreen) then ncount <= count+conv_unsigned(1,5); else ncount <= conv_unsigned(0,5); end if; end process; end beh;