Divide by Even N with 50% Duty Cycle
Peripherals often run at an even fraction of the main clock. A parameterized divider covers every ratio with one module: toggle the output every N/2 cycles.
The module divides the frequency of the input clock by an even integer parameter N to produce an output clock with a 50% duty cycle. The output clock transitions every N/2 input clock cycles.
Timing and reset rules:
- Clock edge:
posedge clk - Reset type: Asynchronous
- Reset polarity: Active-low (
rst_n) - Reset behavior: On reset,
clk_outis driven to 0 and all internal counters are cleared to 0 immediately. - Operation: The internal counter increments on every positive edge of
clk. When the counter reaches(N/2) - 1, the outputclk_outtoggles, and the counter resets to 0.
Worked trace for N=4:
Cycle 1: rst_n=0 → clk_out=0, count=0
Cycle 2: rst_n=1 → clk_out=0, count=1
Cycle 3: rst_n=1 → clk_out=1, count=0 (toggled)
Cycle 4: rst_n=1 → clk_out=1, count=1
Cycle 5: rst_n=1 → clk_out=0, count=0 (toggled)
Cycle 6: rst_n=1 → clk_out=0, count=1
| Parameter | Default | Description |
|---|---|---|
N |
4 | Even integer division ratio |
| Signal | Direction | Width | Description |
|---|---|---|---|
clk |
input | 1 | Positive-edge triggered clock |
rst_n |
input | 1 | Asynchronous active-low reset; clk_out goes to 0 when asserted |
clk_out |
output | 1 | Divided clock output with 50% duty cycle |
Constraints
Nis guaranteed to be an even integer greater than or equal to 2.- Clock edge is
posedge clk. - Reset is asynchronous and active-low.
- On reset,
clk_outand any internal counters must immediately go to 0. clk_outmust be a registered output.
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 7 of 36 in the Clock Domain Crossing and Synchronization track.
Related problems
Browse all problems · Verilog practice problems · Learning tracks