Skip to content

Commit 98be072

Browse files
committed
add phase_props
1 parent 05f47ed commit 98be072

File tree

1 file changed

+72
-14
lines changed

1 file changed

+72
-14
lines changed

streaming/src/lib.rs

Lines changed: 72 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ use crossbeam::channel::{bounded, Sender};
5252
use events::StreamingEvents;
5353
pub use events::{NewDataHandler, RawChannelDataBlock, StreamingEvent};
5454
use parking_lot::RwLock;
55-
use pico_common::{ChannelConfig, PicoChannel, PicoCoupling, PicoRange, PicoResult, PicoStatus, SampleConfig, PicoSweepType, PicoExtraOperations, PicoIndexMode, PicoSigGenTrigType, PicoSigGenTrigSource, PicoWaveType, SweepShotCount};
55+
use pico_common::{
56+
ChannelConfig, PicoChannel, PicoCoupling, PicoRange, PicoResult, PicoStatus, SampleConfig,
57+
PicoSweepType, PicoExtraOperations, PicoIndexMode, PicoSigGenTrigType, PicoSigGenTrigSource, PicoWaveType,
58+
SweepShotCount, SigGenArbitraryMinMaxValues,
59+
};
5660
use pico_device::PicoDevice;
5761
use std::{
5862
collections::HashMap, fmt, pin::Pin, sync::Arc, thread, thread::JoinHandle, time::Duration,
@@ -61,14 +65,25 @@ use tracing::*;
6165

6266
mod events;
6367

68+
#[derive(Debug, Clone)]
69+
pub enum SetSigGenArbitraryPhaseProperties {
70+
PhasesFull { start: u32, stop: u32, increment: u32, dwell_count: u32},
71+
// TODO: FrequencyHzSweep { start: f64, stop: f64, increment: f64, duration_secs: f64}
72+
FrequencyConstantHz(f64),
73+
}
74+
75+
impl Default for SetSigGenArbitraryPhaseProperties {
76+
fn default() -> Self {
77+
SetSigGenArbitraryPhaseProperties::FrequencyConstantHz(10.0)
78+
}
79+
}
80+
81+
6482
#[derive(Debug, Clone)]
6583
pub struct SetSigGenArbitraryProperties {
6684
pub offset_voltage: i32, /* microvolts */
6785
pub pk_to_pk: u32, /* microvolts */
68-
pub start_delta_phase: u32,
69-
pub stop_delta_phase: u32,
70-
pub delta_phase_increment: u32,
71-
pub dwell_count: u32,
86+
pub phase_props: SetSigGenArbitraryPhaseProperties,
7287
pub arbitrary_waveform: Vec<i16>,
7388
pub sweep_type: PicoSweepType,
7489
pub extra_operations: PicoExtraOperations,
@@ -83,10 +98,7 @@ impl Default for SetSigGenArbitraryProperties {
8398
SetSigGenArbitraryProperties {
8499
offset_voltage: 0,
85100
pk_to_pk: 200_000,
86-
start_delta_phase: 0,
87-
stop_delta_phase: 0,
88-
delta_phase_increment: 0,
89-
dwell_count: 1,
101+
phase_props: Default::default(),
90102
arbitrary_waveform: vec![1, 1, 1, 1, 0, 0, 0, 0],
91103
sweep_type: PicoSweepType::Up,
92104
extra_operations: PicoExtraOperations::Off,
@@ -667,6 +679,30 @@ impl PicoStreamingDevice {
667679
)
668680
}
669681

682+
#[tracing::instrument(skip(self), level = "trace")]
683+
pub fn sig_gen_arbitrary_min_max_values(
684+
&self
685+
) -> PicoResult<SigGenArbitraryMinMaxValues> {
686+
let current_state = self.current_state.write();
687+
let handle = match current_state.clone() {
688+
State::Closed => {
689+
panic!("attempt to sig gen on closed device, no handle");
690+
}
691+
State::Open {
692+
handle
693+
} => {
694+
handle
695+
},
696+
State::Streaming {
697+
handle,
698+
..
699+
} => {
700+
handle
701+
},
702+
};
703+
self.device.driver.sig_gen_arbitrary_min_max_values(handle)
704+
}
705+
670706
#[tracing::instrument(skip(self), level = "trace")]
671707
pub fn set_sig_gen_arbitrary(
672708
&self,
@@ -691,18 +727,40 @@ impl PicoStreamingDevice {
691727
},
692728
};
693729

730+
let index_mode = PicoIndexMode::Single;
731+
732+
// check that we are within limits
733+
let min_max = self.device.driver.sig_gen_arbitrary_min_max_values(handle)?;
734+
let min_size = min_max.min_size as usize;
735+
let max_size = min_max.max_size as usize;
736+
let n = props.arbitrary_waveform.len();
737+
if min_size > n || max_size < n {
738+
tracing::trace!(min_size = min_size, max_size = max_size, size = n);
739+
return Err(PicoStatus::AWG_NOT_SUPPORTED.into());
740+
}
741+
742+
let (start_delta_phase, stop_delta_phase, delta_phase_increment, dwell_count) = match props.phase_props {
743+
SetSigGenArbitraryPhaseProperties::FrequencyConstantHz(freq_hz) => {
744+
let phase = self.device.driver.sig_gen_frequency_to_phase(handle, freq_hz, index_mode, n as u32)?;
745+
(phase, phase, 0, 0)
746+
},
747+
SetSigGenArbitraryPhaseProperties::PhasesFull { start, stop, increment, dwell_count } => {
748+
(start, stop, increment, dwell_count)
749+
}
750+
};
751+
694752
self.device.driver.set_sig_gen_arbitrary(
695753
handle,
696754
props.offset_voltage,
697755
props.pk_to_pk,
698-
props.start_delta_phase,
699-
props.stop_delta_phase,
700-
props.delta_phase_increment,
701-
props.dwell_count,
756+
start_delta_phase,
757+
stop_delta_phase,
758+
delta_phase_increment,
759+
dwell_count,
702760
&props.arbitrary_waveform,
703761
props.sweep_type,
704762
props.extra_operations,
705-
PicoIndexMode::Single,
763+
index_mode,
706764
props.sweeps_shots,
707765
props.trig_type,
708766
props.trig_source,

0 commit comments

Comments
 (0)