// ========================================================== // Helper: FTW function (compile-time or runtime call) // FTW = round( f_hz * 2^PHASE_BITS / FS_HZ ) // Notes: // - Accepts integer Hz. // - Uses 64-bit math to avoid overflow for typical params. // - Can be called from a testbench or combinational logic that // prepares 'ftw_in' before asserting 'ftw_we'. // Example: // initial begin // #1; // $display("FTW 1kHz = 0x%08x", ftw_from_hz(1000)); // end // ========================================================== function [31:0] ftw_from_hz; input integer f_hz; input integer phase_bits; input integer fs_hz; reg [63:0] numer; begin numer = ((64'd1 << phase_bits) * f_hz) + (fs_hz/2); ftw_from_hz = numer / fs_hz; end endfunction