Advertisement
oussama_ait_ahmad_23

VHDL Testbench code

Sep 14th, 2023
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 1.59 KB | Source Code | 0 0
  1. -- VHDL project: VHDL code for traffic light controller
  2. LIBRARY ieee;
  3. USE ieee.std_logic_1164.ALL;
  4. -- Testbench VHDL code for traffic light controller
  5. ENTITY tb_traffic_light_controller IS
  6. END tb_traffic_light_controller;
  7.  
  8. ARCHITECTURE behavior OF tb_traffic_light_controller IS
  9.     -- Component Declaration for the traffic light controller
  10.     COMPONENT traffic_light_controller
  11.     PORT(
  12.          sensor : IN  std_logic;
  13.          clk : IN  std_logic;
  14.          rst_n : IN  std_logic;
  15.          light_highway : OUT  std_logic_vector(2 downto 0);
  16.          light_farm : OUT  std_logic_vector(2 downto 0)
  17.         );
  18.     END COMPONENT;
  19.    signal sensor : std_logic := '0';
  20.    signal clk : std_logic := '0';
  21.    signal rst_n : std_logic := '0';
  22.   --Outputs
  23.    signal light_highway : std_logic_vector(2 downto 0);
  24.    signal light_farm : std_logic_vector(2 downto 0);
  25.    constant clk_period : time := 10 ns;
  26. BEGIN
  27.  -- Instantiate the traffic light controller
  28.    trafficlightcontroller : traffic_light_controller PORT MAP (
  29.           sensor => sensor,
  30.           clk => clk,
  31.           rst_n => rst_n,
  32.           light_highway => light_highway,
  33.           light_farm => light_farm
  34.         );
  35.    -- Clock process definitions
  36.    clk_process :process
  37.    begin
  38.   clk <= '0';
  39.   wait for clk_period/2;
  40.   clk <= '1';
  41.   wait for clk_period/2;
  42.    end process;
  43.    stim_proc: process
  44.    begin    
  45.   rst_n <= '0';
  46.   sensor <= '0';
  47.       wait for clk_period*10;
  48.   rst_n <= '1';
  49.   wait for clk_period*20;
  50.   sensor <= '1';
  51.   wait for clk_period*100;
  52.   sensor <= '0';
  53.       wait;
  54.    end process;
  55.  
  56. END;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement