mirror of
https://github.com/hubaldv/bioz-firmware-rs.git
synced 2025-12-06 05:01:18 +00:00
Change multi to sweep.
This commit is contained in:
@@ -16,11 +16,11 @@ use num::complex::Complex;
|
||||
use crate::ad5940::*;
|
||||
use crate::ad5940_registers::*;
|
||||
|
||||
use bioz_icd_rs::{SingleImpedanceOutput, IcdDftNum, ImpedanceInitError, MeasurementPointSet, MultiImpedanceOutput};
|
||||
use bioz_icd_rs::{SingleImpedanceOutput, IcdDftNum, ImpedanceInitError, MeasurementPointSet, SweepImpedanceOutput};
|
||||
use crate::icd_mapping::IntoDftnum;
|
||||
|
||||
pub static IMPEDANCE_CHANNEL_SINGLE: Channel<ThreadModeRawMutex, SingleImpedanceOutput, 50> = Channel::new();
|
||||
pub static IMPEDANCE_CHANNEL_MULTI: Channel<ThreadModeRawMutex, MultiImpedanceOutput, 5> = Channel::new();
|
||||
pub static IMPEDANCE_CHANNEL_SWEEP: Channel<ThreadModeRawMutex, SweepImpedanceOutput, 5> = Channel::new();
|
||||
|
||||
pub type ImpedanceSetupType = Mutex<ThreadModeRawMutex, ImpedanceSetup>;
|
||||
pub static IMPEDANCE_SETUP: StaticCell<ImpedanceSetupType> = StaticCell::new();
|
||||
@@ -32,8 +32,8 @@ pub enum RunningMode {
|
||||
None,
|
||||
SingleFrequency2Lead,
|
||||
SingleFrequency4Lead,
|
||||
MultiFrequency2Lead(MeasurementPointSet),
|
||||
MultiFrequency4Lead(MeasurementPointSet),
|
||||
SweepFrequency2Lead(MeasurementPointSet),
|
||||
SweepFrequency4Lead(MeasurementPointSet),
|
||||
}
|
||||
|
||||
pub enum RtiaCalibrated {
|
||||
@@ -303,7 +303,7 @@ impl ImpedanceSetup {
|
||||
if let Some(dsp_config) = &self.dsp_config {
|
||||
wait_time = self.ad5940.sequencer_calculate_wait_time(dsp_config).await.unwrap();
|
||||
sinus_periods_per_dft = wait_time as f32 / dsp_config.fsys.unwrap() as f32 * frequency as f32;
|
||||
info!("Sinus periods per DFT: {}", sinus_periods_per_dft);
|
||||
// info!("Sinus periods per DFT: {}", sinus_periods_per_dft);
|
||||
} else {
|
||||
error!("DSP configuration not set, cannot calculate wait time");
|
||||
return Err(ImpedanceInitError::DSPNotSet);
|
||||
@@ -385,7 +385,7 @@ impl ImpedanceSetup {
|
||||
if let Some(dsp_config) = &self.dsp_config {
|
||||
wait_time = self.ad5940.sequencer_calculate_wait_time(dsp_config).await.unwrap();
|
||||
sinus_periods_per_dft = wait_time as f32 / dsp_config.fsys.unwrap() as f32 * frequency as f32;
|
||||
info!("Sinus periods per DFT: {}", sinus_periods_per_dft);
|
||||
// info!("Sinus periods per DFT: {}", sinus_periods_per_dft);
|
||||
} else {
|
||||
error!("DSP configuration not set, cannot calculate wait time");
|
||||
return Err(ImpedanceInitError::DSPNotSet);
|
||||
@@ -464,7 +464,7 @@ impl ImpedanceSetup {
|
||||
Ok(sinus_periods_per_dft)
|
||||
}
|
||||
|
||||
pub async fn init_multi_frequency_measurement_2_lead<const N: usize>(&mut self, number_of_points: MeasurementPointSet) -> Result<heapless::Vec<f32, N>, ImpedanceInitError> {
|
||||
pub async fn init_sweep_frequency_measurement_2_lead<const N: usize>(&mut self, number_of_points: MeasurementPointSet) -> Result<heapless::Vec<f32, N>, ImpedanceInitError> {
|
||||
// Configure LP DAC and TIA
|
||||
self.common_mode_output_enable(false).await.unwrap();
|
||||
|
||||
@@ -511,7 +511,7 @@ impl ImpedanceSetup {
|
||||
let periods_per_dft = wait_time as f32 / dsp_config.fsys.unwrap() as f32 * frequency as f32;
|
||||
|
||||
periods_per_dft_vec.push(periods_per_dft).unwrap();
|
||||
info!("{}Hz: Sinus periods per DFT: {}", frequency, periods_per_dft);
|
||||
// info!("{}Hz: Sinus periods per DFT: {}", frequency, periods_per_dft);
|
||||
|
||||
} else {
|
||||
error!("DSP configuration not set, cannot calculate wait time");
|
||||
@@ -572,7 +572,7 @@ impl ImpedanceSetup {
|
||||
Ok(periods_per_dft_vec)
|
||||
}
|
||||
|
||||
pub async fn init_multi_frequency_measurement_4_lead<const N: usize>(&mut self, number_of_points: MeasurementPointSet) -> Result<heapless::Vec<f32, N>, ImpedanceInitError> {
|
||||
pub async fn init_sweep_frequency_measurement_4_lead<const N: usize>(&mut self, number_of_points: MeasurementPointSet) -> Result<heapless::Vec<f32, N>, ImpedanceInitError> {
|
||||
// Configure LP DAC and TIA
|
||||
self.common_mode_output_enable(true).await.unwrap();
|
||||
|
||||
@@ -631,8 +631,7 @@ impl ImpedanceSetup {
|
||||
let periods_per_dft = wait_time as f32 / dsp_config.fsys.unwrap() as f32 * frequency as f32;
|
||||
|
||||
periods_per_dft_vec.push(periods_per_dft).unwrap();
|
||||
info!("{}Hz: Sinus periods per DFT: {}", frequency, periods_per_dft);
|
||||
|
||||
// info!("{}Hz: Sinus periods per DFT: {}", frequency, periods_per_dft);
|
||||
} else {
|
||||
error!("DSP configuration not set, cannot calculate wait time");
|
||||
return Err(ImpedanceInitError::DSPNotSet);
|
||||
@@ -726,7 +725,7 @@ pub async fn impedance_setup_readout_task(mut pin: ExtiInput<'static>, impedance
|
||||
let mut impedance_setup = impedance_setup.lock().await;
|
||||
|
||||
// Trigger the sequencer again
|
||||
if impedance_setup.running_mode == RunningMode::SingleFrequency2Lead || impedance_setup.running_mode == RunningMode::SingleFrequency4Lead || impedance_setup.running_mode == RunningMode::MultiFrequency2Lead(MeasurementPointSet::Eight) || impedance_setup.running_mode == RunningMode::MultiFrequency2Lead(MeasurementPointSet::Eighteen) || impedance_setup.running_mode == RunningMode::MultiFrequency4Lead(MeasurementPointSet::Eight) || impedance_setup.running_mode == RunningMode::MultiFrequency4Lead(MeasurementPointSet::Eighteen) {
|
||||
if impedance_setup.running_mode == RunningMode::SingleFrequency2Lead || impedance_setup.running_mode == RunningMode::SingleFrequency4Lead || impedance_setup.running_mode == RunningMode::SweepFrequency2Lead(MeasurementPointSet::Eight) || impedance_setup.running_mode == RunningMode::SweepFrequency2Lead(MeasurementPointSet::Eighteen) || impedance_setup.running_mode == RunningMode::SweepFrequency4Lead(MeasurementPointSet::Eight) || impedance_setup.running_mode == RunningMode::SweepFrequency4Lead(MeasurementPointSet::Eighteen) {
|
||||
impedance_setup.start_measurement().await;
|
||||
}
|
||||
|
||||
@@ -780,7 +779,7 @@ pub async fn impedance_setup_readout_task(mut pin: ExtiInput<'static>, impedance
|
||||
}
|
||||
}
|
||||
}
|
||||
RunningMode::MultiFrequency2Lead(points) => {
|
||||
RunningMode::SweepFrequency2Lead(points) => {
|
||||
// Each frequency point produces 4 samples (DFT real/imag for Rcal and Rz)
|
||||
let required_count = points.len() * 4;
|
||||
|
||||
@@ -791,7 +790,7 @@ pub async fn impedance_setup_readout_task(mut pin: ExtiInput<'static>, impedance
|
||||
impedance_setup.read_fifo(data_slice).await.unwrap();
|
||||
|
||||
// Output structure
|
||||
let mut impedance_output = MultiImpedanceOutput {
|
||||
let mut impedance_output = SweepImpedanceOutput {
|
||||
points,
|
||||
magnitudes_8: Vec::new(),
|
||||
phases_8: Vec::new(),
|
||||
@@ -815,11 +814,11 @@ pub async fn impedance_setup_readout_task(mut pin: ExtiInput<'static>, impedance
|
||||
}
|
||||
}
|
||||
|
||||
IMPEDANCE_CHANNEL_MULTI.try_send(impedance_output).ok();
|
||||
IMPEDANCE_CHANNEL_SWEEP.try_send(impedance_output).ok();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
RunningMode::MultiFrequency4Lead(points) => {
|
||||
RunningMode::SweepFrequency4Lead(points) => {
|
||||
// Each frequency point produces 4 samples (DFT real/imag for Rcal and Rz)
|
||||
let required_count = points.len() * 4;
|
||||
|
||||
@@ -830,7 +829,7 @@ pub async fn impedance_setup_readout_task(mut pin: ExtiInput<'static>, impedance
|
||||
impedance_setup.read_fifo(data_slice).await.unwrap();
|
||||
|
||||
// Output structure
|
||||
let mut impedance_output = MultiImpedanceOutput {
|
||||
let mut impedance_output = SweepImpedanceOutput {
|
||||
points,
|
||||
magnitudes_8: Vec::new(),
|
||||
phases_8: Vec::new(),
|
||||
@@ -865,7 +864,7 @@ pub async fn impedance_setup_readout_task(mut pin: ExtiInput<'static>, impedance
|
||||
}
|
||||
}
|
||||
|
||||
IMPEDANCE_CHANNEL_MULTI.try_send(impedance_output).ok();
|
||||
IMPEDANCE_CHANNEL_SWEEP.try_send(impedance_output).ok();
|
||||
}
|
||||
continue;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user