lockin: remove feed()
This commit is contained in:
parent
90bd4741cc
commit
65a3f839a0
@ -1,6 +1,6 @@
|
|||||||
use super::{
|
use super::{
|
||||||
iir_int::{Vec5, IIR},
|
iir_int::{Vec5, IIR},
|
||||||
Accu, Complex,
|
Complex,
|
||||||
};
|
};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
@ -41,20 +41,4 @@ impl Lockin {
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Feed an iterator into the Lockin and return the latest I/Q data.
|
|
||||||
/// Initial stample phase and frequency (phase increment between samples)
|
|
||||||
/// are supplied.
|
|
||||||
pub fn feed<I: IntoIterator<Item = i32>>(
|
|
||||||
&mut self,
|
|
||||||
signal: I,
|
|
||||||
phase: i32,
|
|
||||||
frequency: i32,
|
|
||||||
) -> Option<Complex<i32>> {
|
|
||||||
signal
|
|
||||||
.into_iter()
|
|
||||||
.zip(Accu::new(phase, frequency))
|
|
||||||
.map(|(sample, phase)| self.update(sample, phase))
|
|
||||||
.last()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ use stabilizer::{
|
|||||||
hardware, server, ADC_SAMPLE_TICKS_LOG2, SAMPLE_BUFFER_SIZE_LOG2,
|
hardware, server, ADC_SAMPLE_TICKS_LOG2, SAMPLE_BUFFER_SIZE_LOG2,
|
||||||
};
|
};
|
||||||
|
|
||||||
use dsp::{iir, iir_int, lockin::Lockin, rpll::RPLL};
|
use dsp::{iir, iir_int, lockin::Lockin, rpll::RPLL, Accu};
|
||||||
use hardware::{
|
use hardware::{
|
||||||
Adc0Input, Adc1Input, Dac0Output, Dac1Output, InputStamper, AFE0, AFE1,
|
Adc0Input, Adc1Input, Dac0Output, Dac1Output, InputStamper, AFE0, AFE1,
|
||||||
};
|
};
|
||||||
@ -133,13 +133,15 @@ const APP: () = {
|
|||||||
let sample_phase =
|
let sample_phase =
|
||||||
phase_offset.wrapping_add(pll_phase.wrapping_mul(harmonic));
|
phase_offset.wrapping_add(pll_phase.wrapping_mul(harmonic));
|
||||||
|
|
||||||
if let Some(output) = lockin.feed(
|
if let Some(output) = adc_samples[0]
|
||||||
adc_samples[0].iter().map(|&i|
|
.iter()
|
||||||
|
.zip(Accu::new(sample_phase, sample_frequency))
|
||||||
// Convert to signed, MSB align the ADC sample.
|
// Convert to signed, MSB align the ADC sample.
|
||||||
(i as i16 as i32) << 16),
|
.map(|(&sample, phase)| {
|
||||||
sample_phase,
|
lockin.update((sample as i16 as i32) << 16, phase)
|
||||||
sample_frequency,
|
})
|
||||||
) {
|
.last()
|
||||||
|
{
|
||||||
// Convert from IQ to power and phase.
|
// Convert from IQ to power and phase.
|
||||||
let mut power = output.abs_sqr() as _;
|
let mut power = output.abs_sqr() as _;
|
||||||
let mut phase = output.arg() as _;
|
let mut phase = output.arg() as _;
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
const DAC_SEQUENCE: [f32; 8] =
|
const DAC_SEQUENCE: [f32; 8] =
|
||||||
[0.0, 0.707, 1.0, 0.707, 0.0, -0.707, -1.0, -0.707];
|
[0.0, 0.707, 1.0, 0.707, 0.0, -0.707, -1.0, -0.707];
|
||||||
|
|
||||||
use dsp::{iir_int, lockin::Lockin};
|
use dsp::{iir_int, lockin::Lockin, Accu};
|
||||||
use hardware::{Adc1Input, Dac0Output, Dac1Output, AFE0, AFE1};
|
use hardware::{Adc1Input, Dac0Output, Dac1Output, AFE0, AFE1};
|
||||||
use stabilizer::hardware;
|
use stabilizer::hardware;
|
||||||
|
|
||||||
@ -66,6 +66,7 @@ const APP: () = {
|
|||||||
/// TODO: Document
|
/// TODO: Document
|
||||||
#[task(binds=DMA1_STR4, resources=[adc1, dacs, lockin], priority=2)]
|
#[task(binds=DMA1_STR4, resources=[adc1, dacs, lockin], priority=2)]
|
||||||
fn process(c: process::Context) {
|
fn process(c: process::Context) {
|
||||||
|
let lockin = c.resources.lockin;
|
||||||
let adc_samples = c.resources.adc1.acquire_buffer();
|
let adc_samples = c.resources.adc1.acquire_buffer();
|
||||||
let dac_samples = [
|
let dac_samples = [
|
||||||
c.resources.dacs.0.acquire_buffer(),
|
c.resources.dacs.0.acquire_buffer(),
|
||||||
@ -96,13 +97,15 @@ const APP: () = {
|
|||||||
let sample_phase = phase_offset
|
let sample_phase = phase_offset
|
||||||
.wrapping_add((pll_phase as i32).wrapping_mul(harmonic));
|
.wrapping_add((pll_phase as i32).wrapping_mul(harmonic));
|
||||||
|
|
||||||
if let Some(output) = c.resources.lockin.feed(
|
if let Some(output) = adc_samples
|
||||||
adc_samples.iter().map(|&i|
|
.iter()
|
||||||
|
.zip(Accu::new(sample_phase, sample_frequency))
|
||||||
// Convert to signed, MSB align the ADC sample.
|
// Convert to signed, MSB align the ADC sample.
|
||||||
(i as i16 as i32) << 16),
|
.map(|(&sample, phase)| {
|
||||||
sample_phase,
|
lockin.update((sample as i16 as i32) << 16, phase)
|
||||||
sample_frequency,
|
})
|
||||||
) {
|
.last()
|
||||||
|
{
|
||||||
// Convert from IQ to power and phase.
|
// Convert from IQ to power and phase.
|
||||||
let _power = output.abs_sqr();
|
let _power = output.abs_sqr();
|
||||||
let phase = output.arg() >> 16;
|
let phase = output.arg() >> 16;
|
||||||
|
Loading…
Reference in New Issue
Block a user