Advertisement
Oleguer

Maquina de estados

Jun 26th, 2022
1,015
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 3.66 KB | None | 0 0
  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3.  
  4. entity ms_p4 is
  5.     port (
  6.         FIRST, KEY0, FOURS, KEY1, Clk : in std_logic;
  7.         Actual, Suma, R, Uno, Dos, Tres, Cuatro, light, blink : out std_logic);
  8. end ms_P4;
  9.  
  10. architecture behavioural of ms_p4 is
  11.  
  12.     type state is (E0, E1, E2, E3, E4, E5, E6, E7, E8, E9, E10, E11, E12, E13, E14, E15, E16, E17);
  13.     signal state_reg, state_next : state;
  14.    
  15. begin
  16.  
  17.     process(Clk, KEY1) is
  18.     begin
  19.         if KEY1 = '1' then
  20.             state_reg <= E0;
  21.         elsif (Clk'event and Clk = '1') then
  22.             state_reg <= state_next;
  23.         end if;
  24.     end process;
  25.  
  26.     process(state_reg, FIRST) is
  27.     begin
  28.         case state_reg is
  29.             when E0 =>
  30.                 if FIRST = '1' then
  31.                 state_next <= E1;
  32.                 else
  33.                     state_next <= E0;
  34.                 end if;
  35.             when E1 =>
  36.                 if KEY0 = '1' then
  37.                     state_next <= E2;
  38.                 else
  39.                     state_next <= E1;
  40.                 end if;
  41.             when E2 =>
  42.                 if FIRST = '0' then
  43.                     state_next <= E3;
  44.                 else
  45.                     state_next <= E2;
  46.                 end if;
  47.             when E3 =>
  48.                 if FOURS = '1' then
  49.                     state_next <= E4;
  50.                 else
  51.                     state_next <= E3;
  52.                 end if;
  53.             when E4 =>
  54.                 if FOURS = '1' then
  55.                     state_next <= E5;
  56.                 else
  57.                     state_next <= E4;
  58.                 end if;
  59.             when E5 =>
  60.                 if FOURS = '1' then
  61.                     state_next <= E6;
  62.                 else
  63.                     state_next <= E5;
  64.                 end if;
  65.             when E6 =>
  66.                 if FOURS = '1' then
  67.                     state_next <= E7;
  68.                 else
  69.                     state_next <= E6;
  70.                 end if;
  71.             when E7 =>
  72.                 if FOURS = '1' then
  73.                     state_next <= E8;
  74.                 else
  75.                     state_next <= E7;
  76.                 end if;
  77.             when E8 =>
  78.                 if FOURS = '1' then
  79.                     state_next <= E9;
  80.                 else
  81.                     state_next <= E8;
  82.                 end if;
  83.             when E9 =>
  84.                 if FOURS = '1' then
  85.                     state_next <= E10;
  86.                 else
  87.                     state_next <= E9;
  88.                 end if;
  89.             when E10 =>
  90.                 if FOURS = '1' then
  91.                     state_next <= E11;
  92.                 else
  93.                     state_next <= E10;
  94.                 end if;
  95.             when E11 =>
  96.                 if FOURS = '1' then
  97.                     state_next <= E12;
  98.                 else
  99.                     state_next <= E11;
  100.                 end if;
  101.             when E12 =>
  102.                 if FOURS = '1' then
  103.                     state_next <= E13;
  104.                 else
  105.                     state_next <= E12;
  106.                 end if;
  107.             when E13 =>
  108.                 if FOURS = '1' then
  109.                     state_next <= E14;
  110.                 else
  111.                     state_next <= E13;
  112.                 end if;
  113.             when E14 =>
  114.                 if FOURS = '1' then
  115.                     state_next <= E15;
  116.                 else
  117.                     state_next <= E14;
  118.                 end if;
  119.             when E15 =>
  120.                 if FOURS = '1' then
  121.                     state_next <= E16;
  122.                 else
  123.                     state_next <= E15;
  124.                 end if;
  125.             when E16 =>
  126.                 if FOURS = '1' then
  127.                     state_next <= E16;
  128.                 else
  129.                     state_next <= E15;
  130.                 end if;
  131.             when E17 =>
  132.                 if KEY1 = '1' then
  133.                     state_next <= E0;
  134.                 else
  135.                     state_next <= E16;
  136.                 end if;
  137.         end case;
  138.     end process;
  139.  
  140.     process (state_reg) is
  141.  
  142.     begin
  143.         Actual <= '0';
  144.         Suma <= '0';
  145.         R <= '0';
  146.         Uno <= '0';
  147.         Dos <= '0';
  148.         Tres <= '0';
  149.         Cuatro <= '0';
  150.         light <= '0';
  151.         blink <= '0';
  152.        
  153.         case state_reg is
  154.             when E0 =>
  155.                 Actual <= '1';
  156.             when E1 =>
  157.                 Actual <= '1';
  158.                 Suma <= '1';
  159.             when E2 =>
  160.                 R <= '1';
  161.             when E3 =>
  162.             when E4 =>
  163.                 Uno <= '1';
  164.                 blink <= '1';
  165.             when E5 =>
  166.                 Uno <= '1';
  167.                 light <= '1';
  168.             when E6 =>
  169.                 Uno <= '1';
  170.                 blink <= '1';
  171.             when E7 =>
  172.             when E8 =>
  173.                 Dos <= '1';
  174.                 blink <= '1';
  175.             when E9 =>
  176.                 Dos <= '1';
  177.                 light <= '1';
  178.             when E10 =>
  179.                 Dos <= '1';
  180.                 blink <= '1';
  181.             when E11 =>
  182.             when E12 =>
  183.                 Tres <= '1';
  184.                 blink <= '1';
  185.             when E13 =>
  186.                 Tres <= '1';
  187.                 light <= '1';
  188.             when E14 =>
  189.                 Tres <= '1';
  190.                 blink <= '1';
  191.             when E15 =>
  192.             when E16 =>
  193.                 Cuatro <= '1';
  194.                 blink <= '1';
  195.             when E17 =>
  196.                 Cuatro <= '1';
  197.                 light <= '1';
  198.         end case;
  199.     end process;
  200. end behavioural;
  201.                
  202.                
  203.            
  204.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement