VHDL Code For Counters With Testbench
VHDL Code For Counters With Testbench
VHDL Code For Counters With Testbench
Home FPGA Projects Verilog Projects VHDL Projects FPGA Tutorial Verilog vs VHDL About Search
component UP_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
1 of 6 1/16/2024, 2:21 PM
VHDL code for counters with testbench - FPGA4student.com https://www.fpga4student.com/2017/06/vhdl-code-for-counters-with-tes...
);
end component;
signal reset,clk: std_logic;
signal counter:std_logic_vector(3 downto 0);
begin
dut: UP_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;
Simulation waveform:
end Behavioral;
Testbench VHDL code for the down counter:
2 of 6 1/16/2024, 2:21 PM
VHDL code for counters with testbench - FPGA4student.com https://www.fpga4student.com/2017/06/vhdl-code-for-counters-with-tes...
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
-- FPGA projects using Verilog code VHDL code
-- fpga4student.com: FPGA projects, Verilog projects, VHDL projects
-- VHDL project: VHDL code for counters with testbench
-- VHDL project: Testbench VHDL code for down counter
entity tb_counters is
end tb_counters;
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;
Simulation waveform:
3 of 6 1/16/2024, 2:21 PM
VHDL code for counters with testbench - FPGA4student.com https://www.fpga4student.com/2017/06/vhdl-code-for-counters-with-tes...
begin
if(rising_edge(clk)) then
if(reset='1') then
counter_updown <= x"0";
elsif(up_down='1') then
counter_updown <= counter_updown - x"1"; -- count down
else
counter_updown <= counter_updown + x"1"; -- count up
end if;
end if;
end process;
counter <= counter_updown;
end Behavioral;
Testbench VHDL code for the up-down counter:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
-- FPGA projects using Verilog code VHDL code
-- fpga4student.com: FPGA projects, Verilog projects, VHDL projects
-- VHDL project: VHDL code for counters with testbench
-- VHDL project: Testbench VHDL code for up-down counter
entity tb_counters is
end tb_counters;
component UPDOWN_COUNTER
Port ( clk: in std_logic; -- clock input
reset: in std_logic; -- reset input
up_down: in std_logic;
counter: out std_logic_vector(3 downto 0) -- output 4-bit counter
);
end component;
signal reset,clk,up_down: std_logic;
signal counter:std_logic_vector(3 downto 0);
begin
dut: UPDOWN_COUNTER port map (clk => clk, reset=>reset, up_down => up_down, 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';
up_down <= '0';
wait for 20 ns;
reset <= '0';
wait for 300 ns;
up_down <= '1';
wait;
end process;
end Behavioral;
Simulation waveform:
4 of 6 1/16/2024, 2:21 PM
VHDL code for counters with testbench - FPGA4student.com https://www.fpga4student.com/2017/06/vhdl-code-for-counters-with-tes...
1 comment:
5 of 6 1/16/2024, 2:21 PM
VHDL code for counters with testbench - FPGA4student.com https://www.fpga4student.com/2017/06/vhdl-code-for-counters-with-tes...
6 of 6 1/16/2024, 2:21 PM