Verilog HDL: Behavioral Counter

This example describes an 8-bit loadable counter with count enable. The always construct, highlighted in red text, describes how the counter should behave.

For more information of Verilog, go to:


module behav_counter( d, clk, clear, load, up_down, qd);

// Port Declaration

input   [7:0] d;
input   clk;
input   clear;
input   load;
input   up_down;
output  [7:0] qd;

reg     [7:0] cnt;

always @ (posedge clk)
    if (!clear)
        cnt <= 8'h00;
    else if (load)
        cnt <= d;
    else if (up_down)
        cnt <= cnt + 1;
        cnt <= cnt - 1;
assign qd = cnt;


Design Examples Disclaimer

These design examples may only be used within Intel PSG Corporation devices and remain the property of Intel PSG. They are being provided on an “as-is” basis and as an accommodation; therefore, all warranties, representations, or guarantees of any kind (whether express, implied, or statutory) including, without limitation, warranties of merchantability, non-infringement, or fitness for a particular purpose, are specifically disclaimed. Intel PSG expressly does not recommend, suggest, or require that these examples be used in combination with any other product not provided by Intel PSG.