forked from pdaxrom/pyldin2012
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclock_divider.v
65 lines (54 loc) · 1.84 KB
/
clock_divider.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// File clock_didived.vhdl translated with vhd2vl v3.0 VHDL to Verilog RTL translator
// vhd2vl settings:
// * Verilog Module Declaration Style: 2001
// vhd2vl is Free (libre) Software:
// Copyright (C) 2001 Vincenzo Liguori - Ocean Logic Pty Ltd
// http://www.ocean-logic.com
// Modifications Copyright (C) 2006 Mark Gonzales - PMC Sierra Inc
// Modifications (C) 2010 Shankar Giri
// Modifications Copyright (C) 2002-2017 Larry Doolittle
// http://doolittle.icarus.com/~larry/vhd2vl/
// Modifications (C) 2017 Rodrigo A. Melo
//
// vhd2vl comes with ABSOLUTELY NO WARRANTY. Always check the resulting
// Verilog for correctness, ideally with a formal verification tool.
//
// You are welcome to redistribute vhd2vl under certain conditions.
// See the license (GPLv2) file included with the source for details.
// The result of translation follows. Its copyright status should be
// considered unchanged from the original VHDL.
// no timescale needed
module clock_div(
input wire i_clk,
input wire i_rst,
input wire [3:0] i_clk_divider,
output reg o_clk
);
reg [3:0] r_clk_counter = 0;
reg [3:0] r_clk_divider = 0;
reg [3:0] r_clk_divider_half = 0;
always @(posedge i_clk) begin
if((i_rst == 1'b0)) begin
r_clk_counter <= {4{1'b0}};
r_clk_divider <= {4{1'b0}};
r_clk_divider_half <= {4{1'b0}};
o_clk <= 1'b0;
end else begin
r_clk_divider <= (i_clk_divider) - 1;
r_clk_divider_half <= {1'b0,i_clk_divider[3:1]};
// half
if((r_clk_counter < r_clk_divider_half)) begin
r_clk_counter <= r_clk_counter + 1;
o_clk <= 1'b0;
end
else if((r_clk_counter == r_clk_divider)) begin
r_clk_counter <= {4{1'b0}};
o_clk <= 1'b1;
end
else begin
r_clk_counter <= r_clk_counter + 1;
o_clk <= 1'b1;
end
end
end
endmodule