Revert "rpll: auto-align counter"

This reverts commit dbacc5293e12f712fef7bd85848e1b0bd8fde823.
master
Robert Jördens 2021-01-27 09:00:48 +01:00
parent 45e7d6de3c
commit 1749d48ca3
2 changed files with 5 additions and 15 deletions

View File

@ -18,12 +18,14 @@ impl RPLL {
///
/// Args:
/// * dt2: inverse update() rate. 1 << dt2 is the counter rate to update() rate ratio.
/// * t: Counter time. Counter value at the first update() call. Typically 0.
///
/// Returns:
/// Initialized RPLL instance.
pub fn new(dt2: u8) -> RPLL {
pub fn new(dt2: u8, t: i32) -> RPLL {
RPLL {
dt2,
t,
..Default::default()
}
}
@ -67,19 +69,7 @@ impl RPLL {
// Update frequency lock
self.ff = self.ff.wrapping_add(p_ref.wrapping_sub(p_sig));
// Time in counter cycles between timestamp and "now"
let mut dt = self.t.wrapping_sub(x);
if dt < 0 {
// Timestamp is in the future
// Advance phase and time until we are just past the most recent
// timestamp.
let mut dt_ceil = dt >> self.dt2;
self.y = self.y.wrapping_sub(self.f.wrapping_mul(dt_ceil));
dt_ceil <<= self.dt2;
self.t = self.t.wrapping_sub(dt_ceil);
dt = dt.wrapping_sub(dt_ceil);
}
let dt = self.t.wrapping_sub(x);
// Reference phase estimate "now"
let y_ref = (self.f >> self.dt2).wrapping_mul(dt);
// Phase error

View File

@ -53,7 +53,7 @@ const APP: () = {
// Configure the microcontroller
let (mut stabilizer, _pounder) = hardware::setup(c.core, c.device);
let pll = RPLL::new(ADC_SAMPLE_TICKS_LOG2 + SAMPLE_BUFFER_SIZE_LOG2);
let pll = RPLL::new(ADC_SAMPLE_TICKS_LOG2 + SAMPLE_BUFFER_SIZE_LOG2, 0);
let lockin = Lockin::new(
&iir_int::IIRState::lowpass(1e-3, 0.707, 2.), // TODO: expose