Advertisement
Guest User

Untitled

a guest
Jan 7th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 6.54 KB | None | 0 0
  1. --processo di sincronizzazione del reset
  2. synchronous_process: process(clk, rst)
  3.  
  4. begin
  5.     if rising_edge(clk) then
  6.         if rst = '1' then
  7.         current_state <= s0;
  8.         else
  9.         current_state <= next_state;
  10.         end if;
  11.     end if;
  12. end process;
  13.  
  14. --processo principale tramite il quale si descrive il comportamento dell'automa di Mealy
  15. next_state_and_output_Mealy: process(current_state, badge, col, row)
  16.  
  17. begin
  18. case current_state is
  19.    
  20. when s0 =>if(badge = '1') then --lettura badge 1
  21.              next_state <= s1;
  22.           output <="01";--ingresso inserito con successo
  23.           else
  24.           next_state <= s0; --il badge resta a 0
  25.              output<= "00";
  26.              end if;
  27.              state_debug<= conv_std_logic_vector(state'POS(current_state),4);
  28.  
  29. --alla lettura del badge '1' si transita in s1        
  30.    
  31. when s1=>if(badge='1')then
  32. --non  stato inserito nulla da stastierino: resta in attesa (out 00) i s1
  33.          if(col="000" and row="0000") then
  34.              next_state<= s1;
  35.           output<="00"  ;
  36.           elsif(col="001" and row="0001")then--inserimento cancelletto: resta in s1 con out 01
  37.            next_state<= s1;
  38.            output<="01";
  39.            elsif(col="010" and row="0001") then--inserimento 0: va in s3 con out 01
  40.             next_state <= s3;
  41.             output <= "01";
  42.             else--nessuna delle precedenti: va in errore in s2 con out 10
  43.                 next_state<= s2;
  44.                 output<= "10";
  45.             end if;
  46.          else--badge=0 quindi torna in s0          
  47.          next_state<= s0;
  48.          output<= "00";
  49.          end if;
  50.             state_debug<= conv_std_logic_vector(state'POS(current_state),4);     
  51.  
  52. when s2 =>if(badge='1')then
  53. --non  stato inserito nulla da tastierino: resta in attesa (out 00) i s2
  54.              if(col="000" and row="0000") then
  55.            next_state<= s2;
  56.            output<="00"  ;
  57.            elsif(col="001" and row="0001")then--inserimento cancelletto
  58.             next_state<= s1;
  59.             output<="01";
  60.           else
  61.             next_state <= s2;
  62.             output <= "10";
  63.           end if;  
  64.           else
  65.           next_state<= s0;
  66.           output<= "00";
  67.           end if; --chiusura primo if
  68.              state_debug<= conv_std_logic_vector(state'POS(current_state),4);
  69.    
  70. when s3 => if(badge='1')then
  71. --non e' stato inserito nulla da stastierino: resta in attesa (out 00) i s3
  72.            if(col="000" and row="0000") then
  73.             next_state<= s3;
  74.             output<="00"  ;
  75.             elsif(col="001" and row="0001")then--inserimento cancelletto
  76.              next_state<= s3;
  77.              output<="01";
  78.              elsif((col="010" and row="0001") or (col="100" and row= "1000")) then--inserimento 0 o 1
  79.               next_state <= s5;
  80.               output <= "01";
  81.            else
  82.            next_state<= s4;
  83.            output<= "10";
  84.            end if;
  85.            else
  86.            next_state<= s0;
  87.            output<= "00";
  88.            end if;
  89.               state_debug<= conv_std_logic_vector(state'POS(current_state),4);      
  90.  
  91. when s4 =>if(badge='1')then
  92. --non e' stato inserito nulla da stastierino: resta in attesa (out 00) i s4
  93.           if(col="000" and row="0000") then
  94.             next_state<= s4;
  95.             output<="00";
  96.             elsif(col="001" and row="0001")then--inserimento cancelletto
  97.              next_state<= s3;
  98.              output<="01";
  99.           else
  100.             next_state <= s4;
  101.             output <= "01";
  102.           end if;  
  103.           else
  104.           next_state<= s0;
  105.           output<= "00";
  106.           end if;
  107.              state_debug<= conv_std_logic_vector(state'POS(current_state),4);
  108.          
  109. when s5 =>if(badge='1')then
  110. --non  stato inserito nulla da stastierino: resta in attesa (out 00) i s5
  111.           if(col="000" and row="0000") then
  112.             next_state<= s5;
  113.             output<="00"  ;
  114.             elsif(col="001" and row="0001")then--inserimento cancelletto
  115.              next_state<= s5;
  116.              output<="01";
  117.                  --inserimento 1 o 2
  118.              elsif((col="010" and row="1000") or (col="100" and row= "1000")) then
  119.               next_state <= s7;
  120.               output <= "01";
  121.           else
  122.             next_state<= s6;
  123.             output<= "10";
  124.           end if;
  125.           else
  126.           next_state<= s0;
  127.           output<= "00";
  128.           end if;
  129.           state_debug<= conv_std_logic_vector(state'POS(current_state),4);
  130.          
  131. when s6 =>if(badge='1')then
  132. --non  stato inserito nulla da stastierino: resta in attesa (out 00) i s6
  133.           if(col="000" and row="0000") then
  134.             next_state<= s6;
  135.             output<="00"  ;
  136.             elsif(col="001" and row="0001")then--inserimento cancelletto
  137.               next_state<= s5;
  138.               output<="01";
  139.           else
  140.             next_state <= s6;
  141.             output <= "10";
  142.           end if;  
  143.           else
  144.           next_state<= s0;
  145.           output<= "00";
  146.           end if;
  147.           state_debug<= conv_std_logic_vector(state'POS(current_state),4);
  148.                  
  149. when s7 =>if(badge='1')then
  150. --non  stato inserito nulla da stastierino: resta in attesa (out 00) i s7
  151.           if(col="000" and row="0000") then
  152.             next_state<= s7;
  153.             output<="00"  ;
  154.             elsif(col="001" and row="0001")then--inserimento cancelletto
  155.               next_state<= s7;
  156.               output<="01";
  157.                   --inserimento * per confermare apertura sessione
  158.               elsif(col="100" and row="0001") then
  159.                next_state <= s9;
  160.                output <= "01";
  161.           else
  162.             next_state<= s8;
  163.             output<= "10";
  164.           end if;
  165.           else
  166.           next_state<= s0;
  167.           output<= "00";
  168.           end if;
  169.              state_debug<= conv_std_logic_vector(state'POS(current_state),4);
  170.          
  171. when s8 =>if(badge='1')then
  172. --non e' stato inserito nulla da stastierino: resta in attesa (out 00) i s8
  173.           if(col="000" and row="0000") then
  174.             next_state<= s8;
  175.             output<="00";
  176.             elsif(col="001" and row="0001")then--inserimento cancelletto
  177.               next_state<= s7;
  178.               output<="01";
  179.           else
  180.             next_state <= s8;
  181.             output <= "10";
  182.           end if;  
  183.           else
  184.           next_state<= s0;
  185.           output<= "00";
  186.           end if;
  187.              state_debug<= conv_std_logic_vector(state'POS(current_state),4);
  188.          
  189. when s9 =>if(badge = '1') then
  190.              next_state <= s9;
  191.              output <="11";--apertura lezione
  192.              else
  193.              next_state <= s0;
  194.              output<= "00";
  195.              end if;
  196.              state_debug<= conv_std_logic_vector(state'POS(current_state),4);
  197.          
  198. end case;
  199. end process;        
  200. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement