From 9a3c9afa7ec11549f29e3f81f80e80c55eb7d55e Mon Sep 17 00:00:00 2001 From: Matt Huszagh Date: Thu, 14 Jan 2021 14:47:55 -0800 Subject: [PATCH] fix reciprocal_pll divide error when reference frequency is 0 --- dsp/src/reciprocal_pll.rs | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/dsp/src/reciprocal_pll.rs b/dsp/src/reciprocal_pll.rs index eaeaac7..d06abbb 100644 --- a/dsp/src/reciprocal_pll.rs +++ b/dsp/src/reciprocal_pll.rs @@ -62,18 +62,26 @@ impl TimestampHandler { self.reference_frequency = frequency as u32 as i64; } - let demodulation_frequency = divide_round( - 1 << (32 + self.adc_sample_ticks_log2), - self.reference_frequency, - ) as u32; - let demodulation_initial_phase = divide_round( - (((self.batch_index as i64) - << (self.adc_sample_ticks_log2 - + self.sample_buffer_size_log2)) - - self.reference_phase) - << 32, - self.reference_frequency, - ) as u32; + let demodulation_frequency: u32; + let demodulation_initial_phase: u32; + + if self.reference_frequency == 0 { + demodulation_frequency = u32::MAX; + demodulation_initial_phase = u32::MAX; + } else { + demodulation_frequency = divide_round( + 1 << (32 + self.adc_sample_ticks_log2), + self.reference_frequency, + ) as u32; + demodulation_initial_phase = divide_round( + (((self.batch_index as i64) + << (self.adc_sample_ticks_log2 + + self.sample_buffer_size_log2)) + - self.reference_phase) + << 32, + self.reference_frequency, + ) as u32; + } if self.batch_index < (1 << (32