Electronics > FPGA

Verilog Floating Point Clock Divider Release.

(1/2) > >>

BrianHG:
**************************************************************************************************
   BHG_FP_clk_divider.v   V1.2, August 10, 2022.
   Floating point clock divider/synthesizer.
   24.16 (m.n) bit floating point clock divider. (Actually it is a fixed point fractional divider.)

   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.

Written by Brian Guralnick.
https://github.com/BrianHGinc/Verilog-Floating-Point-Clock-Divider
 
     Provide / define the INPUT_CLK_HZ parameter and the BHG_FP_clk_divider will generate a clock at the specified CLK_OUT_HZ parameter.  The module will output a 50:50 duty cycle clock plus two single clk_in cycle pulsed outputs, one at the rise of the clk_out, and another at the fall of clk_out.
 
     *** The module will generate a report of the synthesized output clock specs in your FPGA vendor compiler's message processing window during compile.  The report will contain the resulting frequency down to the 0.01Hz, calculated PPM error and jitter spec.
 
  To simulate this project in Modelsim:
     1) Run Modelsim all by itself.  You do not need your FPGA compiler studio.
     2) Select 'File / Change Directory' and choose this project's folder.
     3) In the transcript, type:                           'do setup_fpd.do'.  (DONE!)
     4) To re-compile and simulate again, type: 'do run_fpd.do'.    (DONE!)
 
     For public use.  Just be fair and give credit where it is due.

**************************************************************************************************

Example Modelsim screenshot of simulating a full second:

(USE_FLOATING_DIVIDE=1,CLK_IN_HZ=100000000,CLK_OUT_HZ=3579545)


(USE_FLOATING_DIVIDE=0,CLK_IN_HZ=100000000,CLK_OUT_HZ=3579545)



Example Quartus screenshot of compilation report with LUT/LR:

(USE_FLOATING_DIVIDE=1,CLK_IN_HZ=148500000,CLK_OUT_HZ=3072000 = Audio I2S sclk for 48Khz sound)


(USE_FLOATING_DIVIDE=0,CLK_IN_HZ=148500000,CLK_OUT_HZ=3072000 = Audio I2S sclk for 48Khz sound)


Looking at the 'Frequency error PPM' alone shows the value in this code.
Remember, most consumer grade crystals are around +/-50ppm tolerant.

If you require a single or multiple fractional clocks when you only have a single source clock, or want your FPGA compiler to only deal with one master clock domain using my clock divider's pulse outputs as 'enable logic', this code will fit the bill.

BrianHG:
*** Note *** I just changed the '13.16 (m.n)' divider to '24.16 (m.n)'.  Just re-download the source.

IE: If you have a 450MHz clock, you can now divide down to below a 1 KHz clock.  My code automatically trims unused bits for smaller divides, or divides with even fractions.

ali_asadzadeh:
BrianHG Thanks for sharing
I tried to simulate the design in modelsim and it complains about it,


--- Quote ---vlog -work work -vopt -stats=none C:/Users/ASiDesigner/Desktop/Verilog-Floating-Point-Clock-Divider/hdl/BHG_FP_clk_divider_tb.v
Model Technology ModelSim SE-64 vlog 10.6d Compiler 2018.02 Feb 24 2018
-- Compiling module BHG_FP_clk_divider
** Error: C:/Users/ASiDesigner/Desktop/Verilog-Floating-Point-Clock-Divider/hdl/BHG_FP_clk_divider_tb.v(28): (vlog-2155) Global declarations are illegal in Verilog 2001 syntax.
** Error: C:/Users/ASiDesigner/Desktop/Verilog-Floating-Point-Clock-Divider/hdl/BHG_FP_clk_divider_tb.v(34): (vlog-2730) Undefined variable: 'PS_NUMERATOR'.
** Error (suppressible): C:/Users/ASiDesigner/Desktop/Verilog-Floating-Point-Clock-Divider/hdl/BHG_FP_clk_divider_tb.v(34): (vlog-2388) 'PS_NUMERATOR' already declared in this scope (work).
** Error: C:/Users/ASiDesigner/Desktop/Verilog-Floating-Point-Clock-Divider/hdl/BHG_FP_clk_divider_tb.v(34): Verilog Compiler exiting
--- End quote ---

BrianHG:

--- Quote from: ali_asadzadeh on August 10, 2022, 09:04:08 am ---BrianHG Thanks for sharing
I tried to simulate the design in modelsim and it complains about it,


--- Quote ---vlog -work work -vopt -stats=none C:/Users/ASiDesigner/Desktop/Verilog-Floating-Point-Clock-Divider/hdl/BHG_FP_clk_divider_tb.v
Model Technology ModelSim SE-64 vlog 10.6d Compiler 2018.02 Feb 24 2018
-- Compiling module BHG_FP_clk_divider
** Error: C:/Users/ASiDesigner/Desktop/Verilog-Floating-Point-Clock-Divider/hdl/BHG_FP_clk_divider_tb.v(28): (vlog-2155) Global declarations are illegal in Verilog 2001 syntax.
** Error: C:/Users/ASiDesigner/Desktop/Verilog-Floating-Point-Clock-Divider/hdl/BHG_FP_clk_divider_tb.v(34): (vlog-2730) Undefined variable: 'PS_NUMERATOR'.
** Error (suppressible): C:/Users/ASiDesigner/Desktop/Verilog-Floating-Point-Clock-Divider/hdl/BHG_FP_clk_divider_tb.v(34): (vlog-2388) 'PS_NUMERATOR' already declared in this scope (work).
** Error: C:/Users/ASiDesigner/Desktop/Verilog-Floating-Point-Clock-Divider/hdl/BHG_FP_clk_divider_tb.v(34): Verilog Compiler exiting
--- End quote ---

--- End quote ---

Thanks, there are 2 ways to fix this:

    1) In Modelsim, In menu 'Compile / Compile Options / Language Syntax':
        Switch from 'Use Verilog 2001' to 'Default'.

    2) In my source code 'BHG_FP_clk_divider_tb.v', move line 36 to line 28.

    Thank you for pointing this out.  I will patch my Github with option #2 as it will allow Modelsim to work with both language syntax setting in Modelsim.  However, 'Use Verilog 2001' also blocks SystemVerilog support.


BrianHG:
New version 1.1 released:

     * v1.1 Patches a simulation bug where Modelsim's 'Compile / Compile Options / Language Syntax' is set to 'Use Verilog 2001' instead of 'Default'.

The 'BHG_FP_CLK_DIVIDER_v1.1.zip' is now attached to in opening thread.

Navigation

[0] Message Index

[#] Next page

There was an error while thanking
Thanking...
Go to full version