-------------------------------------------------------------------- -- ELETTRONICA DEI SISTEMI DIGITALI -- -- bibite.vhd -------------------------------------------------------------------- library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity bibite is port ( clk,reset : in std_logic; e010,e020,e050,e1,e2,xx : in Std_logic; -- inserimento monete acqua,bibita : in Std_logic; -- selzione prodotto rifiuta : out Std_logic; -- rifiuto moneta non valida esce_acqua,esce_bibita : out Std_logic; -- consegna prodotto resto : out Unsigned(0 to 4) -- consegna resto ); end bibite; architecture bibite_p of bibite is type stato is (start,rifiuta,restituisci,outacqua,outbibita); signal cs,ns : stato; signal tot,ntot : unsigned(0 to 4); signal count,ncount : unsigned(0 to 4); signal time_over : std_logic; begin -- Parte sequenziale: memorizza il timer,il totale, e lo stato process(clk,reset,time_over) begin if reset = '1' or time_over='1' then tot <= conv_unsigned(0,5); cs <= start; count <= conv_unsigned(0,5); elsif clk'event and clk='1' then tot <= ntot; cs <= ns; count <= ncount; end if; end process; MACCHINASTATI:process(xx,e020,e050,e1,e2,acqua,bibita) begin if xx='1' then rifiuta <= '1'; ns <= start; ntot <= tot; elsif acqua='1' then rifiuta <= '1'; if tot >= conv_unsigned(4,5) then ns <= outacqua; ntot <= tot; else ns <= cs; ntot <= tot; end if; elsif bibita='1' then rifiuta <= '1'; if tot >= conv_unsigned(8,5) then ns <= outbibita; ntot <= tot; else ns <= cs; ntot <= tot; end if; else case(cs) is when start => -- Uscite dipendenti dal solo stato (Moore) esce_acqua <= '0'; esce_bibita <= '0'; resto <= conv_unsigned(0,5); -- Cambiamento di stato e uscite dipendenti dagli ingressi (Mealy) if e020='1' then rifiuta <= '0'; ns <= start; ntot <= tot + conv_unsigned(2,5); elsif e050='1' then rifiuta <= '0'; ns <= start; ntot <= tot + conv_unsigned(5,5); elsif e1='1' then rifiuta <= '0'; ns <= start; ntot <= tot + conv_unsigned(10,5); elsif e2='1' then rifiuta <= '0'; ns <= start; ntot <= tot + conv_unsigned(20,5); else xx='1' then rifiuta <= '1'; ns <= start; ntot <= tot; end if; when outacqua => -- Uscite dipendenti dal solo stato rifiuta <= '0'; esce_acqua <= '1';esce_bibita <= '0'; resto <= tot-conv_unsigned(4,5); ntot <= conv_unsigned(0,5); ns <= start; when outbibita => -- Uscite dipendenti dal solo stato rifiuta <= '0'; esce_acqua <= '0';esce_bibita <= '1'; resto <= tot - conv_unsigned(8,5); ns <= start;ntot <= conv_unsigned(0,5); end case; end if; end process; -- Azzeramento contatempo process(xx,e020,e050,e1,e2) begin if (xx='1' or e020='1' or e050='1' or e1='1' or e2='1') then ncount<=conv_unsigned(0,5); else ncount<=count+conv_unsigned(1,5); end if; end process; -- Segnalazione di time over dopo 20 clk process(ncount) begin if ncount=conv_unsigned(20,5) then time_over<='1'; else time_over <= '0'; end if; end process; end bibite_p;