Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AWG - RFC #8

Open
wants to merge 34 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
45a98ed
add call to ps2000aSetSigGenArbitrary via PicoDriver::set_sig_gen_arb…
alon Apr 7, 2022
1ba95cf
now get BUSY
alefminus Apr 7, 2022
71108f1
add sig_gen_built_in_v2
alefminus Apr 7, 2022
b331e24
export software trigger, and built in properties change - missing awg…
alon Apr 11, 2022
15182ca
add wave_type enum
alon Apr 11, 2022
481c05b
enums: white space fixes, remove duplicate enum name in variants
alon Apr 11, 2022
4637a7a
add some documentation from the sdk
alon Apr 11, 2022
8343a53
make PicoSigGenTrigSource comparable for egui radio_button
alon Apr 11, 2022
9e59f0a
enums: sig_gen related: shorten variants to remove enum prefix
alon Apr 12, 2022
8932505
remove streaming wrappers for sig_gen_software_control - confusing, m…
alon Apr 12, 2022
9551fde
introduce SweepShotCount to use an enum for the special 2^32-1 value
alon Apr 12, 2022
d433b2f
streaming/set_sig_gen_built_in_v2: return PicoResult
alon Apr 12, 2022
d342db3
siggen: better shots/sweeps encoding using a rust enum
alon Apr 12, 2022
d381c30
prelude: expose PicoResult
alon Apr 12, 2022
b4d501c
add SetSigGenArbitraryProperties
alon Apr 13, 2022
a99ec8f
add sig_gen_arbitrary_min_max_values
alefminus Apr 13, 2022
05f47ed
expose sig_gen
alon Apr 13, 2022
98be072
add phase_props
alefminus Apr 17, 2022
4435735
add sig_gen_frequency_to_phase
alefminus Apr 17, 2022
f73f939
exporet MinMaxArbitraryValues
alefminus Apr 17, 2022
d780c32
add ps2000a sig_gen_frequency_to_phase
alefminus Apr 17, 2022
cacbe6c
fix typo
alon Apr 17, 2022
4cd5631
add Default trait impl for some enums
alon Apr 18, 2022
74a0ddb
move sig-gen types into sig-gen module, add property struct for sig-g…
alon Apr 20, 2022
e8b4dd0
remove cloning of arbitrary waveform, and a todo
alefminus May 24, 2022
9f4f8fa
ps2000a: slight refactor to show addition for signal generation
alefminus May 24, 2022
8875bff
implement signal generation API for PS4000A (tested on 4824)
alefminus May 24, 2022
1a9ae87
wip: panic in set_sig_gen_arbitrary if called in open mode - since we…
alefminus May 24, 2022
22c74bd
streaming/lib: add PartialEq<Target> for State
alefminus May 24, 2022
9420957
PicoStreamingDevice: add pub wait_for_state_settle: TODO ask author
alefminus May 24, 2022
3b36026
bugfix awg: FOLD earlier: take read lock, not write, on current_state
alefminus May 24, 2022
d7403fa
wip add debug print
alefminus May 24, 2022
b988f5e
add dwell_count to SigGenArbitraryMinMaxValues
alefminus Feb 18, 2024
7663c57
formatter churn
alefminus Feb 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ mod error;
mod range;
mod status;
mod utils;
mod sig_gen;

pub use config::*;
pub use driver::*;
Expand All @@ -21,3 +22,4 @@ pub use error::*;
pub use range::*;
pub use status::*;
pub use utils::*;
pub use sig_gen::*;
205 changes: 205 additions & 0 deletions common/src/sig_gen.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
use num_derive::{FromPrimitive, ToPrimitive};

#[derive(Debug, Clone, Copy, FromPrimitive, ToPrimitive)]
pub enum PicoWaveType {
Sine = 0,
Square = 1,
Triangle = 2,
RampUp = 3,
RampDown = 4,
Sinc = 5,
Gaussian = 6,
HalfSine = 7,
DCVoltage = 8,
}

impl Default for PicoWaveType {
fn default() -> Self {
PicoWaveType::Sine
}
}

#[derive(Debug, Clone, Copy, FromPrimitive, ToPrimitive)]
pub enum PicoSweepType {
Up = 0,
Down = 1,
UpDown = 2,
DownUp = 3,
}

impl Default for PicoSweepType {
fn default() -> Self {
PicoSweepType::Up
}
}

#[derive(Debug, Clone)]
pub struct SigGenArbitraryMinMaxValues {
pub min_value: i16,
pub max_value: i16,
pub min_size: u32,
pub max_size: u32,
pub dwell_count: u32,
}

// Rust addition: encode the potential values of sweeps and shots, to avoid invalid states
// like >0 & >0
#[derive(Debug, Clone)]
pub enum SweepShotCount {
None,
Sweeps(u32),
Shots(u32),
ContinuousSweeps,
ContinuousShots,
}

impl Default for SweepShotCount {
fn default() -> Self {
SweepShotCount::None
}
}

// TODO: this value is copied from sys/src/ps2000a - should we import it here?
// should there be a crate for identical symbols?
// should build.rs check for identity?
const COPY_PS2000A_SHOT_SWEEP_TRIGGER_CONTINUOUS_RUN: u32 = 4294967295;

impl SweepShotCount {
pub fn to_sweeps(&self) -> u32 {
match self {
SweepShotCount::Sweeps(sweeps) => *sweeps,
SweepShotCount::ContinuousSweeps => COPY_PS2000A_SHOT_SWEEP_TRIGGER_CONTINUOUS_RUN,
_ => 0,
}
}

pub fn to_shots(&self) -> u32 {
match self {
SweepShotCount::Shots(shots) => *shots,
SweepShotCount::ContinuousShots => COPY_PS2000A_SHOT_SWEEP_TRIGGER_CONTINUOUS_RUN,
_ => 0,
}
}
}

#[derive(Debug, Clone, Copy, FromPrimitive, ToPrimitive)]
pub enum PicoExtraOperations {
/// <summary>
/// Normal signal generator operation specified by wavetype.
/// </summary>
Off = 0,
/// <summary>
/// The signal generator produces white noise and ignores all settings except pkToPk and offsetVoltage.
/// </summary>
WhiteNoise = 1,
/// <summary>
/// produces a pseudorandom random binary sequence with a bit rate
/// specified by the start and stop frequency.
/// </summary>
PRBS = 2, // Pseudo-Random Bit Stream
}

impl Default for PicoExtraOperations {
fn default() -> Self {
PicoExtraOperations::Off
}
}

/// <summary>
/// AWG index modes
/// </summary>
#[derive(Debug, Clone, Copy, FromPrimitive, ToPrimitive)]
pub enum PicoIndexMode {
/// <summary>
/// The generator outputs the raw contents of the buffer repeatedly .
/// </summary>
Single = 0,
/// <summary>
/// The generator outputs the contents of the buffer from beginning to end, and then does a second pass in the reverse
/// direction through the buffer
/// </summary>
Dual = 1,
/// <summary>
/// This is similiar to the Dual but passes through the buffer four time inverting, and inverting reversed
/// </summary>
Quad = 2,
}

/// <summary>
/// The type of trigger that will be applied to the signal generator
/// </summary>
#[derive(Debug, Clone, Copy, FromPrimitive, ToPrimitive)]
pub enum PicoSigGenTrigType {
/// <summary>
/// Trigger on rising edge
/// </summary>
Rising = 0,
/// <summary>
/// Trigger on falling edge
/// </summary>
Falling = 1,
/// <summary>
/// Run while trigger is high
/// </summary>
GateHigh = 2,
/// <summary>
/// Run while trigger is low
/// </summary>
GateLow = 3,
}

impl Default for PicoSigGenTrigType {
fn default() -> Self {
PicoSigGenTrigType::Rising
}
}

/// <summary>
/// The source that will trigger the signal generator
/// </summary>
#[derive(Debug, Clone, Copy, FromPrimitive, ToPrimitive, PartialEq)]
pub enum PicoSigGenTrigSource {
/// <summary>
/// Run without waiting for trigger
/// </summary>
None = 0,
/// <summary>
/// Use scope trigger
/// </summary
ScopeTrig = 1,
/// <summary>
/// Use AUXIO input
/// </summary>
AuxIn = 2,
/// <summary>
/// Use external input
/// </summary>
ExtIn = 3,
/// <summary>
/// Wait for software trigger
/// </summary>
SoftTrig = 4,
}

impl Default for PicoSigGenTrigSource {
fn default() -> Self {
PicoSigGenTrigSource::None
}
}

#[derive(Default, Debug)]
pub struct SetSigGenBuiltInV2Properties {
pub offset_voltage: i32, /* microvolts */
pub pk_to_pk: u32, /* microvolts */
pub wave_type: PicoWaveType,
pub start_frequency: f64, /* Hertz */
pub stop_frequency: f64, /* Hertz */
pub increment: f64, /* delta frequency jumps in Hertz */
pub dwell_time: f64, /* amount to stay at each frequency in seconds */
pub sweep_type: PicoSweepType,
pub extra_operations: PicoExtraOperations,
pub sweeps_shots: SweepShotCount,
pub trig_type: PicoSigGenTrigType,
pub trig_source: PicoSigGenTrigSource,
pub ext_in_threshold: i16,
}
78 changes: 76 additions & 2 deletions driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@

use parking_lot::RwLock;
use pico_common::{
ChannelConfig, Driver, FromPicoStr, PicoChannel, PicoError, PicoInfo, PicoRange, PicoResult,
SampleConfig,
ChannelConfig, Driver, FromPicoStr, PicoChannel, PicoError, PicoInfo, PicoRange, PicoResult, SampleConfig,
PicoSweepType, PicoExtraOperations, PicoIndexMode, PicoSigGenTrigType, PicoSigGenTrigSource,
SweepShotCount, SigGenArbitraryMinMaxValues, SetSigGenBuiltInV2Properties,
};
pub use resolution::Resolution;
use std::{fmt, pin::Pin, sync::Arc};
Expand Down Expand Up @@ -159,6 +160,79 @@ pub trait PicoDriver: fmt::Debug + Send + Sync {
Ok(())
}
}

#[tracing::instrument(level = "trace", skip(self))]
fn set_sig_gen_properties_built_in(
&self,
_handle: i16,
_start_frequency: f64,
_stop_frequency: f64,
_increment: f64,
_dwell_time: f64,
_sweep_type: PicoSweepType,
_sweeps_shots: SweepShotCount,
_trigger_type: PicoSigGenTrigType,
_trigger_source: PicoSigGenTrigSource,
_ext_in_threshold: i16
) -> PicoResult<()> {
unimplemented!()
}

#[tracing::instrument(level = "trace", skip(self))]
fn sig_gen_software_control(
&self,
_handle: i16,
_state: i16,
) -> PicoResult<()> {
unimplemented!()
}

#[tracing::instrument(level = "trace", skip(self))]
fn set_sig_gen_built_in_v2(
&self,
_handle: i16,
_props: SetSigGenBuiltInV2Properties
) -> PicoResult<()> {
unimplemented!()
}

fn set_sig_gen_arbitrary(
&self,
_handle: i16,
_offset_voltage: i32,
_pk_to_pk: u32,
_start_delta_phase: u32,
_stop_delta_phase: u32,
_delta_phase_increment: u32,
_dwell_count: u32,
_arbitrary_waveform: &mut Vec<i16>,
_sweep_type: PicoSweepType,
_operation: PicoExtraOperations,
_index_mode: PicoIndexMode,
_sweeps_shots: SweepShotCount,
_trigger_type: PicoSigGenTrigType,
_trigger_source: PicoSigGenTrigSource,
_ext_in_threshold: i16,
) -> PicoResult<()> {
unimplemented!()
}

fn sig_gen_arbitrary_min_max_values(
&self,
_handle: i16,
) -> PicoResult<SigGenArbitraryMinMaxValues> {
unimplemented!();
}

fn sig_gen_frequency_to_phase(
&self,
_handle: i16,
_frequency: f64,
_index_mode: PicoIndexMode,
_buffer_length: u32,
) -> PicoResult<u32> {
unimplemented!();
}
}

pub type ArcDriver = Arc<dyn PicoDriver>;
Expand Down
Loading