Advertisement
Guest User

Untitled

a guest
Mar 29th, 2020
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. LIBRARY IEEE;
  2. USE IEEE.std_logic_1164.ALL;
  3.  
  4. ENTITY controller_tb IS
  5. END ENTITY controller_tb;
  6.  
  7. ARCHITECTURE structural OF controllertb IS
  8. COMPONENT timebase IS
  9. PORT (
  10. clk : IN std_logic;
  11. reset : IN std_logic;
  12.  
  13. count_out : OUT std_logic_vector (19 DOWNTO 0)
  14. );
  15. END COMPONENT timebase;
  16.  
  17. COMPONENT controller IS
  18. PORT (
  19. clk : IN std_logic;
  20. reset : IN std_logic;
  21.  
  22. count_in : IN std_logic_vector (19 DOWNTO 0);
  23.  
  24. sensor_l : IN std_logic;
  25. sensor_m : IN std_logic;
  26. sensor_r : IN std_logic;
  27.  
  28. motor_l_direction : OUT std_logic; -- '0' == ccw; '1' == cw
  29. motor_r_direction : OUT std_logic; -- '0' == ccw; '1' == cw
  30.  
  31. count_reset : OUT std_logic;
  32. motor_l_reset : OUT std_logic;
  33. motor_r_reset : OUT std_logic
  34. );
  35. END COMPONENT controller;
  36.  
  37. SIGNAL clk, reset : std_logic;
  38. SIGNAL sensor_l, sensor_m, sensor_r : std_logic;
  39. SIGNAL sensors : std_logic_vector(2 DOWNTO 0);
  40. SIGNAL motor_l_direction, motor_r_direction, count_reset, motor_l_reset, motor_r_reset : std_logic;
  41.  
  42. BEGIN
  43. lbl0 : timebase PORT MAP(
  44. clk => clk,
  45. reset => reset,
  46. count_out => count
  47. );
  48.  
  49. lbl1 : controller PORT MAP(
  50. clk => clk,
  51. reset => reset,
  52. sensor_l_in => sensor_l,
  53. sensor_m_in => sensor_m,
  54. sensor_r_in => sensor_r,
  55. motor_l_direction => motor_l_direction,
  56. motor_r_direction => motor_r_direction,
  57. count_reset => count_reset,
  58. motor_l_reset => motor_l_reset,
  59. motor_r_reset => motor_r_reset,
  60. count_in => count
  61. );
  62.  
  63. -- 20 ns = 50 MHz
  64. clk <= '0' AFTER 0 ns,
  65. '1' AFTER 10 ns WHEN clk /= '1' ELSE
  66. '0' AFTER 10 ns;
  67.  
  68. reset <= '1' AFTER 0 ns,
  69. '0' AFTER 40 ms;
  70.  
  71. sensors <= "000" AFTER 0 ns, -- bbb
  72. "001" AFTER 80 ms, -- bbw
  73. "010" AFTER 120 ms, -- bwb
  74. "011" AFTER 160 ms, -- bww
  75. "100" AFTER 200 ms, -- wbb
  76. "101" AFTER 240 ms, -- wbw
  77. "110" AFTER 280 ms, -- wwb
  78. "111" AFTER 320 ms; -- www
  79.  
  80. sensor_l <= sensors(2);
  81. sensor_m <= sensors(1);
  82. sensor_r <= sensors(0);
  83.  
  84. END ARCHITECTURE structural;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement