// dds.sv // Direct digital synthesis (NCO): an N-bit phase accumulator and a // quarter-wave sine lookup table. // // Output frequency: f_out = tuning_word * f_clk / 2**ACC_W. // The top PH_W bits of the accumulator address the table. The two most // significant of them select the quarter of the cycle; the rest address a // 2**(PH_W-2)-entry table that holds only the first quarter. // quarter 0: lut[a] quarter 1: lut[~a] // quarter 2: -lut[a] quarter 3: -lut[~a] // Table entry k = round(32767 * sin(2*pi*(k + 0.5) / 2**PH_W)), written by // dds_model.py. The half-step offset makes the quarter symmetric, so the // mirrored address ~a needs no extra adder. // // Pipeline: phase register -> table address register -> table read register // -> output register. Latency from the phase register to sample: 3 cycles. `timescale 1ns/1ps module dds #( parameter int ACC_W = 32, // phase accumulator width parameter int PH_W = 10, // phase bits used after truncation parameter int OUT_W = 16, // signed output width parameter string INIT_FILE = "dds_sine_quarter.hex" ) ( input logic clk, input logic rst, // synchronous, active high input logic en, // advance the phase this cycle input logic [ACC_W-1:0] tuning_word, // phase increment per clock output logic [ACC_W-1:0] phase, // accumulator value output logic signed [OUT_W-1:0] sample, output logic sample_valid ); localparam int AW = PH_W - 2; // table address width logic [OUT_W-1:0] lut [0:(1<