October 1, 2023

Down Counter

 down_counter.vhd

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity down_counter is
Port ( clk: in std_logic;
reset: in std_logic;
counter: out std_logic_vector(3 downto 0)
);
end down_counter;

architecture Behavioral of down_counter is
signal count: std_logic_vector(3 downto 0);
begin
process(clk)
begin
if(rising_edge(clk)) then
if(reset=’1') then
count <= x”F”;
else
count <= count — x”1";
end if;
end if;
end process;
counter <= count;

end Behavioral;

tb_down_counter.vhd

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity tb_down_counters is
end tb_down_counters;

architecture Behavioral of tb_down_counters is

component down_counter
Port ( clk: in std_logic; — clock input
reset: in std_logic; — reset input
counter: out std_logic_vector(3 downto 0) — output 4-bit counter
);
end component;
signal reset,clk: std_logic;
signal counter:std_logic_vector(3 downto 0);

begin
dut: down_counter port map (clk => clk, reset=>reset, counter => counter);
— Clock process definitions
clock_process :process
begin
clk <= ‘0’;
wait for 10 ns;
clk <= ‘1’;
wait for 10 ns;
end process;

— Stimulus process
stim_proc: process
begin
— hold reset state for 100 ns.
reset <= ‘1’;
wait for 20 ns;
reset <= ‘0’;
wait;
end process;
end Behavioral;


No comments:

Post a Comment

Explore Our Topics!

Check out the extensive list of topics we discuss:  Communication Protocols: -  USB   - RS232   -  Ethernet   -  AMBA Protocol: APB, AHB and...