You are on page 1of 1

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

Verilog code for counter with testbench


In this project, Verilog code for counters with testbench will be presented including up counter, Join 15,000+ Followers
down counter, up-down counter, and random counter.

FPGA4student

YouTube 564

Subscribe to get upcoming


FPGA projects by email
Enter your email address... Submit

Popular FPGA projects

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
Verilog code for up counter: image (.bmp) in Verilog...

// FPGA projects using Verilog/ VHDL [FPGA Tutorial] Seven-


Segment LED Display on
// fpga4student.com: FPGA projects, Verilog projects, VHDL projects Basys 3 FPGA
// Verilog code for up counter This FPGA tutorial will
module up_counter(input clk, reset, output[3:0] counter guide you how to control
the 4-digit seven-segment display on
); Basys 3 FPGA Board. A display
reg [3:0] counter_up; controller will be ...

VHDL code for Seven-


// up counter Segment Display on Basys
always @(posedge clk or posedge reset) 3 FPGA
Last time , I wrote a full
begin FPGA tutorial on how to
if(reset) control the 4-digit 7-segment display on
counter_up <= 4'd0; Basys 3 FPGA. A full Verilog code for
displayi...
else
counter_up <= counter_up + 4'd1; Verilog code for counter
end with testbench
In this project, Verilog code
assign counter = counter_up; for counters with testbench
endmodule will be presented including
up counter, down counter, up-down
Verilog testbench code for up counter: counter, and r...

Verilog code for Arithmetic


// FPGA projects using Verilog/ VHDL Logic Unit (ALU)
// fpga4student.com: FPGA projects, Verilog projects, VHDL projects Last time , an Arithmetic
// Verilog code for up counter with testbench Logic Unit ( ALU ) is
// Testbench Verilog code for up counter designed and implemented
in VHDL . Full VHDL code for the ALU
module upcounter_testbench(); was presented. Today, f...
reg clk, reset;
wire [3:0] counter; Verilog code for D Flip Flop
D Flip-Flop is a
up_counter dut(clk, reset, counter); fundamental component in
digital logic circuits. Verilog
initial begin code for D Flip Flop is
clk=0; presented in this project. There are tw...
forever #5 clk=~clk;
end Verilog code for 16-bit
initial begin single cycle MIPS
processor
reset=1;
In this project, a 16-bit
#20; single-cycle MIPS
reset=0; processor is implemented in Verilog
end HDL. MIPS is an RISC processor ,
endmodule which is widely used by ...

Simulation waveform for up counter:

Verilog code for down counter:


// FPGA projects using Verilog/ VHDL
// fpga4student.com: FPGA projects, Verilog projects, VHDL projects
// Verilog code for down counter
module down_counter(input clk, reset, output [3:0] counter
);
reg [3:0] counter_down;

// down counter
always @(posedge clk or posedge reset)
begin
if(reset)
counter_down <= 4'hf;
else
counter_down <= counter_down - 4'd1;
end
assign counter = counter_down;
endmodule

Verilog testbench code for down counter:


// FPGA projects using Verilog/ VHDL
// fpga4student.com: FPGA projects, Verilog projects, VHDL projects
// Verilog code for down counter with testbench
// Testbench Verilog code for down counter
module downcounter_testbench();
reg clk, reset;
wire [3:0] counter;

down_counter dut(clk, reset, counter);


initial begin
clk=0;
forever #5 clk=~clk;
end
initial begin
reset=1;
#20;
reset=0;
end
endmodule

Simulation waveform for down counter:

Verilog code for up-down counter:


// FPGA projects using Verilog/ VHDL
// fpga4student.com: FPGA projects, Verilog projects, VHDL projects
// Verilog code for up-down counter
module up_down_counter(input clk, reset,up_down, output[3:0] counter
);
reg [3:0] counter_up_down;

// down counter
always @(posedge clk or posedge reset)
begin
if(reset)
counter_up_down <= 4'h0;
else if(~up_down)
counter_up_down <= counter_up_down + 4'd1;
else
counter_up_down <= counter_up_down - 4'd1;
end
assign counter = counter_up_down;
endmodule
Verilog testbench code for up-down counter:
// FPGA projects using Verilog/ VHDL
// fpga4student.com: FPGA projects, Verilog projects, VHDL projects
// Verilog code for up-down counter with testbench
// Testbench Verilog code for up-down counter
module updowncounter_testbench();
reg clk, reset,up_down;
wire [3:0] counter;

up_down_counter dut(clk, reset,up_down, counter);


initial begin
clk=0;
forever #5 clk=~clk;
end
initial begin
reset=1;
up_down=0;
#20;
reset=0;
#200;
up_down=1;
end
endmodule

Simulation waveform for up-down counter:

Verilog code for random counter using LFSR:


// FPGA projects using Verilog/ VHDL
// fpga4student.com: FPGA projects, Verilog projects, VHDL projects
// Verilog code for random counter using linear shift feedback register
module random_counter_lfsr(input clk, rst_n,
input[4:0] initialized_value,
output[4:0] counter_random);
wire [4:0] counter_lfsr;
wire d_xor;
xor xor_u(d_xor,counter_lfsr[1],counter_lfsr[4]);
D_FF u0(.q(counter_lfsr[0]), .d(counter_lfsr[4]), .rst_n(rst_n), .clk(clk),.init_
D_FF u1(.q(counter_lfsr[1]), .d(counter_lfsr[0]), .rst_n(rst_n), .clk(clk),.init_
D_FF u2(.q(counter_lfsr[2]), .d(d_xor), .rst_n(rst_n), .clk(clk),.init_value(init
D_FF u3(.q(counter_lfsr[3]), .d(counter_lfsr[2]), .rst_n(rst_n), .clk(clk),.init_
D_FF u4(.q(counter_lfsr[4]), .d(counter_lfsr[3]), .rst_n(rst_n), .clk(clk),.init_
assign counter_random = counter_lfsr;
endmodule
// FPGA projects using Verilog/ VHDL
// fpga4student.com: FPGA projects, Verilog projects, VHDL projects
// Verilog code for random counter using linear shift feedback register
// Verilog code for D_FF using in random counter
module D_FF (q, d, rst_n, clk,init_value);
output q;
input d, rst_n, clk,init_value;
reg q;
always @(posedge clk or negedge rst_n)
if (~rst_n)
q <= init_value;
else
q <= d;
endmodule

Verilog testbench code for random counter using LFSR:


// FPGA projects using Verilog/ VHDL
// fpga4student.com: FPGA projects, Verilog projects, VHDL projects
// Verilog code for random counter with testbench
// Testbench Verilog code for random counter
module randomcounter_testbench();
reg clk, reset;
reg [4:0] initialized_value;
wire [4:0] counter_random;

random_counter_lfsr dut( clk, reset,


initialized_value,
counter_random);
initial begin
clk=0;
forever #5 clk=~clk;
end
initial begin
reset=0;
initialized_value=5'b11111;
#20;
reset=1;
end
endmodule

Simulation waveform for random counter:

Recommended Verilog projects:


1. What is an FPGA? How Verilog works on FPGA
2. Verilog code for FIFO memory
3. Verilog code for 16-bit single-cycle MIPS processor
4. Programmable Digital Delay Timer in Verilog HDL
5. Verilog code for basic logic components in digital circuits
6. Verilog code for 32-bit Unsigned Divider
7. Verilog code for Fixed-Point Matrix Multiplication
8. Plate License Recognition in Verilog HDL
9. Verilog code for Carry-Look-Ahead Multiplier
10. Verilog code for a Microcontroller
11. Verilog code for 4x4 Multiplier
12. Verilog code for Car Parking System
13. Image processing on FPGA using Verilog HDL
14. How to load a text file into FPGA using Verilog HDL
15. Verilog code for Traffic Light Controller
16. Verilog code for Alarm Clock on FPGA
17. Verilog code for comparator design
18. Verilog code for D Flip Flop
19. Verilog code for Full Adder
20. Verilog code for counter with testbench
21. Verilog code for 16-bit RISC Processor
22. Verilog code for button debouncing on FPGA
23. How to write Verilog Testbench for bidirectional/ inout ports
24. Tic Tac Toe Game in Verilog and LogiSim
25. 32-bit 5-stage Pipelined MIPS Processor in Verilog (Part-1)
26. 32-bit 5-stage Pipelined MIPS Processor in Verilog (Part-2)
27. 32-bit 5-stage Pipelined MIPS Processor in Verilog (Part-3)
28. Verilog code for Decoder
29. Verilog code for Multiplexers
30. N-bit Adder Design in Verilog
31. Verilog vs VHDL: Explain by Examples
32. Verilog code for Clock divider on FPGA
33. How to generate a clock enable signal in Verilog
34. Verilog code for PWM Generator
35. Verilog coding vs Software Programming
36. Verilog code for Moore FSM Sequence Detector

37. Verilog code for 7-segment display controller on Basys 3 FPGA

53
SHARES
Facebook Twitter Pinterest

No comments:

Post a Comment

Enter your comment...

Comment as: Geeky Maniac Sign out

Publish Preview Notify me

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

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 Full Adder


In this Verilog project , Verilog code for Full Adder is presented. Both behavioral and structural Verilog code for Full Adder
is implem...

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

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

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

What is FPGA Programming?


Last time , I presented in detail what exactly an FPGA is and the advantage of FPGAs over ASICs and microcontrollers.
FPGAs are nothing,...

Verilog Code for Ripple Carry Adder


A Verilog code for a 4-bit Ripple-Carry Adder is provided in this project. The 4-bit ripple-carry adder is built using 4 1-bit
full adde...

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

VHDL code for Arithmetic Logic Unit (ALU)


Arithmetic Logic Unit ( ALU ) is one of the most important digital logic components in CPUs. It normally executes logic
and arithmetic op...

Subscribe to More Upcoming FPGA/Verilog/VHDL Projects

Email your email address... Submit

Privacy Policy | Disclaimer | Sitemap | Contact | Support Us


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

You might also like