WRPLL simulation wrapper
wrpll: add gtx, base_adpll init wrpll: config the 3 PLL modes, helper, main & both wrpll: expose PID terms and sim options
This commit is contained in:
parent
cbc9772efa
commit
96280ac79a
93
src/wrpll.py
Normal file
93
src/wrpll.py
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
import numpy as np
|
||||||
|
from numba import jit
|
||||||
|
from wave_gen import square_arr
|
||||||
|
from sim import simulation_jit
|
||||||
|
|
||||||
|
|
||||||
|
class WRPLL_simulator():
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
time,
|
||||||
|
sim_mode,
|
||||||
|
helper_filter,
|
||||||
|
main_filter,
|
||||||
|
gtx_freq,
|
||||||
|
gtx_jitter_SD,
|
||||||
|
dcxo_freq,
|
||||||
|
dcxo_jitter_SD,
|
||||||
|
freq_acquisition_SD,
|
||||||
|
N,
|
||||||
|
adpll_write_period,
|
||||||
|
blind_period,
|
||||||
|
start_up_delay,
|
||||||
|
cycle_slip_comp,
|
||||||
|
helper_init_freq=None
|
||||||
|
):
|
||||||
|
|
||||||
|
self.time = time
|
||||||
|
self.sim_mode = sim_mode
|
||||||
|
self.h_KP = helper_filter["KP"]
|
||||||
|
self.h_KI = helper_filter["KI"]
|
||||||
|
self.h_KD = helper_filter["KD"]
|
||||||
|
self.m_KP = main_filter["KP"]
|
||||||
|
self.m_KI = main_filter["KI"]
|
||||||
|
self.m_KD = main_filter["KD"]
|
||||||
|
|
||||||
|
# init condition
|
||||||
|
self.dcxo_freq = dcxo_freq
|
||||||
|
self.dcxo_jitter_SD = dcxo_jitter_SD
|
||||||
|
self.N = N
|
||||||
|
self.helper_init_freq = helper_init_freq
|
||||||
|
|
||||||
|
self.gtx = square_arr(time, gtx_freq, gtx_jitter_SD)
|
||||||
|
|
||||||
|
# freq_acquisition() error
|
||||||
|
freq_diff = gtx_freq - dcxo_freq + np.random.normal(0, freq_acquisition_SD)
|
||||||
|
self.base_adpll = int(freq_diff * (1 / dcxo_freq) * (1e6 / 0.0001164))
|
||||||
|
|
||||||
|
# sim config
|
||||||
|
self.adpll_write_period = adpll_write_period
|
||||||
|
self.blind_period = blind_period
|
||||||
|
self.start_up_delay = start_up_delay
|
||||||
|
self.cycle_slip_comp = cycle_slip_comp
|
||||||
|
|
||||||
|
if type(self.sim_mode) is not str:
|
||||||
|
raise ValueError(f"pll_type {type(self.sim_mode)} is not a string")
|
||||||
|
|
||||||
|
self.helper_pll = self.main_pll = False
|
||||||
|
if self.sim_mode.lower() == "both":
|
||||||
|
self.helper_pll = self.main_pll = True
|
||||||
|
elif self.sim_mode.lower() == "helper_pll":
|
||||||
|
self.helper_pll = True
|
||||||
|
elif self.sim_mode.lower() == "main_pll":
|
||||||
|
if self.helper_init_freq == None:
|
||||||
|
raise ValueError("main pll mode need to set a helper frequency")
|
||||||
|
self.main_pll = True
|
||||||
|
else:
|
||||||
|
raise ValueError("sim_mode is not helper_pll nor main_pll")
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
print("running simulation...")
|
||||||
|
self.period_err, self.phase_err, self.helper_adpll, self.main_adpll, self.gtx_beating, self.main_beating, self.helper, self.main, self.helperfreq, self.mainfreq = simulation_jit(
|
||||||
|
self.time,
|
||||||
|
self.gtx,
|
||||||
|
self.helper_pll,
|
||||||
|
self.main_pll,
|
||||||
|
self.h_KP,
|
||||||
|
self.h_KI,
|
||||||
|
self.h_KD,
|
||||||
|
self.m_KP,
|
||||||
|
self.m_KI,
|
||||||
|
self.m_KD,
|
||||||
|
self.dcxo_freq,
|
||||||
|
self.dcxo_jitter_SD,
|
||||||
|
self.base_adpll,
|
||||||
|
self.N,
|
||||||
|
self.adpll_write_period,
|
||||||
|
self.blind_period,
|
||||||
|
self.start_up_delay,
|
||||||
|
self.cycle_slip_comp,
|
||||||
|
self.helper_init_freq
|
||||||
|
)
|
||||||
|
print("Done!")
|
Loading…
Reference in New Issue
Block a user