Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library IEEE;
- use IEEE.STD_LOGIC_1164.ALL;
- use IEEE.STD_LOGIC_ARITH.ALL;
- entity GestionePulsanti is
- Port ( rst : in STD_LOGIC;
- clk : in STD_LOGIC;
- P1 : in STD_LOGIC;
- P2 : in STD_LOGIC;
- seg_out : out STD_LOGIC_VECTOR (0 to 3);
- state_debug : out STD_LOGIC_VECTOR (0 to 2);
- count_debug : out STD_LOGIC_VECTOR (0 to 3));
- end GestionePulsanti;
- architecture Behavioral of GestionePulsanti is
- type state is (PrecP1, Win1_Prec1, Win2_Prec1, PrecP2, Win1_Prec2, Win2_Prec2);
- signal CurrentState, NextState: state;
- signal count, new_count: integer range 0 to 10;
- signal temp_unlock: std_logic:= '0';
- signal timeover: std_logic:= '0';
- begin
- Memorizzazione: process(clk, rst) -- reset di tipo asincrono
- begin
- if(rst='1')
- -- se il reset alto, resetto la macchina riportandola allo stato iniziale
- then CurrentState <= PrecP1;
- count <= 0;
- elsif(rising_edge(clk))
- -- altrimenti, commuto di stato sul fronte di salita del clock
- then CurrentState <= NextState;
- count <= new_count;
- end if;
- end process;
- TransizioneStato: process(CurrentState, P1, P2, timeover)
- variable Ingressi: std_logic_vector (0 to 1);
- begin
- Ingressi:=P2&P1;
- case (CurrentState) is
- when PrecP1 => temp_unlock<='0';
- state_debug<="000";
- case Ingressi is
- when "00" => NextState <= PrecP1;
- when "01" => NextState <= Win1_Prec1;
- when "10" => NextState <= Win2_Prec1;
- when "11" => NextState <= Win1_Prec2;
- when others => null;
- end case;
- when Win1_Prec1 => temp_unlock<='1';
- state_debug<="001";
- if (timeover='1') then
- case Ingressi is
- when others => NextState <= PrecP1;
- -- torna nello stato PrecP1 quando ha finito di contare
- end case;
- elsif (timeover='0') then
- case Ingressi is
- when others => NextState <= Win1_Prec1;
- -- rimane nello stato corrente
- end case;
- end if;
- when Win2_Prec1 => temp_unlock<='1';
- state_debug<="010";
- if (timeover='1') then
- case Ingressi is
- when others => NextState <= PrecP1;
- -- torna nello stato PrecP1 quando ha finito di contare
- end case;
- elsif (timeover='0') then
- case Ingressi is
- when others => NextState <= Win2_Prec1;
- -- rimane nello stato corrente
- end case;
- end if;
- when PrecP2 => temp_unlock<='0';
- state_debug<="011";
- case Ingressi is
- when "00" => NextState <= PrecP2;
- when "01" => NextState <= Win1_Prec2;
- when "10" => NextState <= Win2_Prec2;
- when "11" => NextState <= Win2_Prec1;
- when others => null;
- end case;
- when Win1_Prec2 => temp_unlock<='1';
- state_debug<="100";
- if (timeover='1') then
- case Ingressi is
- when others => NextState <= PrecP2;
- -- torna nello stato PrecP1 quando ha finito di contare
- end case;
- elsif (timeover='0') then
- case Ingressi is
- when others => NextState <= Win1_Prec2;
- -- rimane nello stato corrente
- end case;
- end if;
- when Win2_Prec2 => temp_unlock<='1';
- state_debug<="101";
- if (timeover='1') then
- case Ingressi is
- when others => NextState <= PrecP2;
- -- torna nello stato PrecP1 quando ha finito di contare
- end case;
- elsif (timeover='0') then
- case Ingressi is
- when others => NextState <= Win2_Prec2;
- -- rimane nello stato corrente
- end case;
- end if;
- end case;
- end process;
- Uscite: process(CurrentState)
- begin
- case CurrentState is
- when PrecP1 => seg_out <= "1111"; -- display spento
- when Win1_Prec1 => seg_out <= "0001"; -- vince il giocatore 1
- when Win2_Prec1 => seg_out <= "0010"; -- vince il giocatore 2
- when PrecP2 => seg_out <= "1111"; -- display spento
- when Win1_Prec2 => seg_out <= "0001"; -- vince il giocatore 1
- when Win2_Prec2 => seg_out <= "0010"; -- vince il giocatore 2
- end case;
- end process;
- Contatore: process(temp_unlock, count)
- begin
- if temp_unlock = '1' then -- questo segnale vale 1 quando sto in uno stato di conteggio
- if count = 10 then -- se ho finito di contare, azzero new_count ed imposto timeover ad 1
- new_count <= 0;
- timeover <= '1';
- else -- altrimenti aggiorno il contatore di 1
- new_count <= count + 1;
- timeover <= '0';
- end if;
- else
- new_count <= 0;
- timeover <= '0';
- end if;
- end process;
- count_debug <= conv_std_logic_vector(count, 4);
- end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement