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 Controllo_lezioni_TECD is
- Port ( clk : in STD_LOGIC;
- rst : in STD_LOGIC;
- badge : in STD_LOGIC;--badge letto 1 per aprire, 0 per chiudere la sessione
- col : in STD_LOGIC_VECTOR (3 downto 1);--colonna del tastierino
- row : in STD_LOGIC_VECTOR (4 downto 1);--riga del tastierino
- state_debug: out std_logic_vector(3 downto 0);
- output : out STD_LOGIC_VECTOR (2 downto 1));----vettore a 2
- --vettore a 2: 00 attesa iniziale(sess. chiusa), 01 seq.riconosciuta, 10 errore, 11 sessione aperta
- end Controllo_lezioni_TECD;
- --tastierino
- -- row
- -- 100 010 001
- --col 1000 1 2 3
- -- 0100 4 5 6
- -- 0010 7 8 9
- -- 0001 * 0 #
- architecture Behavioral of Controllo_lezioni_TECD is
- --dichiaraziamo un nuovo tipo stato
- type state is (s0,s1,s2,s3,s4,s5,s6,s7,s8,s9);
- --dichiarazione segnali utilizzati nel processo per identificare lo stato corrente e futuro
- signal current_state, next_state: state;
- begin
- --processo di sincronizzazione del reset
- synchronous_process: process(clk, rst)
- begin
- if rising_edge(clk) then
- if rst = '1' then
- current_state <= s0;
- else
- current_state <= next_state;
- end if;
- end if;
- end process;
- --processo principale tramite il quale si descrive il comportamento dell'automa di Mealy
- next_state_and_output_Mealy: process(current_state, badge, col, row)
- begin
- case current_state is
- when s0 =>if(badge = '1') then --lettura badge 1
- next_state <= s1;
- output <="01";--ingresso inserito con successo
- else
- next_state <= s0; --il badge resta a 0
- output<= "00";
- end if;
- state_debug<= conv_std_logic_vector(state'POS(current_state),4);
- --alla lettura del badge '1' si transita in s1
- when s1=>if(badge='1')then
- --non stato inserito nulla da stastierino: resta in attesa (out 00) i s1
- if(col="000" and row="0000") then
- next_state<= s1;
- output<="00" ;
- elsif(col="001" and row="0001")then--inserimento cancelletto: resta in s1 con out 01
- next_state<= s1;
- output<="01";
- elsif(col="010" and row="0001") then--inserimento 0: va in s3 con out 01
- next_state <= s3;
- output <= "01";
- else--nessuna delle precedenti: va in errore in s2 con out 10
- next_state<= s2;
- output<= "10";
- end if;
- else--badge=0 quindi torna in s0
- next_state<= s0;
- output<= "00";
- end if;
- state_debug<= conv_std_logic_vector(state'POS(current_state),4);
- when s2 =>if(badge='1')then
- --non stato inserito nulla da tastierino: resta in attesa (out 00) i s2
- if(col="000" and row="0000") then
- next_state<= s2;
- output<="00" ;
- elsif(col="001" and row="0001")then--inserimento cancelletto
- next_state<= s1;
- output<="01";
- else
- next_state <= s2;
- output <= "10";
- end if;
- else
- next_state<= s0;
- output<= "00";
- end if; --chiusura primo if
- state_debug<= conv_std_logic_vector(state'POS(current_state),4);
- when s3 => if(badge='1')then
- --non e' stato inserito nulla da stastierino: resta in attesa (out 00) i s3
- if(col="000" and row="0000") then
- next_state<= s3;
- output<="00" ;
- elsif(col="001" and row="0001")then--inserimento cancelletto
- next_state<= s3;
- output<="01";
- elsif((col="010" and row="0001") or (col="100" and row= "1000")) then--inserimento 0 o 1
- next_state <= s5;
- output <= "01";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement