Skip to content

Commit a5005a2

Browse files
authored
Add files via upload
1.2a - Added a protection for when the integer divider has less than 2 bits. 1.2b- Added a compilation $error and $stop with instructions if the user supplies inoperable CLK_HZ parameters. 1.1 - Fixed a bug with some Modelsim versions where its 'Compile/Compile Options/Language Syntax' is set to 'Use Verilog 2001' instead of 'Default'. 1.0 - Initial release.
1 parent f34a3fe commit a5005a2

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

hdl/BHG_FP_clk_divider.v

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
// ******************************************************************************************************
22
//
3-
// BHG_FP_clk_divider.v V1.1, August 2022.
3+
// BHG_FP_clk_divider.v V1.2, August 2022.
44
// Floating point clock divider/synthesizer.
55
// 24.16 (m.n) bit floating point clock divider. (Actually it is a fixed point fractional divider.)
66
//
7+
// 1.2 - Added a protection for when the integer divider has less than 2 bits.
8+
// - Added a compilation $error and $stop with instructions if the user supplies inoperable CLK_HZ parameters.
9+
// 1.1 - Fixed a bug with some Modelsim versions where its 'Compile / Compile Options / Language Syntax' is set to 'Use Verilog 2001' instead of 'Default'.
10+
// 1.0 - Initial release.
11+
//
712
// Written by Brian Guralnick.
813
// https://github.com/BrianHGinc / or / https://www.eevblog.com/forum/fpga/ User BrianHG.
914
//
@@ -37,6 +42,37 @@ parameter INPUT_CLK_HZ = 100000000 ; // Source clk_in frequency in Hz.
3742
parameter OUTPUT_CLK_HZ = 3579545 ; // Desired clk_out frequency in Hz.
3843

3944

45+
// ****************************************************************************
46+
// Inoperable Parameter Error
47+
// ****************************************************************************
48+
generate
49+
if ( (OUTPUT_CLK_HZ*2)>INPUT_CLK_HZ ) initial begin
50+
$display("");
51+
$display(" XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
52+
$display(" XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
53+
$display(" XXXXX XXXXX");
54+
$display(" XXXXX BHG_FP_clk_divider.v inoperable parameter error. XXXXX");
55+
$display(" XXXXX https://github.com/BrianHGinc XXXXX");
56+
$display(" XXXXX XXXXX");
57+
$display(" XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
58+
$display(" XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
59+
$display(" XXXXX XXXXX");
60+
$display(" XXXXX BHG_FP_clk_divider.v can only generate an output clock at least 1/2 the source clock frequency. XXXXX");
61+
$display(" XXXXX XXXXX");
62+
$display(" XXXXX Your current set parameters: XXXXX");
63+
$display(" XXXXX XXXXX");
64+
$display(" XXXXX .INPUT_CLK_HZ = %d Hz. XXXXX",31'(INPUT_CLK_HZ));
65+
$display(" XXXXX .OUTPUT_CLK_HZ = %d Hz. XXXXX",31'(OUTPUT_CLK_HZ));
66+
$display(" XXXXX XXXXX");
67+
$display(" XXXXX .OUTPUT_CLK_HZ must be less than or equal to .INPUT_CLK_HZ/2 for BHG_FP_clk_divider.v to function. XXXXX");
68+
$display(" XXXXX XXXXX");
69+
$display(" XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
70+
$warning(" XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
71+
$error;
72+
$stop;
73+
end
74+
endgenerate
75+
4076
// *************************************************************************************************************************************************************
4177
// Forcing 64 bits is required due to a ModelSim internal bug where if 'PLL1_OUT_TRUE_HZ*655360' exceeds 31 bits, it's considered negative and cropped
4278
// when computing the localparam. So, never use 'localparam int' when going above 2 billion anywhere inside, or you will get bogus results.
@@ -90,7 +126,8 @@ endgenerate
90126
// Floating point clock divider logic.
91127
// ****************************************************************************
92128

93-
localparam mb = $clog2(clk_per_int);
129+
localparam pmb = $clog2(clk_per_int);
130+
localparam mb = (pmb<2) ? 2 : pmb ; // Protection for when the integer divider has less than 2 bits.
94131

95132
reg [mb-1:0] clk_cnt_m = (mb)'(0) ; // This integer counts up 1 by 1 requiring manual bit reduction 'mb' for minimum logic cells.
96133
reg [16:0] clk_cnt_n = 17'd0 ; // This fractional int adds upward by a fixed parameter, the FPGA compiler is capable of automatically pruning unused bits.

hdl/BHG_FP_clk_divider_tb.v

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
// ***************************************************************************************************************
2-
// BHG_FP_clk_divider_tb.v V1.1, August 2022.
2+
// BHG_FP_clk_divider_tb.v V1.2, August 2022.
33
// Floating point clock divider/synthesizer testbench.
44
// 24.16 (m.n) bit floating point clock divider. (Actually it is a fixed point fractional divider.)
55
//
6+
// 1.2 - Added a protection for when the integer divider has less than 2 bits.
7+
// - Added a compilation $error and $stop with instructions if the user supplies inoperable CLK_HZ parameters.
8+
// 1.1 - Fixed a bug with some Modelsim versions where its 'Compile / Compile Options / Language Syntax' is set to 'Use Verilog 2001' instead of 'Default'.
9+
// 1.0 - Initial release.
10+
//
611
// Written by Brian Guralnick.
712
// https://github.com/BrianHGinc / or / https://www.eevblog.com/forum/fpga/ User BrianHG.
813
//

0 commit comments

Comments
 (0)