Advertisement
Guest User

Untitled

a guest
Jan 7th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 3.79 KB | None | 0 0
  1. library IEEE;
  2. use IEEE.STD_LOGIC_1164.ALL;
  3. use IEEE.STD_LOGIC_ARITH.ALL;
  4.  
  5. entity Controllo_lezioni_TECD is
  6.     Port ( clk : in  STD_LOGIC;
  7.            rst : in  STD_LOGIC;
  8.            badge : in  STD_LOGIC;--badge letto 1 per aprire, 0 per chiudere la sessione
  9.            col : in  STD_LOGIC_VECTOR (3 downto 1);--colonna del tastierino
  10.            row : in  STD_LOGIC_VECTOR (4 downto 1);--riga del tastierino
  11.            state_debug: out std_logic_vector(3 downto 0);
  12.            output : out  STD_LOGIC_VECTOR (2 downto 1));----vettore a 2
  13. --vettore a 2: 00 attesa iniziale(sess. chiusa), 01 seq.riconosciuta, 10 errore, 11 sessione aperta
  14. end Controllo_lezioni_TECD;
  15.  
  16. --tastierino
  17.  
  18. --          row
  19. --         100  010  001
  20. --col 1000   1     2     3  
  21. --    0100   4     5     6
  22. --    0010   7     8     9
  23. --    0001   *     0     #
  24.  
  25. architecture Behavioral of Controllo_lezioni_TECD is
  26.  
  27. --dichiaraziamo un nuovo tipo stato
  28. type state is (s0,s1,s2,s3,s4,s5,s6,s7,s8,s9);
  29.  
  30.  
  31. --dichiarazione segnali utilizzati nel processo per identificare lo stato corrente e futuro
  32. signal current_state, next_state: state;
  33.  
  34. begin
  35.  
  36. --processo di sincronizzazione del reset
  37. synchronous_process: process(clk, rst)
  38.  
  39. begin
  40.     if rising_edge(clk) then
  41.         if rst = '1' then
  42.         current_state <= s0;
  43.         else
  44.         current_state <= next_state;
  45.         end if;
  46.     end if;
  47. end process;
  48.  
  49. --processo principale tramite il quale si descrive il comportamento dell'automa di Mealy
  50. next_state_and_output_Mealy: process(current_state, badge, col, row)
  51.  
  52. begin
  53. case current_state is
  54.    
  55. when s0 =>if(badge = '1') then --lettura badge 1
  56.              next_state <= s1;
  57.           output <="01";--ingresso inserito con successo
  58.           else
  59.           next_state <= s0; --il badge resta a 0
  60.              output<= "00";
  61.              end if;
  62.              state_debug<= conv_std_logic_vector(state'POS(current_state),4);
  63.  
  64. --alla lettura del badge '1' si transita in s1        
  65.    
  66. when s1=>if(badge='1')then
  67. --non  stato inserito nulla da stastierino: resta in attesa (out 00) i s1
  68.          if(col="000" and row="0000") then
  69.              next_state<= s1;
  70.           output<="00"  ;
  71.           elsif(col="001" and row="0001")then--inserimento cancelletto: resta in s1 con out 01
  72.            next_state<= s1;
  73.            output<="01";
  74.            elsif(col="010" and row="0001") then--inserimento 0: va in s3 con out 01
  75.             next_state <= s3;
  76.             output <= "01";
  77.             else--nessuna delle precedenti: va in errore in s2 con out 10
  78.                 next_state<= s2;
  79.                 output<= "10";
  80.             end if;
  81.          else--badge=0 quindi torna in s0          
  82.          next_state<= s0;
  83.          output<= "00";
  84.          end if;
  85.             state_debug<= conv_std_logic_vector(state'POS(current_state),4);     
  86.  
  87. when s2 =>if(badge='1')then
  88. --non  stato inserito nulla da tastierino: resta in attesa (out 00) i s2
  89.              if(col="000" and row="0000") then
  90.            next_state<= s2;
  91.            output<="00"  ;
  92.            elsif(col="001" and row="0001")then--inserimento cancelletto
  93.             next_state<= s1;
  94.             output<="01";
  95.           else
  96.             next_state <= s2;
  97.             output <= "10";
  98.           end if;  
  99.           else
  100.           next_state<= s0;
  101.           output<= "00";
  102.           end if; --chiusura primo if
  103.              state_debug<= conv_std_logic_vector(state'POS(current_state),4);
  104.    
  105. when s3 => if(badge='1')then
  106. --non e' stato inserito nulla da stastierino: resta in attesa (out 00) i s3
  107.            if(col="000" and row="0000") then
  108.             next_state<= s3;
  109.             output<="00"  ;
  110.             elsif(col="001" and row="0001")then--inserimento cancelletto
  111.              next_state<= s3;
  112.              output<="01";
  113.              elsif((col="010" and row="0001") or (col="100" and row= "1000")) then--inserimento 0 o 1
  114.               next_state <= s5;
  115.               output <= "01";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement