0% found this document useful (0 votes)
179 views6 pages

VHDL Code For Counters With Testbench

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 6

VHDL code for counters with testbench - FPGA4student.com https://www.fpga4student.com/2017/06/vhdl-code-for-counters-with-tes...

Home FPGA Projects Verilog Projects VHDL Projects FPGA Tutorial Verilog vs VHDL About Search

VHDL code for counters with testbench


Last time, several 4-bit counters including up counter, down counter and up-down Join 18,000+ Followers
counter are implemented in Verilog. Verilog code for the counters is presented.
In this VHDL project, the counters are implemented in VHDL. The testbench VHDL code for the
FPGA4STUDENT
counters is also presented together with the simulation waveform.
YouTube 1K

Popular FPGA projects

Verilog code for D Flip Flop


D Flip-Flop is a
fundamental component in
digital logic circuits. Verilog
code for D Flip Flop is
presented in this project. There are t...

Verilog code for Arithmetic


Logic Unit (ALU)
VHDL code for up counter: Last time , an Arithmetic
Logic Unit ( ALU ) is
library IEEE; designed and implemented
use IEEE.STD_LOGIC_1164.ALL; in VHDL . Full VHDL code for the ALU
was presented. Today, f...
use IEEE.STD_LOGIC_UNSIGNED.ALL;
-- FPGA projects using Verilog code VHDL code [FPGA Tutorial] Seven-
-- fpga4student.com: FPGA projects, Verilog projects, VHDL projects Segment LED Display on
Basys 3 FPGA
-- VHDL project: VHDL code for counters with testbench This FPGA tutorial will
-- VHDL project: VHDL code for up counter guide you how to control
entity UP_COUNTER is the 4-digit seven-segment display on
Basys 3 FPGA Board. A display
Port ( clk: in std_logic; -- clock input controller will be ...
reset: in std_logic; -- reset input
counter: out std_logic_vector(3 downto 0) -- output 4-bit counter Verilog code for counter
with testbench
); In this project, Verilog code
end UP_COUNTER; for counters with testbench
will be presented including
up counter, down counter, up-down
architecture Behavioral of UP_COUNTER is counter, and r...
signal counter_up: std_logic_vector(3 downto 0);
begin Image processing on
FPGA using Verilog HDL
-- up counter
This FPGA project is
process(clk) aimed to show in details
begin how to process an image
using Verilog from reading an input
if(rising_edge(clk)) then bitmap image (.bmp) in Verilog...
if(reset='1') then
counter_up <= x"0"; VHDL code for Seven-
Segment Display on Basys
else 3 FPGA
counter_up <= counter_up + x"1"; Last time , I wrote a full
end if; FPGA tutorial on how to
control the 4-digit 7-segment display on
end if;
Basys 3 FPGA. A full Verilog code for
end process; displayi...
counter <= counter_up;
VHDL code for Arithmetic
Logic Unit (ALU)
end Behavioral; Arithmetic Logic Unit ( ALU
Testbench VHDL code for the up-counter: ) is one of the most
important digital logic
library IEEE; components in CPUs. It normally
executes logic and arithmetic op...
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 counter
entity tb_counters is
end tb_counters;

architecture Behavioral of tb_counters is

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:

VHDL code for down counter:


library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_UNSIGNED.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: VHDL code for down counter
entity DOWN_COUNTER is
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 DOWN_COUNTER;

architecture Behavioral of DOWN_COUNTER is


signal counter_down: std_logic_vector(3 downto 0);
begin
-- down counter
process(clk)
begin
if(rising_edge(clk)) then
if(reset='1') then
counter_down <= x"F";
else
counter_down <= counter_down - x"1";
end if;
end if;
end process;
counter <= counter_down;

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;

architecture Behavioral of tb_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;
Simulation waveform:

VHDL code for the up-down counter:


library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_UNSIGNED.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: VHDL code for up-down counter
entity UPDOWN_COUNTER is
Port ( clk: in std_logic; -- clock input
reset: in std_logic; -- reset input
up_down: in std_logic; -- up or down
counter: out std_logic_vector(3 downto 0) -- output 4-bit counter
);
end UPDOWN_COUNTER;

architecture Behavioral of UPDOWN_COUNTER is


signal counter_updown: std_logic_vector(3 downto 0);
begin
-- down counter
process(clk)

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;

architecture Behavioral of tb_counters is

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:

Recommended VHDL projects:


1. What is an FPGA? How VHDL works on FPGA
2. VHDL code for FIFO memory

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...

3. VHDL code for FIR Filter


4. VHDL code for 8-bit Microcontroller
5. VHDL code for Matrix Multiplication
6. VHDL code for Switch Tail Ring Counter
7. VHDL code for digital alarm clock on FPGA
8. VHDL code for 8-bit Comparator
9. How to load a text file into FPGA using VHDL
10. VHDL code for D Flip Flop
11. VHDL code for Full Adder
12. PWM Generator in VHDL with Variable Duty Cycle
13. VHDL code for ALU
14. VHDL code for counters with testbench
15. VHDL code for 16-bit ALU
16. Shifter Design in VHDL
17. Non-linear Lookup Table Implementation in VHDL
18. Cryptographic Coprocessor Design in VHDL
19. Verilog vs VHDL: Explain by Examples
20. VHDL Code for Clock Divider on FPGA
21. How to generate a clock enable signal instead of creating another clock domain
22. VHDL code for debouncing buttons on FPGA
23. VHDL code for Traffic light controller
24. VHDL code for a simple 2-bit comparator
25. VHDL code for a single-port RAM
22. VHDL code for debouncing buttons on FPGA
23. VHDL code for Traffic light controller
24. VHDL code for a simple 2-bit comparator
25. VHDL code for a single-port RAM
26. VHDL code for Car Parking System using FSM
27. VHDL coding vs Software Programming
28. VHDL code for MIPS Processor
29. VHDL code for Moore FSM Sequence Detector
30. VHDL code for Seven-Segment Display on Basys 3 FPGA

1 comment:

Unknown February 15, 2020 at 2:32 AM


VHDL CODE for 2- bit counter
Reply

To leave a comment, click the button below to sign in with Google.

SIGN IN WITH GOOGLE

Newer Post Home Older Post

Trending FPGA Projects

Verilog code for D Flip Flop


D Flip-Flop is a fundamental component in digital logic circuits. Verilog code for D Flip Flop is presented in this project.
There are t...

Verilog code for Arithmetic Logic Unit (ALU)


Last time , an Arithmetic Logic Unit ( ALU ) is designed and implemented in VHDL . Full VHDL code for the ALU was
presented. Today, f...

Verilog Code for 16-bit RISC Processor


In this V erilog project , Verilog code for a 16-bit RISC processor is presented. The RISC processor is designed based
on its instructi...

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...

Verilog code for counter with testbench


In this project, Verilog code for counters with testbench will be presented including up counter, down counter, up-down
counter, and r...

Verilog code for FIFO memory


In this project, Verilog code for FIFO memory is presented. The First-In-First-Out ( FIFO ) memory with the following
specification is imp...

Image processing on FPGA using Verilog HDL


This FPGA project is aimed to show in details how to process an image using Verilog from reading an input bitmap image
(.bmp) in Verilog...

[FPGA Tutorial] Seven-Segment LED Display on Basys 3 FPGA


This FPGA tutorial will guide you how to control the 4-digit seven-segment display on Basys 3 FPGA Board. A display
controller will be ...

Verilog code for 16-bit single cycle MIPS processor


In this project, a 16-bit single-cycle MIPS processor is implemented in Verilog HDL. MIPS is an RISC processor , which is
widely used by ...

Full Verilog code for Moore FSM Sequence Detector


This Verilog project is to present a full Verilog code for Sequence Detector using Moore FSM . A Verilog Testbench for
the Moore FSM sequ...

VHDL code for Seven-Segment Display on Basys 3 FPGA


Last time , I wrote a full FPGA tutorial on how to control the 4-digit 7-segment display on Basys 3 FPGA. A full Verilog
code for displayi...

Privacy Policy | Disclaimer | Sitemap | Contact | Advertise Here


Copyright © 2016-2020 FPGA4student.com All Rights Reserved.

6 of 6 1/16/2024, 2:21 PM

You might also like