Advertisement
Guest User

Untitled

a guest
Nov 14th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.95 KB | None | 0 0
  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3. use ieee.numeric_std.all;
  4.  
  5. entity sender_AL 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 sender_AL;
  15.  
  16. architecture RTL of sender_AL is
  17.  
  18. signal hallo_enable : std_logic;
  19. signal hallo : std_logic;
  20. signal resetn : std_logic;
  21. signal sender : std_logic;
  22. signal mottat_blink : std_logic;
  23. signal vippe_a, vippe_b : std_logic;
  24.  
  25. signal start_teller, baud_enable_m, baud_enable_s : std_logic;
  26.  
  27. type sender_state_type is (s_idle, s_transmit, s_shift_out, s_finish, s_wait);
  28. signal sender_state : sender_state_type;
  29.  
  30. signal send_shift_register : std_logic_vector(9 downto 0);
  31.  
  32. constant START_BIT : std_logic := '0';
  33. constant STOPP_BIT : std_logic := '1';
  34.  
  35. signal data_inn, data_ut : std_logic;
  36. signal start_sender, start_q, start_qq : std_logic;
  37.  
  38. type mottak_state_type is (s_idle, s_wait_for_sender, s_shift_in, s_offload, s_error);
  39. signal mottak_state : mottak_state_type;
  40.  
  41. signal data_inn_q, data_inn_qq, data_inn_qqq : std_logic;
  42. signal error : std_logic;
  43. signal mottak_shift_reg : std_logic_vector(9 downto 0);
  44. signal motatt_data : std_logic_vector(7 downto 0);
  45.  
  46.  
  47. component Enable_gen Is
  48. Port ( clock_50 : in std_logic;
  49. resetn : in std_logic;
  50. velg_enable:in std_logic_vector(2 downto 0);
  51. Enable: out std_logic);
  52. End component;
  53.  
  54.  
  55. component reset_sync is
  56. port(
  57. clk, reset_key3 : in std_logic;
  58. reset_clk : out std_logic
  59.  
  60. );
  61. end component reset_sync;
  62.  
  63. component baudrate_gen is
  64. port(
  65. CLOCK_50 : in std_logic;
  66. resetn : in std_logic;
  67. velg_baudrate : in std_logic_vector(2 downto 0);
  68.  
  69. start_teller : in std_logic;
  70. baud_enable_m : out std_logic;
  71. baud_enable_s : out std_logic
  72.  
  73. );
  74. end component baudrate_gen;
  75.  
  76. begin
  77.  
  78. Enable_gen_inst : component Enable_gen
  79. port map(
  80. clock_50 => CLOCK_50,
  81. resetn => resetn,
  82. velg_enable => "111",
  83. Enable => hallo_enable
  84.  
  85. );
  86.  
  87. reser_syn_inst : component reset_sync
  88. port map(
  89. clk => CLOCK_50,
  90. reset_key3 => KEY(3),
  91. reset_clk => resetn
  92. );
  93.  
  94. -- lag lokalt blinkesignal
  95. p_hallo : process (CLOCK_50) is
  96. begin
  97. if rising_edge(CLOCK_50) then
  98. if resetn = '0' then
  99. hallo <= '0';
  100. elsif hallo_enable = '1' then
  101. hallo <= not hallo;
  102. end if;
  103. end if;
  104. end process p_hallo;
  105.  
  106. LEDR(17) <= hallo;
  107.  
  108. sender <= SW(17);
  109. LEDG(0) <= sender;
  110. LEDG(7) <= mottat_blink;
  111.  
  112.  
  113. p_send_motta_hallo : process (CLOCK_50) is
  114. begin
  115. if rising_edge(CLOCK_50) then
  116. if sender = '1' then
  117. GPIO(1) <= hallo;
  118. mottat_blink <= '0';
  119. else
  120. -- mottar hallo
  121. GPIO(1) <= 'Z';
  122. vippe_a <= GPIO(1);
  123. vippe_b <= vippe_a;
  124. mottat_blink <= vippe_b;
  125. end if;
  126. end if;
  127. end process;
  128.  
  129. baudrate_gen_inst : component baudrate_gen
  130. port map(
  131. CLOCK_50 => CLOCK_50,
  132. resetn => resetn,
  133. velg_baudrate => SW(16 downto 14),
  134. start_teller => start_teller,
  135. baud_enable_m => baud_enable_m,
  136. baud_enable_s => baud_enable_s
  137. );
  138.  
  139. data_inn <= GPIO(7) when sender = '0' else '1';
  140. GPIO(7) <= data_ut when sender = '1' else 'Z';
  141.  
  142. p_start_teller : process(CLOCK_50) is --data inn
  143. begin
  144. if rising_edge(CLOCK_50) then
  145. if resetn = '0' then
  146. start_teller <= '0';
  147. data_inn_q <= '0';
  148. data_inn_qq <= '0';
  149. data_inn_qqq <= '0';
  150.  
  151. else
  152. start_teller <= '0';
  153. data_inn_q <= data_inn;
  154. data_inn_qq <= data_inn_q;
  155. data_inn_qqq <= data_inn_qq;
  156. if data_inn_qqq = '1' and data_inn_qq = '0' then
  157. --fallende flanke
  158. if mottak_state = s_wait_for_sender then
  159. start_teller <= '1';
  160. end if;
  161. end if;
  162. end if;
  163. end if;
  164. end process p_start_teller;
  165.  
  166.  
  167. start_sender <= KEY(0);
  168.  
  169. p_synk_start_sender : process(CLOCK_50) is
  170. begin
  171. if rising_edge(CLOCK_50) then
  172. if resetn = '0' then
  173. start_q <= '0';
  174. start_qq <= '0';
  175. else
  176. start_q <= not start_sender;
  177. start_qq <= start_sender;
  178. end if;
  179. end if;
  180. end process p_synk_start_sender;
  181.  
  182.  
  183. p_sender_tilstandsmaskin : process(CLOCK_50) is
  184. begin
  185. if rising_edge(CLOCK_50) then
  186. if resetn = '0' then
  187. sender_state <= s_idle;
  188. else
  189.  
  190. if baud_enable_s = '1' and sender = '1' then
  191. case sender_state is
  192. when s_idle =>
  193. data_ut <= '1';
  194. send_shift_register <= (others => '0');
  195. if start_qq = '1' then
  196. sender_state <= s_transmit;
  197. end if;
  198.  
  199. when s_transmit =>
  200. data_ut <= '1';
  201. send_shift_register <= STOPP_BIT & SW(8 downto 1) & START_BIT;
  202. if baud_enable_s = '1' then
  203. sender_state <= s_shift_out;
  204. end if;
  205.  
  206. when s_shift_out =>
  207. if baud_enable_s = '1' then
  208. if send_shift_register = "0000000000" then
  209. sender_state <= s_finish;
  210. data_ut <= '1';
  211. else
  212. data_ut <= send_shift_register(0);
  213. send_shift_register <= '0' & send_shift_register(9 downto 1);
  214.  
  215. end if;
  216. end if;
  217. when s_finish =>
  218. data_ut <= '1';
  219. if baud_enable_s = '1' then
  220. sender_state <= s_wait;
  221. end if;
  222.  
  223. when s_wait =>
  224. data_ut <= '1';
  225. if baud_enable_s = '1' then
  226. sender_state <= s_transmit;
  227. end if;
  228. end case;
  229. end if;
  230. end if;
  231. end if;
  232. end process;
  233.  
  234.  
  235. p_mottak_tilstandsmaskin : process(CLOCK_50) is
  236. begin
  237. if rising_edge(CLOCK_50) then
  238. if resetn = '0' then
  239. motatt_data <= "00000000";
  240. mottak_state <= s_idle;
  241. error <= '0';
  242. else
  243. if sender = '0' then
  244. case mottak_state is
  245.  
  246. when s_idle =>
  247. error <= '0';
  248. mottak_shift_reg <= "1000000000";
  249. if data_inn_qq = '1' then
  250. mottak_state <= s_wait_for_sender;
  251. end if;
  252.  
  253. when s_wait_for_sender =>
  254. if start_teller = '1' then
  255. mottak_state <= s_shift_in;
  256. end if;
  257.  
  258. when s_shift_in =>
  259. if mottak_shift_reg(0) = '1' and mottak_shift_reg(9) = '0' then
  260. -- dette skal aldri skje
  261. mottak_state <= s_error;
  262. elsif mottak_shift_reg(0) = '1' and mottak_shift_reg(9) = '1' then
  263. -- mottat alle databit of stoppbit
  264. mottak_state <= s_offload;
  265. elsif baud_enable_m = '1' then
  266. mottak_shift_reg <= data_inn_qq & mottak_shift_reg(9 downto 1);
  267. end if;
  268.  
  269. when s_offload =>
  270. motatt_data <= mottak_shift_reg(8 downto 1);
  271. mottak_state <= s_idle;
  272.  
  273. when s_error =>
  274. error <= '1';
  275. end case;
  276. end if;
  277. end if;
  278. end if;
  279. end process p_mottak_tilstandsmaskin;
  280.  
  281. LEDR(16) <= error;
  282. LEDR(8 downto 1) <= motatt_data;
  283.  
  284.  
  285. end architecture RTL;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement