From 39bb656f857733319773508221545d97bc1d076f Mon Sep 17 00:00:00 2001 From: morgan Date: Thu, 25 Jan 2024 16:34:26 +0800 Subject: [PATCH] sim: replace beating period error formula --- src/wrpll_simulation/timesim_node.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/wrpll_simulation/timesim_node.py b/src/wrpll_simulation/timesim_node.py index 7daec75..f641779 100644 --- a/src/wrpll_simulation/timesim_node.py +++ b/src/wrpll_simulation/timesim_node.py @@ -120,7 +120,6 @@ class EventManager_IRQ(object): @jitclass class Tag_Collector(object): setpt_beating_period: int64 - last_gtx: int32 gtx_tag_ready: bool gtx_tag: int32 @@ -129,7 +128,6 @@ class Tag_Collector(object): def __init__(self, setpt_beating_period: int64): self.setpt_beating_period = setpt_beating_period - self.last_gtx = 0 # for main PLL self.gtx_tag_ready = False @@ -138,7 +136,6 @@ class Tag_Collector(object): self.main_tag = 0 def collect_gtx_tag(self, tag: int32): - self.last_gtx = self.gtx self.gtx_tag = tag self.gtx_tag_ready = True @@ -147,7 +144,13 @@ class Tag_Collector(object): self.main_tag_ready = True def get_period_error(self) -> int32: - return self.set_phase_error_ready - (self.gtx - self.last_gtx) + # period_error = n * ideal_beating - GTX_tag(n) + period_error = (-self.gtx_tag) % self.setpt_beating_period + + if period_error > self.setpt_beating_period / 2: + return period_error - self.setpt_beating_period + + return period_error def get_phase_error(self) -> int32: # tag_diff = main_tag(n) - gtx_tag(n)