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

43 lines
829 B
Coq
Raw Normal View History

module clock_divider(
input clk,
2018-02-07 00:07:40 +00:00
input reset,
output reg clk_div2,
output reg clk_div4,
output reg clk_div8,
output reg clk_div16,
output reg [3:0] counter,
output cntr_div2,
output cntr_div4,
output cntr_div8,
output cntr_div16
);
// simple ripple clock divider
always @(posedge clk)
clk_div2 <= ~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;
// use bits of (4-bit) counter to divide clocks
2018-02-07 00:07:40 +00:00
always @(posedge clk or posedge reset)
if (reset)
counter <= 0;
else
counter <= counter + 1;
assign cntr_div2 = counter[0];
assign cntr_div4 = counter[1];
assign cntr_div8 = counter[2];
assign cntr_div16 = counter[3];
endmodule