Advertisement
Endrerl

LK

Oct 22nd, 2019
535
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 4.17 KB | None | 0 0
  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3. use ieee.numeric_std.all;
  4. entity lyskryss is
  5.   port(
  6.     CLOCK_50 : in    std_logic;
  7.     KEY      : in    std_logic_vector(3 downto 0);
  8.     SW       : in    std_logic_vector(17 downto 0);
  9.     GPIO     : inout std_logic_vector(35 downto 0);
  10.     LEDR     : out   std_logic_vector(17 downto 0)
  11.     );
  12. end entity lyskryss;
  13.  
  14.  
  15.  
  16. architecture RTL of lyskryss is
  17.  
  18.   signal reset_n, clk, Enable, hallo : std_logic;
  19.   signal velg_enable                 : std_logic_vector(2 downto 0);
  20.   signal state_output                : std_logic_vector(5 downto 0);
  21.   type tilstand is (fase1, fase2, fase3, fase4, fase5, fase6);
  22.   signal state                       : tilstand;
  23.   type ROM_array is array (0 to 5) of std_logic_vector(5 downto 0);
  24.   -- 000001 OV-GRONN / 000010 OV-GUL / 000100 OV-ROD / 001000 NS-GRONN
  25.   -- 010000 NS-gul / 100000 NS-ROD
  26.   constant ROM_fase                  : ROM_array := ("001100", "010100", "100110", "100001", "100010", "110100");
  27.   type tid_array is array (0 to 5) of integer range 0 to 127;
  28.   constant fase_tid                  : tid_array := (40, 4, 3, 40, 4, 3);
  29.   signal teller                      : integer range 0 to 41;
  30. --  signal Sensor1N, Sensor1S, Sensor2O, Sensor2V : std_logic;
  31.  
  32.   component reset_sync is
  33.     port(
  34.       clk       : in  std_logic;
  35.       rst_n     : in  std_logic;
  36.       rst_clk_n : out std_logic
  37.       );
  38.   end component;
  39.   component Enable_gen is
  40.     port (clock_50    : in     std_logic;
  41.           resetn      : in     std_logic;
  42.           velg_enable : in     std_logic_vector(2 downto 0);
  43.           enable      : buffer std_logic
  44.           );
  45.   end component;
  46.  
  47.  
  48. begin
  49.   LEDR(17)           <= hallo;
  50.   clk                <= CLOCK_50;
  51.   GPIO(5 downto 0)   <= state_output;
  52.   LEDR(16 downto 13) <= GPIO(35 downto 32);
  53.   reset_n            <= KEY(3);
  54.   Velg_enable        <= SW(2 downto 0);
  55.   -- Sensor2O, Sensor2V, Sensor1N, Sensor1S <= GPIO(35 downto 32);
  56.  
  57.   blink : Enable_gen
  58.     port map(
  59.       velg_enable => velg_enable,
  60.       clock_50    => clk,
  61.       resetn      => reset_n,
  62.       enable      => Enable
  63.       );
  64.  
  65.   blink_17 : process(clk)
  66.   begin
  67.     if rising_edge(clk) then
  68.       if reset_n = '0' then
  69.         hallo <= '0';
  70.       elsif Enable = '1' then
  71.         hallo <= not hallo;
  72.       end if;
  73.     end if;
  74.   end process blink_17;
  75.  
  76.   tilstandsmaskin : process(clk)
  77.   begin
  78.     if rising_edge(clk) then
  79.       if reset_n = '0' then
  80.         state <= fase1;
  81.       elsif Enable = '1' then
  82.         teller <= teller + 1;
  83.         case state is
  84.           when fase1 =>
  85.             if teller = fase_tid(0) then
  86.               teller <= 0;
  87.               state  <= fase2;
  88.             end if;
  89.           when fase2 =>
  90.             if teller = fase_tid(1) then
  91.               teller <= 0;
  92.               state  <= fase3;
  93.             end if;
  94.           when fase3 =>
  95.             if teller = fase_tid(2) then
  96.               teller <= 0;
  97.               state  <= fase4;
  98.             end if;
  99.           when fase4 =>
  100.             if teller = fase_tid(3) then
  101.               teller <= 0;
  102.               state  <= fase5;
  103.             end if;
  104.           when fase5 =>
  105.             if teller = fase_tid(4) then
  106.               teller <= 0;
  107.               state  <= fase6;
  108.             end if;
  109.           when fase6 =>
  110.             if teller = fase_tid(5) then
  111.               teller <= 0;
  112.               state  <= fase1;
  113.             end if;
  114.           when others =>
  115.             if teller = fase_tid(0) then
  116.               teller <= 0;
  117.               state  <= fase1;
  118.             end if;
  119.         end case;
  120.       end if;
  121.     end if;
  122.   end process tilstandsmaskin;
  123.  
  124.   stae_values : process(state)
  125.   begin
  126.     case state is
  127.       when fase1 =>
  128.         state_output <= ROM_fase(0);
  129.       when fase2 =>
  130.         state_output <= ROM_fase(1);
  131.       when fase3 =>
  132.         state_output <= ROM_fase(2);
  133.       when fase4 =>
  134.         state_output <= ROM_fase(3);
  135.       when fase5 =>
  136.         state_output <= ROM_fase(4);
  137.       when fase6 =>
  138.         state_output <= ROM_fase(5);
  139.       when others =>
  140.         state_output <= ROM_fase(0);
  141.     end case;
  142.   end process;
  143.  
  144. end architecture RTL;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement