Verilog Code for Binary Up/Down Counter
Advertisement
This article provides Verilog HDL code for a binary up/down counter.
Symbol and Truth Table
The following is the truth table of the binary up/down counter:

| Clk | Rst | Dir | Qout |
|---|---|---|---|
| X | 1 | X | 0000 |
| 1 | 0 | 0 | 0001 |
| 1 | 0 | 0 | 0010 |
| 1 | 0 | 0 | 0011 |
| 1 | 0 | 0 | 0100 |
| 1 | 0 | 0 | 0101 |
| 1 | 0 | 0 | 0110 |
| 1 | 0 | 0 | 0111 |
| 1 | 0 | 0 | 1000 |
| 1 | 0 | 0 | 1001 |
| 1 | 0 | 0 | 1010 |
| 1 | 0 | 0 | 1011 |
| 1 | 0 | 0 | 1100 |
| 1 | 0 | 0 | 1101 |
| 1 | 0 | 0 | 1110 |
| 1 | 0 | 0 | 1111 |
Verilog Code
module bin_as(clk,clr,dir, temp);
input clk,clr,dir;
output reg[3:0] temp;
always@(posedge clk,posedge clr)
begin
if(clr==0)
begin
if(dir==0)
temp=temp+1;
else
temp=temp-1;
end
else
temp=4'd0;
end
endmodule
Simulation Result
Here’s the simulation result of the above Verilog code:

Explore Verilog Logic Gates, Mux & Encoders
- Verilog HDL Code for All Logic Gates
- 2-to-4 Decoder (Verilog HDL Code)
- 4-to-1 Multiplexer and 1-to-4 Demultiplexer (Verilog Code)
- Verilog Code: 1-to-4 Demultiplexer
- 8-to-1 Multiplexer (Verilog HDL Code)
- 8-to-3 Encoder Without Priority (Verilog)
- 8-to-3 Priority Encoder (Verilog)
- 8-to-3 Priority Encoder (Verilog Code)
- 1-Bit and 4-Bit Comparator Design (Verilog)
Explore Verilog Flip-Flops, Counters & Registers
- T, D, SR, JK Flip Flop (Verilog HDL Code)
- D Flip Flop Synchronous Reset (Verilog)
- D Flip Flop Without Reset (Verilog)
- Verilog Code for Binary Up-Down Counter
- Verilog HDL: BCD & Gray Counters
- 4-bit Down Counter (Verilog Code Test Bench)
- 4-bit Binary Asynchronous Reset Counter (Verilog)
- 4-bit Binary Synchronous Reset Counter (Verilog)
- 4-bit BCD Asynchronous Reset Counter (Verilog)
- 4-bit BCD Synchronous Reset Counter (Verilog Code)
- 4-bit Mod-13 Counter (Verilog Code Test Bench)
- Shift Left / Shift Right Register (Verilog)
- Parallel Load Shift Left Register (Verilog Code)
- PRBS Generator (Verilog Code Test Bench)
Explore Verilog Math, Processing & Memory
- Full Adder (Verilog HDL Code)
- Verilog Code: Half Adder, Half Subtractor, Full Subtractor
- 32-Bit ALU (Verilog Code)
- RAM / ROM (Verilog Code)
- Asynchronous FIFO (Verilog Code Test Bench)
- Asynchronous FIFO Design (Verilog Code and Explanation)
- Mealy / Moore Machine (Verilog)
- Low Pass FIR Filter (Verilog Code)
- 4-bit Binary to Gray Counter Converter in Verilog
