The Old Man of Storr

Verilog Frequency Divider 〈PREMIUM | Anthology〉

always @(posedge clk) begin if (clk_en) begin // do something every 8 clocks end end If you must produce a real clock (e.g., for an external chip), route the divider output to a global clock buffer (BUFG in Xilinx, GCLK in Intel). This minimizes skew. 4. Advanced Dividers: Programmable and Wide-Range 4.1 Programmable Divider A programmable divider allows software to select ( N ) at runtime. This is a counter with a loadable terminal count .

module prog_divider #(parameter WIDTH=16) ( input clk, rst_n, input [WIDTH-1:0] divisor, // N value output reg clk_out ); reg [WIDTH-1:0] count; always @(posedge clk or negedge rst_n) begin if (!rst_n) begin count <= 0; clk_out <= 0; end else begin if (count == divisor - 1) begin count <= 0; clk_out <= ~clk_out; end else begin count <= count + 1; end end end endmodule verilog frequency divider

Output: 2 cycles high, 1 cycle low → 33% duty, frequency = clk/3. Fractional division (e.g., divide by 2.5) is essential for generating arbitrary frequencies from a fixed crystal. It is achieved by periodically swallowing clock edges using a phase accumulator. always @(posedge clk) begin if (clk_en) begin //

Caveat: The divisor value must be ≥ 2 and stable during operation. For very high input frequencies (e.g., 500 MHz in an ASIC), counter propagation delay may limit performance. Use synchronous prescalers with low-bit ripple counters or Johnson counters. Advanced Dividers: Programmable and Wide-Range 4

module div_by_3 ( input clk, rst_n, output reg clk_out ); reg [1:0] count; always @(posedge clk or negedge rst_n) begin if (!rst_n) begin count <= 0; clk_out <= 0; end else begin if (count == 2) begin // 0,1,2 -> 3 cycles count <= 0; clk_out <= ~clk_out; end else begin count <= count + 1; end end end endmodule

module clk_enable_div8 ( input clk, rst_n, output reg clk_en ); reg [2:0] count; always @(posedge clk or negedge rst_n) begin if (!rst_n) count <= 0; else count <= (count == 7) ? 0 : count + 1; end assign clk_en = (count == 7); // one cycle wide pulse endmodule Then downstream modules use:

Skye Shop

Skye Shop

Browse our online shop for maps, walking guides and gifts.

If you are planning a visit to Skye buying maps and guides before you travel gives you the time to really plan your trip to get the most from your time on the Isle of Skye.

Online Shop

Skye Guide

Isle of Skye Guide

Our guide to Skye includes our top 10 walks each with a full description and photo slideshow offering a step by step account of what to expect.

The Skye Guide also features the towns, villages, wildlife and history of our island.

Skye Guide

Advertise

Sunset over Talisker Beach

To ensure Visitors that are planning a trip to the Island find your business, post a listing here on IsleofSkye.com.

95% of visitors to Skye research the destination online before travelling, help them find what they are looking for!

Advertise