1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2024-11-21 23:30:58 +00:00
8bitworkshop/presets/verilog/clock_divider.v

31 lines
503 B
Verilog

/*
A clock divider in Verilog, using the cascading
flip-flop method.
*/
module clock_divider(
input clk,
input reset,
output reg clk_div2,
output reg clk_div4,
output reg clk_div8,
output reg clk_div16
);
// simple ripple clock divider
always @(posedge clk)
clk_div2 <= reset ? 0 : ~clk_div2;
always @(posedge clk_div2)
clk_div4 <= ~clk_div4;
always @(posedge clk_div4)
clk_div8 <= ~clk_div8;
always @(posedge clk_div8)
clk_div16 <= ~clk_div16;
endmodule