SDVD/design/modular_clock_gen.sv
Waylon Cude 7980424dc8
All checks were successful
ci/woodpecker/push/test-workflow Pipeline was successful
Lots of changes, trying to get ROM working
I think I did some funny math errors so new goal is 8-bit pcm
2025-06-05 18:48:53 -07:00

23 lines
437 B
Systemverilog

module modular_clock_gen(
input clk, reset,
output oclk
);
parameter DIVISOR;
logic [$clog2(DIVISOR)-1:0] counter;
// clock will be high for about half of the cycle, depending on integer
// rounding
assign oclk = counter < (DIVISOR/2);
always_ff @(posedge clk) begin
if (reset)
counter <= DIVISOR-1;
else if (counter == 0)
counter <= DIVISOR-1;
else
counter <= counter - 1;
end
endmodule