Design Code For Counter
Design Code For Counter
Design Code For Counter
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.numeric_std.all;
entity design is
generic(
port(
end design;
begin
process(clk, reset)
begin
end if;
cnt <= d;
end if;
end if;
q <= cnt;
end process;
end rtl;
Testbench counter:
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.numeric_std.all;
entity testbench is
generic(
constant WIDTH : integer := 4);
end testbench;
begin
UUT: design
generic map(
WIDTH => WIDTH)
port map(
clk => clk,
reset => reset,
preset => preset,
direction => direction,
d => d,
q => q);
generate_clk : process
begin
while done = false loop
clk <= not clk;
wait for 50 ns;
end loop;
wait;
end process;
process
begin
-- CASE 0: INITIALIZE
d <= "1111";
reset <= '1';
preset <= '1';
direction <= '1';
-- CASE 1: RESET
d <= "XXXX";
reset <= '0';
preset <= 'X';
direction <= '1';
d <= "XXXX";
reset <= '0';
preset <= 'X';
direction <= '0';
d <= "0000";
reset <= '1';
preset <= '0';
direction <= '0'; -- COUNTING UP
wait for 100 ns;
done := true;
wait;
end process;
end behave;