Divide by Three with 50% Duty Cycle
A counter divides by an odd number easily, but the output is high for one count more than it is low. Getting exactly 50% for an odd ratio needs the falling edge as well as the rising one.
The module divides the input clock clk_in by three while maintaining a perfect 50% duty cycle. The output clock clk_out must remain high for exactly 1.5 cycles of clk_in and low for exactly 1.5 cycles. This requires leveraging both the positive and negative edges of the source clock to achieve the half-cycle shift.
- Clock edge: Both
posedgeandnegedgeofclk_inmust be used to generate the correct output phase. - Reset type: Asynchronous.
- Reset polarity: Active-low (
rst_n). - Output values on reset: All internal states and the output
clk_outmust evaluate to 0 whenrst_nis 0.
Cycle 1 (posedge): rst_n=0, clk_in=0 → clk_out=0
Cycle 2 (posedge): rst_n=1, clk_in=1 → internal counter increments, clk_out transitions to 1
Cycle 2 (negedge): rst_n=1, clk_in=0 → clk_out remains 1
Cycle 3 (posedge): rst_n=1, clk_in=1 → clk_out remains 1
Cycle 3 (negedge): rst_n=1, clk_in=0 → clk_out transitions to 0 (exactly 1.5 cycles after rising)
Cycle 4 (posedge): rst_n=1, clk_in=1 → clk_out remains 0
Cycle 4 (negedge): rst_n=1, clk_in=0 → clk_out remains 0
Cycle 5 (posedge): rst_n=1, clk_in=1 → clk_out transitions to 1 (exactly 1.5 cycles after falling)
| Signal | Direction | Width | Description |
|---|---|---|---|
clk_in |
input | 1 | Source clock |
rst_n |
input | 1 | Asynchronous active-low reset; clk_out goes to 0 when asserted |
clk_out |
output | 1 | Divided clock with 50% duty cycle; resets to 0 |
Constraints
- Output
clk_outmust have exactly a 50% duty cycle. - Reset is asynchronous and active-low.
clk_outmust be exactly 0 whilerst_nis 0.- The design must use both
posedge clk_inandnegedge clk_into achieve the half-cycle resolution. clk_outmust not glitch high immediately when reset is released; the first high pulse must begin strictly on the first positive clock edge after reset deassertion.
Topics
Solve this problem
Write the module in Verilog, SystemVerilog or VHDL. Your submission is compiled and simulated against the problem's testbench. You get the waveform back, not a stored answer.
This problem is part of Codiode Pro. The statement above is free to read.
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.
Part of Clock Domain Crossing and Synchronization
Problem 6 of 36 in the Clock Domain Crossing and Synchronization track.
Related problems
Browse all problems · Verilog practice problems · Learning tracks