Tuesday, November 4, 2025

thumbnail

Clock Divider Design

 ๐Ÿ•’ What is a Clock Divider?


A clock divider is a digital circuit that reduces the frequency of an input clock signal to produce a slower clock output.


For example:

If the input clock is 100 MHz and you divide it by 2, the output clock will be 50 MHz.


⚙️ Why Do We Need Clock Dividers?


Clock dividers are commonly used to:


Generate lower-frequency clocks for slower modules.


Synchronize signals between different clock domains.


Create timing signals (like baud rates in UARTs).


Drive LEDs or display signals visibly.


๐Ÿ”ง Basic Concept


The simplest clock divider works by counting input clock pulses and toggling the output when the count reaches a certain value.


For divide-by-2 → toggle output every clock edge.


For divide-by-N → count up to N/2, then toggle.


๐Ÿงฑ Example 1: Divide-by-2 Clock Divider


This is the simplest case — output frequency = input frequency ÷ 2.


Verilog Code:

module clk_div2 (

  input wire clk,

  input wire reset,

  output reg clk_out

);


  always @(posedge clk or posedge reset) begin

    if (reset)

      clk_out <= 0;

    else

      clk_out <= ~clk_out;  // Toggle on every clock edge

  end


endmodule


Explanation:


Each clock cycle toggles clk_out.


The output frequency is half of the input clock frequency.


๐Ÿงฎ Example 2: General Clock Divider (Divide-by-N)


Here, you can specify any integer division factor N.


Verilog Code:

module clk_divider #(

  parameter N = 10  // Divide-by-N (must be even for 50% duty cycle)

)(

  input wire clk,

  input wire reset,

  output reg clk_out

);

  integer count;


  always @(posedge clk or posedge reset) begin

    if (reset) begin

      count   <= 0;

      clk_out <= 0;

    end else begin

      if (count == (N/2 - 1)) begin

        clk_out <= ~clk_out;  // Toggle output

        count   <= 0;

      end else

        count <= count + 1;

    end

  end


endmodule


Explanation:


count keeps track of input clock cycles.


Every N/2 input clocks, the output toggles.


Result: output clock = input clock ÷ N.


๐Ÿงฐ Example Instantiation

clk_divider #(4) div4 (.clk(clk_in), .reset(rst), .clk_out(clk_out));  // Divide by 4

clk_divider #(10) div10 (.clk(clk_in), .reset(rst), .clk_out(clk_slow)); // Divide by 10


๐Ÿ’ก Example 3: Clock Divider for Odd Division (e.g., ÷3)


Dividing by an odd number (like 3, 5, 7) requires special handling because it can’t produce a perfect 50% duty cycle.


Verilog Code:

module clk_div3 (

  input wire clk,

  input wire reset,

  output reg clk_out

);

  reg [1:0] count;


  always @(posedge clk or posedge reset) begin

    if (reset) begin

      count <= 0;

      clk_out <= 0;

    end else begin

      if (count == 2) begin

        count <= 0;

        clk_out <= ~clk_out;

      end else

        count <= count + 1;

    end

  end

endmodule


Output:


Output frequency = input frequency ÷ 6 (toggle every 3 clocks → full period every 6 clocks).


Duty cycle ≈ 33% or 66%.


๐Ÿ“Š Timing Diagram Example (Divide-by-4)

Input Clock ↑ ↓ ↑ ↓ ↑ ↓ ↑ ↓

Counter 0 1 2 3 0 1 2 3

Output Clock --------____----


Output toggles every N/2 cycles → divided frequency.


๐Ÿง  Key Design Notes


✅ Use non-blocking assignments (<=) in sequential logic.

✅ Use reset to start from a known state.

✅ For 50% duty cycle, N must be even.

✅ For odd dividers, expect non-symmetric duty cycles.

✅ Clock dividers are not synthesizable for extremely high divisions (like millions) — use PLLs or timers for that.


๐Ÿงฉ Testbench Example

module clk_divider_tb;

  reg clk, reset;

  wire clk_out;


  // Instantiate DUT (divide by 4)

  clk_divider #(4) uut (.clk(clk), .reset(reset), .clk_out(clk_out));


  // Generate clock (10ns period = 100 MHz)

  initial clk = 0;

  always #5 clk = ~clk;


  initial begin

    reset = 1;

    #20 reset = 0;


    #200 $finish;

  end


  initial begin

    $monitor("Time=%0t | clk=%b | clk_out=%b", $time, clk, clk_out);

  end

endmodule


⚖️ Summary Table

Divider Type Output Frequency Duty Cycle Example

Divide-by-2 f/2 50% Toggle each edge

Divide-by-N (even) f/N 50% Counter-based

Divide-by-N (odd) f/N ~50% Uneven toggle

Parameterized Divider Flexible Configurable Generic design


✅ In summary:


Clock dividers reduce frequency by counting input clocks.


They can be parameterized for flexible division factors.


Common in FPGA, microcontroller, and digital control systems.

Learn VLSI Training in Hyderabad

Read More

Parameterized Modules in Verilog

Testbenches in Verilog

Writing a 4-bit Adder in Verilog

First Verilog Code: Hello World

Visit Our Training Institute in Hyderabad

Get Directions

Subscribe by Email

Follow Updates Articles from This Blog via Email

No Comments

About

Search This Blog

Powered by Blogger.

Blog Archive