mirror of
https://github.com/pConst/basic_verilog.git
synced 2025-01-14 06:42:54 +08:00
Added SystemVerilog version of clock divider
This commit is contained in:
parent
d971d108cf
commit
a6280adfde
42
clk_divider.sv
Normal file
42
clk_divider.sv
Normal file
@ -0,0 +1,42 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// clk_divider.sv
|
||||
// Konstantin Pavlov, pavlovconst@gmail.com
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// INFO ------------------------------------------------------------------------
|
||||
// Divides main clock to get derivative slower synchronous clocks
|
||||
|
||||
|
||||
/* --- INSTANTIATION TEMPLATE BEGIN ---
|
||||
|
||||
clk_divider #(
|
||||
.WIDTH( 32 )
|
||||
) CD1 (
|
||||
.clk( clk ),
|
||||
.nrst( 1'b1 ),
|
||||
.ena( 1'b1 ),
|
||||
.out( )
|
||||
);
|
||||
|
||||
--- INSTANTIATION TEMPLATE END ---*/
|
||||
|
||||
|
||||
module clk_divider #(
|
||||
WIDTH = 32
|
||||
)(
|
||||
input clk,
|
||||
input nrst,
|
||||
input ena,
|
||||
output logic [(WIDTH-1):0] out = 0
|
||||
);
|
||||
|
||||
|
||||
always_ff @(posedge clk) begin
|
||||
if ( ~nrst ) begin
|
||||
out[(WIDTH-1):0] <= 0;
|
||||
end else if (ena) begin
|
||||
out[(WIDTH-1):0] <= out[(WIDTH-1):0] + 1'b1;
|
||||
end
|
||||
end
|
||||
|
||||
endmodule
|
Loading…
x
Reference in New Issue
Block a user