From 4700d4c9edc7c01b1923656c634816ca75c2a6c7 Mon Sep 17 00:00:00 2001 From: morgan Date: Tue, 7 May 2024 16:34:44 +0800 Subject: [PATCH] WRPLL: remove anti-windup --- src/libboard_artiq/src/si549.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/libboard_artiq/src/si549.rs b/src/libboard_artiq/src/si549.rs index 6384c57..00fd552 100644 --- a/src/libboard_artiq/src/si549.rs +++ b/src/libboard_artiq/src/si549.rs @@ -335,8 +335,6 @@ pub mod wrpll { const COUNTER_WIDTH: u32 = 24; const DIV_WIDTH: u32 = 2; - // 4 ppm capture range - const ADPLL_LIM: i32 = (4.0 / 0.0001164) as i32; // Low pass filter // y[n] = B0*x[n] + B1*x[n-1] + B2*x[n-2] - A1*y[n-1] - A2*y[n-2] const B0: f64 = 0.07209205036273991; @@ -535,10 +533,9 @@ pub mod wrpll { fn helper_pll() -> Result<(), &'static str> { let period_err = tag_collector::get_period_error(); unsafe { - let adpll = (((B0 * period_err as f64) + (B1 * PERIOD_ERR1 as f64) + (B2 * PERIOD_ERR2 as f64) + let adpll = ((B0 * period_err as f64) + (B1 * PERIOD_ERR1 as f64) + (B2 * PERIOD_ERR2 as f64) - (A1 * H_ADPLL1 as f64) - - (A2 * H_ADPLL2 as f64)) as i32) - .clamp(-ADPLL_LIM, ADPLL_LIM); + - (A2 * H_ADPLL2 as f64)) as i32; set_adpll(i2c::DCXO::Helper, BASE_ADPLL + adpll)?; H_ADPLL2 = H_ADPLL1; PERIOD_ERR2 = PERIOD_ERR1; @@ -551,10 +548,9 @@ pub mod wrpll { fn main_pll() -> Result<(), &'static str> { let phase_err = tag_collector::get_phase_error(); unsafe { - let adpll = (((B0 * phase_err as f64) + (B1 * PHASE_ERR1 as f64) + (B2 * PHASE_ERR2 as f64) + let adpll = ((B0 * phase_err as f64) + (B1 * PHASE_ERR1 as f64) + (B2 * PHASE_ERR2 as f64) - (A1 * M_ADPLL1 as f64) - - (A2 * M_ADPLL2 as f64)) as i32) - .clamp(-ADPLL_LIM, ADPLL_LIM); + - (A2 * M_ADPLL2 as f64)) as i32; set_adpll(i2c::DCXO::Main, BASE_ADPLL + adpll)?; M_ADPLL2 = M_ADPLL1; PHASE_ERR2 = PHASE_ERR1;