Add clock divider
This commit is contained in:
parent
88928aa1b2
commit
08c4451abf
2 changed files with 29 additions and 1 deletions
18
clk_div.sv
Normal file
18
clk_div.sv
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
`ifndef CLK_DIV
|
||||
`define CLK_DIV
|
||||
|
||||
module clk_div #(
|
||||
parameter LOG_DIVISOR = 1
|
||||
) (
|
||||
input clk_in,
|
||||
output clk_out
|
||||
);
|
||||
wire [LOG_DIVISOR-1:0] q;
|
||||
|
||||
always_ff @(posedge clk_in)
|
||||
q <= q + 1;
|
||||
|
||||
assign clk_out = q[LOG_DIVISOR-1];
|
||||
endmodule
|
||||
|
||||
`endif
|
||||
12
top.sv
12
top.sv
|
|
@ -1,3 +1,4 @@
|
|||
`include "clk_div.sv"
|
||||
`include "rv32.sv"
|
||||
|
||||
module top (
|
||||
|
|
@ -33,8 +34,17 @@ module top (
|
|||
.D_OUT_0({flash_io1_out, flash_io0_out})
|
||||
);
|
||||
|
||||
logic clk_slow;
|
||||
|
||||
clk_div #(
|
||||
.LOG_DIVISOR(18)
|
||||
) clk_div (
|
||||
.clk_in(clk),
|
||||
.clk_out(clk_slow)
|
||||
);
|
||||
|
||||
rv32 rv32 (
|
||||
.clk(clk),
|
||||
.clk(clk_slow),
|
||||
.leds(leds)
|
||||
);
|
||||
endmodule
|
||||
|
|
|
|||
Loading…
Reference in a new issue