@@ -52,7 +52,11 @@ use crossbeam::channel::{bounded, Sender};
52
52
use events:: StreamingEvents ;
53
53
pub use events:: { NewDataHandler , RawChannelDataBlock , StreamingEvent } ;
54
54
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
+ } ;
56
60
use pico_device:: PicoDevice ;
57
61
use std:: {
58
62
collections:: HashMap , fmt, pin:: Pin , sync:: Arc , thread, thread:: JoinHandle , time:: Duration ,
@@ -61,14 +65,25 @@ use tracing::*;
61
65
62
66
mod events;
63
67
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
+
64
82
#[ derive( Debug , Clone ) ]
65
83
pub struct SetSigGenArbitraryProperties {
66
84
pub offset_voltage : i32 , /* microvolts */
67
85
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 ,
72
87
pub arbitrary_waveform : Vec < i16 > ,
73
88
pub sweep_type : PicoSweepType ,
74
89
pub extra_operations : PicoExtraOperations ,
@@ -83,10 +98,7 @@ impl Default for SetSigGenArbitraryProperties {
83
98
SetSigGenArbitraryProperties {
84
99
offset_voltage : 0 ,
85
100
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 ( ) ,
90
102
arbitrary_waveform : vec ! [ 1 , 1 , 1 , 1 , 0 , 0 , 0 , 0 ] ,
91
103
sweep_type : PicoSweepType :: Up ,
92
104
extra_operations : PicoExtraOperations :: Off ,
@@ -667,6 +679,30 @@ impl PicoStreamingDevice {
667
679
)
668
680
}
669
681
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
+
670
706
#[ tracing:: instrument( skip( self ) , level = "trace" ) ]
671
707
pub fn set_sig_gen_arbitrary (
672
708
& self ,
@@ -691,18 +727,40 @@ impl PicoStreamingDevice {
691
727
} ,
692
728
} ;
693
729
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
+
694
752
self . device . driver . set_sig_gen_arbitrary (
695
753
handle,
696
754
props. offset_voltage ,
697
755
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,
702
760
& props. arbitrary_waveform ,
703
761
props. sweep_type ,
704
762
props. extra_operations ,
705
- PicoIndexMode :: Single ,
763
+ index_mode ,
706
764
props. sweeps_shots ,
707
765
props. trig_type ,
708
766
props. trig_source ,
0 commit comments