Advertisement
Guest User

Untitled

a guest
Jan 7th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 8.09 KB | None | 0 0
  1. -- Company:
  2. -- Engineer: Alessio Orlando
  3. --
  4. -- Create Date:    09:49:05 12/27/2018
  5. -- Design Name:
  6. -- Module Name:    Controllo_lezioni_TECD - Behavioral
  7. -- Project Name:
  8. -- Target Devices:
  9. -- Tool versions:
  10. -- Description:
  11. --
  12. -- Dependencies:
  13. --
  14. -- Revision:
  15. -- Revision 0.01 - File Created
  16. -- Additional Comments:
  17. --
  18. ----------------------------------------------------------------------------------
  19. library IEEE;
  20. use IEEE.STD_LOGIC_1164.ALL;
  21. use IEEE.STD_LOGIC_ARITH.ALL;
  22.  
  23. entity Controllo_lezioni_TECD is
  24.     Port ( clk : in  STD_LOGIC;
  25.            rst : in  STD_LOGIC;
  26.            badge : in  STD_LOGIC;--badge letto 1 per aprire, 0 per chiudere la sessione
  27.            col : in  STD_LOGIC_VECTOR (3 downto 1);--colonna del tastierino
  28.            row : in  STD_LOGIC_VECTOR (4 downto 1);--riga del tastierino
  29.            state_debug: out std_logic_vector(3 downto 0);
  30.            output : out  STD_LOGIC_VECTOR (2 downto 1));----vettore a 2
  31. --vettore a 2: 00 attesa iniziale(sess. chiusa), 01 seq.riconosciuta, 10 errore, 11 sessione aperta
  32. end Controllo_lezioni_TECD;
  33.  
  34. --tastierino
  35.  
  36. --          row
  37. --         100  010  001
  38. --col 1000   1     2     3  
  39. --    0100   4     5     6
  40. --    0010   7     8     9
  41. --    0001   *     0     #
  42.  
  43. architecture Behavioral of Controllo_lezioni_TECD is
  44.  
  45. --dichiaraziamo un nuovo tipo stato
  46. type state is (s0,s1,s2,s3,s4,s5,s6,s7,s8,s9);
  47.  
  48.  
  49. --dichiarazione segnali utilizzati nel processo per identificare lo stato corrente e futuro
  50. signal current_state, next_state: state;
  51.  
  52. begin
  53.  
  54. --processo di sincronizzazione del reset
  55. synchronous_process: process(clk, rst)
  56.  
  57. begin
  58.     if rising_edge(clk) then
  59.         if rst = '1' then
  60.         current_state <= s0;
  61.         else
  62.         current_state <= next_state;
  63.         end if;
  64.     end if;
  65. end process;
  66.  
  67. --processo principale tramite il quale si descrive il comportamento dell'automa di Mealy
  68. next_state_and_output_Mealy: process(current_state, badge, col, row)
  69.  
  70. begin
  71. case current_state is
  72.    
  73. when s0 =>if(badge = '1') then --lettura badge 1
  74.              next_state <= s1;
  75.           output <="01";--ingresso inserito con successo
  76.           else
  77.           next_state <= s0; --il badge resta a 0
  78.              output<= "00";
  79.              end if;
  80.              state_debug<= conv_std_logic_vector(state'POS(current_state),4);
  81.  
  82. --alla lettura del badge '1' si transita in s1        
  83.    
  84. when s1=>if(badge='1')then
  85. --non  stato inserito nulla da stastierino: resta in attesa (out 00) i s1
  86.          if(col="000" and row="0000") then
  87.              next_state<= s1;
  88.           output<="00"  ;
  89.           elsif(col="001" and row="0001")then--inserimento cancelletto: resta in s1 con out 01
  90.            next_state<= s1;
  91.            output<="01";
  92.            elsif(col="010" and row="0001") then--inserimento 0: va in s3 con out 01
  93.             next_state <= s3;
  94.             output <= "01";
  95.             else--nessuna delle precedenti: va in errore in s2 con out 10
  96.                 next_state<= s2;
  97.                 output<= "10";
  98.             end if;
  99.          else--badge=0 quindi torna in s0          
  100.          next_state<= s0;
  101.          output<= "00";
  102.          end if;
  103.             state_debug<= conv_std_logic_vector(state'POS(current_state),4);     
  104.  
  105. when s2 =>if(badge='1')then
  106. --non  stato inserito nulla da tastierino: resta in attesa (out 00) i s2
  107.              if(col="000" and row="0000") then
  108.            next_state<= s2;
  109.            output<="00"  ;
  110.            elsif(col="001" and row="0001")then--inserimento cancelletto
  111.             next_state<= s1;
  112.             output<="01";
  113.           else
  114.             next_state <= s2;
  115.             output <= "10";
  116.           end if;  
  117.           else
  118.           next_state<= s0;
  119.           output<= "00";
  120.           end if; --chiusura primo if
  121.              state_debug<= conv_std_logic_vector(state'POS(current_state),4);
  122.    
  123. when s3 => if(badge='1')then
  124. --non e' stato inserito nulla da stastierino: resta in attesa (out 00) i s3
  125.            if(col="000" and row="0000") then
  126.             next_state<= s3;
  127.             output<="00"  ;
  128.             elsif(col="001" and row="0001")then--inserimento cancelletto
  129.              next_state<= s3;
  130.              output<="01";
  131.              elsif((col="010" and row="0001") or (col="100" and row= "1000")) then--inserimento 0 o 1
  132.               next_state <= s5;
  133.               output <= "01";
  134.            else
  135.            next_state<= s4;
  136.            output<= "10";
  137.            end if;
  138.            else
  139.            next_state<= s0;
  140.            output<= "00";
  141.            end if;
  142.               state_debug<= conv_std_logic_vector(state'POS(current_state),4);      
  143.  
  144. when s4 =>if(badge='1')then
  145. --non e' stato inserito nulla da stastierino: resta in attesa (out 00) i s4
  146.           if(col="000" and row="0000") then
  147.             next_state<= s4;
  148.             output<="00";
  149.             elsif(col="001" and row="0001")then--inserimento cancelletto
  150.              next_state<= s3;
  151.              output<="01";
  152.           else
  153.             next_state <= s4;
  154.             output <= "01";
  155.           end if;  
  156.           else
  157.           next_state<= s0;
  158.           output<= "00";
  159.           end if;
  160.              state_debug<= conv_std_logic_vector(state'POS(current_state),4);
  161.          
  162. when s5 =>if(badge='1')then
  163. --non  stato inserito nulla da stastierino: resta in attesa (out 00) i s5
  164.           if(col="000" and row="0000") then
  165.             next_state<= s5;
  166.             output<="00"  ;
  167.             elsif(col="001" and row="0001")then--inserimento cancelletto
  168.              next_state<= s5;
  169.              output<="01";
  170.                  --inserimento 1 o 2
  171.              elsif((col="010" and row="1000") or (col="100" and row= "1000")) then
  172.               next_state <= s7;
  173.               output <= "01";
  174.           else
  175.             next_state<= s6;
  176.             output<= "10";
  177.           end if;
  178.           else
  179.           next_state<= s0;
  180.           output<= "00";
  181.           end if;
  182.           state_debug<= conv_std_logic_vector(state'POS(current_state),4);
  183.          
  184. when s6 =>if(badge='1')then
  185. --non  stato inserito nulla da stastierino: resta in attesa (out 00) i s6
  186.           if(col="000" and row="0000") then
  187.             next_state<= s6;
  188.             output<="00"  ;
  189.             elsif(col="001" and row="0001")then--inserimento cancelletto
  190.               next_state<= s5;
  191.               output<="01";
  192.           else
  193.             next_state <= s6;
  194.             output <= "10";
  195.           end if;  
  196.           else
  197.           next_state<= s0;
  198.           output<= "00";
  199.           end if;
  200.           state_debug<= conv_std_logic_vector(state'POS(current_state),4);
  201.                  
  202. when s7 =>if(badge='1')then
  203. --non  stato inserito nulla da stastierino: resta in attesa (out 00) i s7
  204.           if(col="000" and row="0000") then
  205.             next_state<= s7;
  206.             output<="00"  ;
  207.             elsif(col="001" and row="0001")then--inserimento cancelletto
  208.               next_state<= s7;
  209.               output<="01";
  210.                   --inserimento * per confermare apertura sessione
  211.               elsif(col="100" and row="0001") then
  212.                next_state <= s9;
  213.                output <= "01";
  214.           else
  215.             next_state<= s8;
  216.             output<= "10";
  217.           end if;
  218.           else
  219.           next_state<= s0;
  220.           output<= "00";
  221.           end if;
  222.              state_debug<= conv_std_logic_vector(state'POS(current_state),4);
  223.          
  224. when s8 =>if(badge='1')then
  225. --non e' stato inserito nulla da stastierino: resta in attesa (out 00) i s8
  226.           if(col="000" and row="0000") then
  227.             next_state<= s8;
  228.             output<="00";
  229.             elsif(col="001" and row="0001")then--inserimento cancelletto
  230.               next_state<= s7;
  231.               output<="01";
  232.           else
  233.             next_state <= s8;
  234.             output <= "10";
  235.           end if;  
  236.           else
  237.           next_state<= s0;
  238.           output<= "00";
  239.           end if;
  240.              state_debug<= conv_std_logic_vector(state'POS(current_state),4);
  241.          
  242. when s9 =>if(badge = '1') then
  243.              next_state <= s9;
  244.              output <="11";--apertura lezione
  245.              else
  246.              next_state <= s0;
  247.              output<= "00";
  248.              end if;
  249.              state_debug<= conv_std_logic_vector(state'POS(current_state),4);
  250.          
  251. end case;
  252. end process;        
  253. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement