This website uses cookies. By using this site, you consent to the use of cookies. For more information, please take a look at our Privacy Policy.
Home > FPGA Technical Tutorials > Design Recipes for FPGAs Using Verilog and VHDL > Counters > Simple Binary Counter using Verilog

TABLE OF CONTENTS

Xilinx FPGA FPGA Forum

Simple Binary Counter using Verilog

FONT SIZE : AAA

With the same basic specification as the VHDL counter, it is possible to implement a basic counter in Verilog using the same architecture of the model.

1 module counter (

2 clk, / clock input

3 rst, / reset (active low)

4 counter_output / counter output

5 );

6

7 input clk;

8 input rst;

9

10 output [3:0] counter_output;

11

12 wire clk;

13 wire rst;

14

15 reg [3:0] counter_output ;

16

17 always @ (posedge clk)

18 begin : count

19 if (rst == 1’b0) begin

20 counter_output <= #1 4’b0000;

21 end

22 else begin

23 counter_output <= #1 counter_output + 1;

24 end

25 end

26

27 endmodule

The model has the same connection points and operation, and will be treated in the same way for synthesis by the design software. The test bench is slightly different from the VHDL one in that it is much more explicit about the test function as well as the functionality of the test bench. For example, if we look at the top of the test bench Verilog has the $display and $monitor commands, which enable the time and variable values to be displayed in the monitor of the simulation as well as looking at the waveforms. 

1 $display ("time\t clk reset counter");

2 $monitor ("%g\t %b %b %b",

3 $time, clk, rst, counter_output);

Using this test bench and Verilog model the behavior of the simulation can also be verified as shown in Figure 24.3.

  • XC3090-100PQ160C

    Manufacturer:Xilinx

  • FPGA XC3000 Family 6K Gates 320 Cells 100MHz 5V 160-Pin PQFP
  • Product Categories: FPGAs

    Lifecycle:Obsolete -

    RoHS: No RoHS

  • XC2V2000-4BFG957I

    Manufacturer:Xilinx

  • FPGA Virtex-II Family 2M Gates 24192 Cells 650MHz 0.15um Technology 1.5V 957-Pin FCBGA
  • Product Categories: Module RF, IC et Accessoires

    Lifecycle:Obsolete -

    RoHS:

  • XC2V2000-4FF896I

    Manufacturer:Xilinx

  • FPGA Virtex-II Family 2M Gates 24192 Cells 650MHz 0.15um Technology 1.5V 896-Pin FCBGA
  • Product Categories: FPGAs (Field Programmable Gate Array)

    Lifecycle:Obsolete -

    RoHS: No RoHS

  • XC2V2000-4FG676I

    Manufacturer:Xilinx

  • FPGA Virtex-II Family 2M Gates 24192 Cells 650MHz 0.15um Technology 1.5V 676-Pin FBGA
  • Product Categories: FPGAs (Field Programmable Gate Array)

    Lifecycle:Obsolete -

    RoHS:

  • XC4028XLA-08BG352C

    Manufacturer:Xilinx

  • FPGA XC4000XLA Family 28K Gates 2432 Cells 263MHz 0.35um Technology 3.3V 352-Pin Metal BGA
  • Product Categories:

    Lifecycle:Obsolete -

    RoHS: No RoHS

Need Help?

Support

If you have any questions about the product and related issues, Please contact us.