2020# User-tunable parameters
2121# -----------------------------------------------------------------------------
2222VREF = 1.0 # full-scale voltage of the ADC model
23- FS = 50e6 # sample rate [Hz] (informational only)
23+ FS_NS = 20 # sample rate in [ns]
24+ FS = int (1 / FS_NS * 1e9 ) # sample rate [Hz] (informational only)
25+
2426N_SAMPLES = 4096 # record length for FFT (power of two)
2527K_BIN = 601 # coherent-tone bin index (1 ≤ K < N/2)
2628F_IN = K_BIN * FS / N_SAMPLES
@@ -63,6 +65,8 @@ def calc_dynamic_metrics(codes: np.ndarray, vref: float = VREF):
6365 sfdr = 10 * np .log10 (fund_power / max (harmonics )) if harmonics else float ("nan" )
6466 enob = (sinad - 1.76 ) / 6.02
6567
68+ assert 7.5 <= enob <= 8.0
69+
6670 return {"SINAD" : sinad , "SNR" : snr , "THD" : thd , "SFDR" : sfdr , "ENOB" : enob , "freqs" : freqs , "spec" : spec }
6771
6872
@@ -104,6 +108,9 @@ def calc_inl_dnl(codes: np.ndarray, vref: float = VREF):
104108 mids_ideal = (np .arange (n_codes ) + 0.5 ) * ideal_step
105109 inl = (mids_actual - mids_ideal ) / ideal_step
106110
111+ assert 0 <= np .max (np .abs (inl )) <= 1
112+ assert 0 <= np .max (np .abs (dnl )) <= 1
113+
107114 return inl , dnl
108115
109116
@@ -124,7 +131,7 @@ async def run_adc_characterisation(dut):
124131 t = n / FS
125132 vin = 0.5 * VREF * (1 + math .sin (2 * math .pi * F_IN * t ))
126133 dut .vin .value = vin
127- await Timer (2 , units = "ns" )
134+ await Timer (FS_NS , units = "ns" )
128135 codes_fft [n ] = dut .code .value .integer
129136
130137 dyn = calc_dynamic_metrics (codes_fft )
@@ -145,14 +152,14 @@ async def run_adc_characterisation(dut):
145152 dut ._log .info (f"Spectrum saved to { spec_pdf .resolve ()} " )
146153
147154 dut .vin .value = 0.0
148- await Timer (1 , units = "us" )
155+ await Timer (10 , units = "us" )
149156
150157 # ------------------------------------------------------------- ramp run
151158 codes_ramp = np .empty (RAMP_SAMPLES , dtype = np .int16 )
152159 for n in range (RAMP_SAMPLES ):
153160 vin = (n / (RAMP_SAMPLES - 1 )) * VREF
154161 dut .vin .value = vin
155- await Timer (2 , units = "ns" )
162+ await Timer (FS_NS , units = "ns" )
156163 codes_ramp [n ] = dut .code .value .integer
157164
158165 inl , dnl = calc_inl_dnl (codes_ramp )
0 commit comments