Advertisement
Endrerl

dsf

Nov 14th, 2019
619
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 5.88 KB | None | 0 0
  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3. use ieee.numeric_std.all;
  4.  
  5. entity lab8_del2 is
  6.   port(
  7.     CLOCK_50 : in    std_logic;
  8.     KEY      : in    std_logic_vector(3 downto 0);
  9.     SW       : in    std_logic_vector(17 downto 0);
  10.     GPIO     : inout std_logic_vector(35 downto 0);
  11.     LEDR     : out   std_logic_vector(17 downto 0);
  12.     LEDG     : out   std_logic_vector(7 downto 0)
  13.     );
  14. end entity lab8_del2;
  15.  
  16. architecture RTL of lab8_del2 is
  17.  
  18.   component Enable_gen is
  19.     port(clock_50    : in  std_logic;
  20.          resetn      : in  std_logic;
  21.          velg_enable : in  std_logic_vector(2 downto 0);
  22.          Enable      : out std_logic);
  23.   end component;
  24.  
  25.   component reset_synchronizer is
  26.     port(
  27.       clk        : in  std_logic;
  28.       reset_key3 : in  std_logic;
  29.       reset_clk  : out std_logic
  30.       );
  31.   end component reset_synchronizer;
  32.  
  33.   component baudrate_gen is
  34.     port(
  35.       CLOCK_50      : in std_logic;
  36.       resetn        : in std_logic;
  37.       velg_baudrate : in std_logic_vector(2 downto 0);
  38.       start_teller  : in std_logic;
  39.  
  40.       baud_enable_m : out std_logic;
  41.       baud_enable_s : out std_logic
  42.       );
  43.   end component baudrate_gen;
  44.  
  45.  
  46.   signal resetn           : std_logic;
  47.   signal hallo_enable     : std_logic;
  48.   signal hallo            : std_logic;
  49.   signal sender           : std_logic;
  50.   signal mottatt_blink    : std_logic;
  51.   signal vippe_a, vippe_b : std_logic;
  52.  
  53.   signal start_teller, baud_enable_m, baud_enable_s : std_logic;
  54.  
  55.   type sender_state_type is = (s_idle, s_transmit, s_shift_out, s_finish, s_wait);
  56.   signal sender_state : sender_state_type;
  57.  
  58.   signal send_shift_register : std_logic_vector(9 downto 0);
  59.  
  60.   constant start_bit : std_logic := '0';
  61.   constant stopp_bit : std_logic := '1';
  62.  
  63.   signal data_ut, data_inn : std_logic;
  64.   signal start_q,start_qq : std_logic;
  65.  
  66.  
  67. begin
  68.  
  69.   Enable_gen_inst : component Enable_gen
  70.     port map(
  71.       clock_50    => CLOCK_50,
  72.       resetn      => resetn,
  73.       velg_enable => "000",
  74.       Enable      => hallo_enable
  75.       );
  76.  
  77.   reset_synchronizer_inst : component reset_synchronizer
  78.     port map(
  79.       clk        => CLOCK_50,
  80.       reset_key3 => KEY(3),
  81.       reset_clk  => resetn
  82.       );
  83.  
  84.   -- lag lokalt blinkesignal
  85.   p_hallo : process (CLOCK_50) is
  86.   begin
  87.     if rising_edge(CLOCK_50) then
  88.       if resetn = '0' then
  89.         hallo <= '0';
  90.       elsif hallo_enable = '1' then
  91.         hallo <= not hallo;
  92.       end if;
  93.     end if;
  94.   end process p_hallo;
  95.  
  96.   LEDR(17) <= hallo;
  97.  
  98.   sender  <= SW(17);
  99.   LEDG(0) <= sender;
  100.   LEDG(7) <= mottatt_blink;
  101.  
  102.   p_send_motta_hallo : process (CLOCK_50) is
  103.   begin
  104.     if rising_edge(CLOCK_50) then
  105.       -- sender hallo
  106.       if sender = '1' then
  107.         GPIO (1)      <= hallo;
  108.         mottatt_blink <= '0';
  109.       else
  110.         -- mottar hallo
  111.         GPIO(1)       <= 'Z';
  112.         vippe_a       <= GPIO(1);
  113.         vippe_b       <= vippe_a;
  114.         mottatt_blink <= vippe_b;
  115.       end if;
  116.     end if;
  117.   end process;
  118.  
  119.   baudrate_gen_inst : component baudrate_gen
  120.     port map(
  121.       CLOCK_50      => CLOCK_50,
  122.       resetn        => resetn,
  123.       velg_baudrate => SW(16 downto 14),
  124.       start_teller  => start_teller,
  125.       baud_enable_m => baud_enable_m,
  126.       baud_enable_s => baud_enable_s
  127.       );
  128.  
  129.   data_inn <= GPIO(7) when sender = '0' else '1';
  130.   GPIO(7)  <= data_ut when sender = '1' else 'Z';
  131.  
  132.   p_start_teller : process (CLOCK_50) is
  133.   begin
  134.     if rising_edge(CLOCK_50) then
  135.       if resetn = '0' then
  136.         start_teller <= '0';
  137.         data_inn_q   <= '0';
  138.         data_inn_qq  <= '0';
  139.         data_inn_qqq <= '0';
  140.       else
  141.         start_teller <= '0';
  142.         data_inn_q   <= data_inn;
  143.         data_inn_qq  <= data_inn_q;
  144.         data_inn_qqq <= data_inn_qq;
  145.         if data_inn_qqq = '1' and data_inn_qq = '0' then
  146.           --fallende flanke
  147.           if state = s_wait_for_sender then
  148.             start_teller <= '1';
  149.           end if;
  150.         end if;
  151.       end if;
  152.     end if;
  153.  
  154.   end process p_start_teller;
  155.  
  156.   start_sender <= KEY(0);
  157.  
  158.   p_sync_start_sender : process(CLOCK_50)
  159.   begin
  160.     if rising_edge(CLOCK_50) then
  161.       if resetn = '0' then
  162.         start_q  <= '0';
  163.         start_qq <= '0';
  164.       else
  165.         start_q  <= not start_sender;
  166.         start_qq <= start_sender;
  167.       end if;
  168.     end if;
  169.   end process;
  170.  
  171.   p_sender_tilstandsmaskin : process(CLOCK_50)
  172.   begin
  173.     if rising_edge(CLOCK_50) then
  174.       if resetn = '0' then
  175.         sender_state <= s_idle;
  176.       else
  177.         if sender = '1' then
  178.           case sender_state is
  179.  
  180.             when s_idle =>
  181.               data_ut             <= '1';
  182.               send_shift_register <= (others => '0');
  183.               if start_qq = '1' then
  184.                 sender_State <= s_transmit;
  185.               end if;
  186.             when s_transmit =>
  187.               data_ut             <= '1';
  188.               send_shift_register <= stopp_bit & SW(8 downto 1) & start_bit;
  189.               if baud_enable_s = '1' then
  190.  
  191.                 sender_state <= s_shift_out;
  192.               end if;
  193.             when s_shift_out =>
  194.               data_ut <= send_shift_register(0);
  195.               if baud_enable_s = '1' then
  196.                 send_shift_register <= '0' & send_shift_register(9 downto 1);
  197.                 if sender_shift_register = "0000000000" then
  198.                   sender_State <= s_finish;
  199.                 end if;
  200.               end if;
  201.             when s_finish =>
  202.               data_ut <= '1';
  203.               if baud_enable_s = '1' then
  204.                 sender_state <= s_wait;
  205.               end if;
  206.             when s_wait =>
  207.               data_ut <= '1';
  208.               if baud_enable_s = '1' then
  209.                 sender_state <= s_transmit;
  210.               end if;
  211.             when others =>
  212.           end case;
  213.         end if;
  214.       end if;
  215.     end if;
  216.  
  217.   end process;
  218.  
  219.  
  220. end architecture RTL;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement