|
4 | 4 | // Floating point clock divider/synthesizer. |
5 | 5 | // 24.16 (m.n) bit floating point clock divider. (Actually it is a fixed point fractional divider.) |
6 | 6 | // |
| 7 | +// 1.3 - Corrected the PPM calculation + added 1 bit to the M divider counter for the occasional requirement. (Thanks to 'dennowiggle' for catching the error) |
7 | 8 | // 1.2 - Added a protection for when the integer divider has less than 2 bits. |
8 | 9 | // - Added a compilation $error and $stop with instructions if the user supplies inoperable CLK_HZ parameters. |
9 | 10 | // 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'. |
@@ -87,7 +88,7 @@ localparam [15:0] clk_per_f = USE_FLOATING_DIVIDE ? clk_per_x65k[15:0] |
87 | 88 |
|
88 | 89 | localparam [63:0] clk_tru_hzX100 = INPUT_CLK_HZ * 6553600 / (clk_per_int*65536+clk_per_f) ; // Calculate the true output clock X 100. |
89 | 90 | localparam signed clk_dif_hzX100 = (clk_tru_hzX100 - (OUTPUT_CLK_HZ*100)) ; |
90 | | -localparam signed clk_ppm_x100 = clk_dif_hzX100 * OUTPUT_CLK_HZ / 1000000 ; // Calculate the PPM offset error X 100. |
| 91 | +localparam signed clk_ppm_x100 = clk_dif_hzX100 * 1000000 / OUTPUT_CLK_HZ ; // Calculate the PPM offset error X 100. |
91 | 92 | localparam [63:0] clk_jitterx100 = (clk_per_f==0) ? 0 : (100000*1000000/INPUT_CLK_HZ) /2 ; // Calculate the occasional jitter X 100 generated by the floating point clock correction clock step. |
92 | 93 |
|
93 | 94 | localparam real f_tru = clk_tru_hzX100 ; // Necessary for being able to display the decimal point |
@@ -126,7 +127,7 @@ endgenerate |
126 | 127 | // Floating point clock divider logic. |
127 | 128 | // **************************************************************************** |
128 | 129 |
|
129 | | -localparam pmb = $clog2(clk_per_int); |
| 130 | +localparam pmb = $clog2(clk_per_int) + 1; |
130 | 131 | localparam mb = (pmb<2) ? 2 : pmb ; // Protection for when the integer divider has less than 2 bits. |
131 | 132 |
|
132 | 133 | 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. |
|
0 commit comments