CodiodeCodiode
Home
Problem Solving
Skill Tracks
My Assignments
Contests
Leaderboard
Community
Settings
Codiode/Problems/Sequential Logic

Divide by Four Using Counter

EasyVerilog / SystemVerilogBuild

Digital systems frequently require slower, synchronized clocks for low-power peripherals or slower processing domains. A power-of-two clock divider safely generates these frequencies using a simple binary counter.

The module takes a high-speed input clock and outputs a clock running at exactly one-quarter the frequency. By incrementing a 2-bit counter on every clock cycle, the most significant bit naturally toggles at one-quarter the rate of the input clock. Extracting the divided clock directly from this register bit provides a clean, glitch-free clock signal for downstream logic.

The circuit uses a positive-edge triggered clock and an asynchronous active-low reset. On reset, the internal counter and the output clock must both be forced to 0.

Cycle 1: rst_n=0 → count=0, clk_out=0 Cycle 2: rst_n=1 → count=1, clk_out=0 Cycle 3: rst_n=1 → count=2, clk_out=1 Cycle 4: rst_n=1 → count=3, clk_out=1 Cycle 5: rst_n=1 → count=0, clk_out=0 Cycle 6: rst_n=1 → count=1, clk_out=0

{ "signal": [
  { "name": "clk_in",  "wave": "p........." },
  { "name": "rst_n",   "wave": "01........" },
  { "name": "count",   "wave": "=...=...=.", "data": ["0","1","2","3","0","1","2","3","0"] },
  { "name": "clk_out", "wave": "0...1...0." }
], "head": { "text": "The most significant bit of the 2-bit counter provides the divided clock." } }

| Signal | Direction | Width | Description | |--------|-----------|-------|-------------| | clk_in | input | 1 | Positive-edge triggered input clock | | rst_n | input | 1 | Asynchronous active-low reset; forces clk_out to 0 | | clk_out | output | 1 | Divided clock running at one-quarter the frequency of clk_in |

Constraints

  • The module must trigger on the positive edge of clk_in
  • The reset must be asynchronous and active-low
  • The output clock clk_out must be identically zero when rst_n is asserted
  • The output clock must be derived directly from the most significant bit of an internal 2-bit counter to prevent glitches

Topics

Clock Domain CrossingCountersClocking

Solve this problem

Write the module in Verilog, SystemVerilog or VHDL. Your submission is compiled and simulated against a real testbench — you get the waveform back, not a stored answer.

This problem is part of Codiode Pro. The statement above is free to read.

Sign in to solveSee what Pro unlocks

The circuit builder and code editor need a desktop screen. On a phone, read the problem here and open it on a laptop to solve.

Related problems

  • Basic D Flip FlopEasy
  • Debug: Missing Edge in Sensitivity ListMedium
  • Read After Write Hazard DetectionEasy
  • Parameterized Interface with ModportsHard
  • Struct Array PipelineHard
  • T Flip Flop from D Flip Flop TemplateEasy
  • Recursive Generate Reduction TreeHard
  • Four Stage Shift RegisterEasy

Browse all problems · Learning tracks