Advertisement
Guest User

Untitled

a guest
May 21st, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.97 KB | None | 0 0
  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3. use ieee.std_logic_unsigned.all;
  4. use ieee.std_logic_misc.all;
  5.  
  6. entity SERIAL_RX is
  7. generic (
  8. F_ZEGARA :natural := 20000000; -- czestotliwosc zegata w [Hz]
  9. L_BODOW :natural := 9600; -- predkosc nadawania w [bodach]
  10. B_SLOWA :natural := 8; -- liczba bitow slowa danych (5-8)
  11. B_STOPOW :natural := 2; -- liczba bitow stopu (1-2)
  12. N_RX :boolean := FALSE; -- negacja logiczna sygnalu szeregowego
  13. N_SLOWO :boolean := FALSE -- negacja logiczna slowa danych
  14. );
  15. port (
  16. R :in std_logic; -- sygnal resetowania
  17. C :in std_logic; -- zegar taktujacy
  18. RX :in std_logic; -- odebrany sygnal szeregowy
  19. SLOWO :out std_logic_vector(B_SLOWA-1 downto 0); -- odebrane slowo danych
  20. GOTOWE :out std_logic -- flaga potwierdzenia odbioru
  21. );
  22. end SERIAL_RX;
  23.  
  24. architecture behavioural of SERIAL_RX is
  25.  
  26. signal wejscie :std_logic_vector(0 to 1); -- podwojny rejestr sygnalu RX
  27.  
  28. type ETAP is (CZEKANIE, START, DANA, STOP); -- lista etapow pracy odbiornika
  29. signal stan :ETAP; -- rejestr maszyny stanow odbiornika
  30.  
  31. constant T :positive := F_ZEGARA/L_BODOW-1; -- czas jednego bodu - liczba takt?w zegara
  32. signal l_czasu :natural range 0 to T; -- licznik czasu jednego bodu
  33. signal l_bitow :natural range 0 to B_SLOWA-1;
  34. signal bufor :std_logic_vector(B_SLOWA-1 downto 0);
  35.  
  36. begin
  37.  
  38. process (R, C) is
  39. begin
  40.  
  41. if (R='1') then
  42. wejscie <= (others => '0');
  43. stan <= CZEKANIE;
  44. l_czasu <= 0;
  45. SLOWO <= (others => '0');
  46. GOTOWE <= '0';
  47.  
  48. elsif (rising_edge(C)) then
  49.  
  50. GOTOWE <= '0';
  51. wejscie(0) <= RX;
  52. if (N_RX = TRUE) then
  53. wejscie(0) <= not(RX);
  54. end if;
  55. wejscie(1) <= wejscie(0);
  56.  
  57. case stan is
  58.  
  59. when CZEKANIE =>
  60. l_czasu <= 0;
  61. if (wejscie(1)='0' and wejscie(0)='1') then
  62. stan <= START;
  63. end if;
  64.  
  65. when START =>
  66. if(l_czasu /= T/2) then
  67. l_czasu <= l_czasu + 1;
  68. else
  69. l_czasu <= 0;
  70. l_bitow <= 0;
  71. stan <= DANA;
  72. end if;
  73.  
  74. when DANA =>
  75. if(l_czasu /= T) then
  76. l_czasu <= l_czasu + 1;
  77. else
  78. l_czasu <= 0;
  79. bufor(bufor'left) <= wejscie(1);
  80. bufor(bufor'left-1 downto 0) <= bufor(bufor'left downto 1);
  81. if(l_bitow < B_SLOWA - 1) then
  82. l_bitow <= l_bitow + 1;
  83. else
  84. stan <= STOP;
  85. end if;
  86. end if;
  87.  
  88. when STOP =>
  89.  
  90. SLOWO <= bufor;
  91. if(N_SLOWO) then
  92. SLOWO <= not(bufor);
  93. end if;
  94.  
  95. if(not(bufor) = "00110001") then
  96. SLOWO <= "00000001";
  97. elsif(not(bufor) = "00110010") then
  98. SLOWO <= "00000010";
  99. elsif(not(bufor) = "00110011") then
  100. SLOWO <= "00000100";
  101. elsif(not(bufor) = "00110100") then
  102. SLOWO <= "00001000";
  103. elsif(not(bufor) = "00110101") then
  104. SLOWO <= "00010000";
  105. elsif(not(bufor) = "00110110") then
  106. SLOWO <= "00100000";
  107. elsif(not(bufor) = "00110111") then
  108. SLOWO <= "01000000";
  109. elsif(not(bufor) = "00111000") then
  110. SLOWO <= "10000000";
  111. end if;
  112.  
  113. GOTOWE <= '1';
  114. stan <= CZEKANIE;
  115. end case;
  116.  
  117. end if;
  118.  
  119. end process;
  120.  
  121. end behavioural;
  122.  
  123.  
  124. --- MAIN FILE --- fpga.vhd ---
  125. --------------------------------------------------------------------------------
  126.  
  127. --------------------------------------------------------------------------------
  128. -- SubModule LD
  129. -- Created 02/17/2016 9:41:04 PM
  130. --------------------------------------------------------------------------------
  131. Library IEEE;
  132. Use IEEE.Std_Logic_1164.all;
  133. Use IEEE.std_logic_misc.all;
  134. Use IEEE.Std_Logic_unsigned.all;
  135. Use IEEE.numeric_std.all;
  136.  
  137. entity FPGA is port
  138. (
  139. RS_TX : out STD_LOGIC;
  140. RS_RX : in STD_LOGIC;
  141. CLK_I : in STD_LOGIC;
  142. RESET : in STD_LOGIC;
  143. BTN_IN : in STD_LOGIC_VECTOR(4 downto 0);
  144. SW_IN : in STD_LOGIC_VECTOR(7 downto 0);
  145. LED_OUT : out STD_LOGIC_VECTOR(7 downto 0)
  146. );
  147. end FPGA;
  148.  
  149. --------------------------------------------------------------------------------
  150.  
  151. architecture Behavioural of FPGA is
  152.  
  153. signal R : std_logic;
  154. signal DRX : std_logic_vector(7 downto 0);
  155. signal DTX : std_logic_vector(7 downto 0);
  156. signal JEST : std_logic;
  157. signal INPUT : std_logic_vector(7 downto 0);
  158. signal READY : std_logic;
  159. signal MY_ERROR : std_logic;
  160. begin
  161.  
  162. --RS_TX <= RS_RX;
  163.  
  164. sd :entity work.SERIAL_RX
  165. generic map (
  166. F_ZEGARA => 20000000, -- czestotliwosc zegata w [Hz]
  167. L_BODOW => 9600, -- minimalna predkosc nadawania w [bodach]
  168. B_SLOWA => 8, -- liczba bitow slowa danych (5-8)
  169. B_STOPOW => 2, -- liczba bitow stopu (1-2)
  170. N_RX => TRUE, -- negacja logiczna sygnalu szeregowego
  171. N_SLOWO => TRUE -- negacja logiczna slowa danych
  172. )
  173. port map(
  174. R => R, -- sygnal resetowania
  175. C => CLK_I, -- zegar taktujacy
  176. RX => RS_RX, -- odebrany sygnal szeregowy
  177. SLOWO => INPUT,
  178. GOTOWE => READY
  179. );
  180.  
  181. process (READY, INPUT) is
  182. begin
  183. if (READY = '1') then
  184. LED_OUT <= INPUT;
  185. end if;
  186. end process;
  187.  
  188. end Behavioural;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement