Menu
Coddy logo textTech

4 Bit Counter

Part of the Fundamentals section of Coddy's Verilog journey — lesson 84 of 90.

challenge icon

Challenge

Build a 4-bit counter that counts from 0 to 15 and wraps back to 0.

Module Interface

PortDirectionWidthDescription
clkinput1 bitClock signal
resetinput1 bitReset counter to 0
countoutput4 bitsCurrent counter value

Truth Table

Clock Cyclecount
After reset0
11
22
......
1515
160 (wraps around)

Your task is to complete the module below.

What to do:

  1. On reset, set count to 0
  2. On each rising clock edge, increment count by 1
  3. When count reaches 15, the next increment should wrap to 0

Try it yourself

module counter (
  input clk,
  input reset,
  output reg [3:0] count
);
  
  // TODO: Add always block with posedge clk and posedge reset
  // On reset: count <= 0
  // Otherwise: count <= count + 1

endmodule

All lessons in Fundamentals