+92 332 4229 857 99ProjectIdeas@Gmail.com

Verilog module Code For Up-Down Counter | Verilog Example Codes

Up-down counter is a type of counter which can count both in increasing (up) and decreasing (down) count order. Here is a model verilog code for  3-bit Up-down counter. The counter has been provided with D_in by which any value of count can be loaded externally.

module up_down_counter (count, D_in, load, count_up, cntr_on, clk, reset);
output [2:0] count;
input        load, count_up, cntr_on, clk, reset;
input  [2:0] D_in;
reg    [2:0] count;

always @ (posedge reset or posedge clk)
if (reset==1'b1) count=3'b0; else
  if (load==1'b1) count=D_in;
    if (cntr_on==1)
    if (count_up==1'b1) count=count + 1;
    count=count - 1;


If count_up is logic high, the counter counts in upward direction, otherwise if logic is low the count proceeds in downward direction. Also, the assertion of load bit loads the value of count from the external source from D_in port.