Clock Divider Verilog 50 Mhz 1hz Today

module clock_divider_50M_to_1Hz ( input wire clk_50mhz, // 50 MHz input clock input wire rst_n, // Active-low reset output reg clk_1hz // 1 Hz output clock ); // 50 MHz → 1 Hz requires division by 50,000,000 // Count from 0 to 24,999,999 (toggle) then repeat // Total cycles: 50,000,000 = 2 × 25,000,000

always @(posedge clk_50mhz or negedge rst_n) begin if (!rst_n) begin count <= 0; clk_1hz <= 0; end else begin if (count == HALF_CYCLE) begin count <= 0; clk_1hz <= ~clk_1hz; end else begin count <= count + 1; end end end endmodule module clock_divider #( parameter INPUT_FREQ = 50_000_000, // Hz parameter OUTPUT_FREQ = 1 // Hz ) ( input wire clk_in, input wire rst_n, output reg clk_out ); localparam MAX_COUNT = (INPUT_FREQ / OUTPUT_FREQ) / 2 - 1; // For 50 MHz to 1 Hz: MAX_COUNT = 24,999,999 clock divider verilog 50 mhz 1hz

// Generate 50 MHz clock (period = 20 ns) initial begin clk_50mhz = 0; forever #10 clk_50mhz = ~clk_50mhz; // 10ns half period = 20ns full period end module clock_divider_50M_to_1Hz ( input wire clk_50mhz