Advertisement
Sarik_Kumpan

Control -งาน HiLv

Nov 22nd, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3. use ieee.std_logic_arith.all;
  4. use ieee.std_logic_unsigned.all;
  5. entity Control is
  6. port (
  7. CLK : in std_logic;
  8. req_i : in std_logic;
  9. rst_i : in std_logic; -- synchronous reset, active low
  10. mode_data : out std_logic_vector(1 downto 0);
  11. sleep : out std_logic:='0';
  12. DATA_IN : in std_logic_vector(7 downto 0));
  13. end Control;
  14.  
  15. architecture behave of Control is
  16. signal channel_tem : std_logic_vector(3 downto 0);
  17. constant TIME_SLEEP : integer := 150000000;
  18. type state_type is (
  19. check_start_bit,
  20. check_mode_bit);
  21. signal state : state_type := check_start_bit;
  22. signal count : integer := 0;
  23. begin
  24. process(CLK, req_i, rst_i)
  25. begin
  26. if rst_i = '0' then
  27. state <= check_start_bit;
  28. elsif rising_edge(CLK)then
  29.  
  30. if count > TIME_SLEEP then
  31. mode_data <= "00";
  32. sleep <= '1';
  33. count <= 0;
  34. end if;
  35.  
  36. case state is
  37. when check_start_bit =>
  38. count <= count + 1;
  39. if req_i = '0' and Data_IN = x"23" then
  40. sleep <= '0';
  41. count <= 0;
  42. state <= check_mode_bit;
  43. end if;
  44.  
  45. when check_mode_bit =>
  46.  
  47. if req_i = '0' then
  48. if DATA_IN = x"30" then -- 0 in Ascii
  49. mode_data <= "00";
  50. state <= check_start_bit;
  51.  
  52. elsif DATA_IN = x"31" then -- 1 in Ascii
  53. mode_data <= "01";
  54. state <= check_start_bit;
  55.  
  56. elsif DATA_IN = x"32" then -- 2 in Ascii
  57. mode_data <= "10";
  58. state <= check_start_bit;
  59.  
  60. elsif DATA_IN = x"33" then -- 3 in Ascii
  61. mode_data <= "11";
  62. state <= check_start_bit;
  63. end if;
  64. end if;
  65.  
  66. end case;
  67. end if;
  68. end process;
  69. end behave;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement