1
0
Fork 0

WRPLL: remove anti-windup

This commit is contained in:
morgan 2024-05-07 16:34:44 +08:00
parent 8409788158
commit 4700d4c9ed
1 changed files with 4 additions and 8 deletions

View File

@ -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;