-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfast_diagrams.py
217 lines (185 loc) · 8.29 KB
/
fast_diagrams.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
from qcodes.utils.wrappers import do1d
import qcodes as qc
def prepare_measurement(keysight_low_V, keysight_high_V, scope_avger, qdac_fast_channel, npts, zi, add_offset: bool=True):
"""
Args:
keysight_low_V (float): keysight ramp start value
keysight_high_V (float): keysight ramp stop value
scope_avger (Scope_avg): The Scope_avg instance
qdac_fast_channel (int): The number of the QDac channel added to
the Keysight ramp
"""
zi.Scope.prepare_scope()
#npts = zi.scope_length()
offset = 0
if add_offset:
offset = qdac_fast_channel.get()
scope_avger.make_setpoints(keysight_low_V+offset, keysight_high_V+offset, npts)
scope_avger.setpoint_names = ('keysight_voltage',)
scope_avger.setpoint_labels = ('Fast {}'.format(qdac_fast_channel.label),)
scope_avger.setpoint_units = ('V',)
# zi.scope_avg_ch1.make_setpoints(keysight_low_V, keysight_high_V, npts)
# zi.scope_avg_ch1.setpoint_names = ('keysight_voltage',)
# zi.scope_avg_ch1.setpoint_labels = ('Keysight Voltage',)
# zi.scope_avg_ch1.setpoint_units = ('V', )
def fast_charge_diagram(keysight_channel, fast_v_start, fast_v_stop, n_averages,
qdac_channel, q_start, q_stop, npoints, delay, qdac_fast_channel, comp_scale,
scope_signal, zi_trig_signal='Trig Input 1',
trigger_holdoff=60e-6, zi_samplingrate='14.0 MHz', zi_scope_length=4096,
zi_trig_hyst=0, zi_trig_level=.5, zi_trig_delay = 0, print_settings=False,
keysight_voltage_multiplier=1, zi=None, keysight=None, tasks_to_perform=None):
"""
Args:
keysight_channel:
fast_v_start
fast_v_stop
keys_freq
n_averages
qdac_channel
q_start
q_stop
npoints:
delay:
zi_input_chan:
zi_trig_signal:
trigger_holdoff;
zi_samplingrate:
zi_trig_hyst:
zi_trig_level:
zi_trig_delay: Should be the rise time of your signal/trigger signal
For Keysight sawtooth it is 6e-7s.
keysight_voltage_multiplier: The actual voltage to the keysight is fast_v_start
and fast_v_stop multiplied by this number. I.e. if you have a voltage divider
between the keysight and your device that divides the voltage by 5. You should
set the fast_voltage_start and fast_voltage_stop to the values you want on the
device and the values sent to the keysight will be 5*fast_voltage_start and 5*fast_voltage_stop
"""
if zi is None:
zi = qc.Instrument.find_instrument('ziuhfli')
if keysight is None:
keysight = qc.Instrument.find_instrument('keysight_gen_left')
if keysight_channel not in ['ch01', 'ch02']:
raise ValueError('Invalid keysight channel. Must be either "ch01" or "ch02".')
if not isinstance(scope_signal, list):
scope_signal = [scope_signal]
if not scope_signal:
raise ValueError('Select valid scope signal(s).')
# In order to take thee hold off time of the uhfli into account
# we need to recalculate the scope duration, sawtooth amplitude
# and keysight frequency.
zi.scope_samplingrate.set(zi_samplingrate)
# KDP: allow for fewer points than the UHFLI 4096 min.
if zi_scope_length < 4096:
zi.scope_length.set(4096)
else:
zi.scope_length.set(zi_scope_length)
zi.daq.sync()
scope_duration = zi.scope_duration()
scope_duration_compensated = trigger_holdoff + scope_duration + zi_trig_delay
key_frequency = 1/scope_duration_compensated
asym = trigger_holdoff/scope_duration_compensated # dead time / meas. time
# # obsolete next line
# additional_sawtooth_amplitude = keysight_amplitude * ((trigger_holdoff)/scope_duration)
fast_v_start_scaled = keysight_voltage_multiplier * fast_v_start
fast_v_stop_scaled = keysight_voltage_multiplier * fast_v_stop
keysight_amplitude = abs(fast_v_stop_scaled-fast_v_start_scaled)
key_offset = fast_v_start_scaled + keysight_amplitude/2
# fast_v_start -= additional_sawtooth_amplitude
zi.scope_channels(3)
zi.scope_trig_holdoffseconds.set(trigger_holdoff)
zi.scope_trig_enable.set('ON')
zi.scope_trig_signal.set(zi_trig_signal)
zi.scope_trig_slope.set('Rise')
zi.scope_trig_hystmode('absolute')
zi.scope_trig_hystabsolute.set(zi_trig_hyst)
zi.scope_trig_gating_enable.set('OFF')
zi.scope_trig_holdoffmode.set('s')
zi.scope_trig_reference.set(0)
zi.scope_segments('ON')
zi.scope_segments_count(n_averages)
zi.scope_trig_level.set(zi_trig_level)
zi.scope_trig_delay.set(zi_trig_delay)
zi.daq.sync()
if keysight_channel == 'ch01':
keysight.ch1_function_type('RAMP')
keysight.ch1_ramp_symmetry(100*(1-asym))
keysight.ch1_phase(180*(1+asym))
keysight.ch1_amplitude_unit('VPP')
keysight.ch1_amplitude(keysight_amplitude)
keysight.ch1_offset(key_offset)
keysight.ch1_frequency(key_frequency)
keysight.sync_source(1)
keysight.ch1_output('ON')
#KDP setup Ch2 for compensating sensor
# Channels should be coupled, ch 2 output inverted
keysight.ch2_function_type('RAMP')
keysight.ch2_ramp_symmetry(100*(1-asym))
keysight.ch2_phase(180*(1+asym))
keysight.ch2_output_polarity('INV')
keysight.ch2_amplitude_unit('VPP')
keysight.ch2_amplitude(keysight_amplitude*comp_scale)
keysight.ch2_frequency(key_frequency)
keysight.ch2_output('ON')
keysight.sync_phase()
elif keysight_channel == 'ch02':
# keysight.ch2_function_type('RAMP')
# keysight.ch2_ramp_symmetry(100*(1-asym))
# keysight.ch2_phase(180*(1+asym))
# keysight.ch2_amplitude_unit('VPP')
# keysight.ch2_amplitude(keysight_amplitude)
# keysight.ch2_offset(key_offset)
# keysight.ch2_frequency(key_frequency)
# keysight.sync_source(2)
# keysight.ch2_output('ON')
pass
else:
raise ValueError('Select a valid Keysight channel.')
scope_avger = []
zi_averager = {0: zi.scope_avg_ch1,
1: zi.scope_avg_ch2}
for ii, sig in enumerate(scope_signal):
if ii == 0:
zi.scope_channel1_input(sig)
elif ii == 1:
zi.scope_channel2_input(sig)
else:
raise ValueError('Select only one or two scope signals.')
zi_averager[ii].label = sig
try:
scope_avger.append(zi_averager[ii])
prepare_measurement(fast_v_start, fast_v_stop, zi_averager[ii],
qdac_fast_channel, zi_scope_length, zi)
except KeyError:
raise ValueError('Invalid scope_channel: {}'.format(ch))
keysight.sync_output('ON')
# set up UHFLI
# zi.scope_mode.set('Time Domain') # currently done in ZI driver
# prepare_measurement(fast_v_start, fast_v_stop, zi_averager[ch])
if print_settings:
print('keysight frequency: {}'.format(key_frequency))
print('keysight amplitude: {}'.format(keysight_amplitude))
print('keysight offset: {}'.format(key_offset))
print('\n')
print('zi_samplingrate: {}'.format(zi_samplingrate))
print('zi_trig_level: {}'.format(zi_trig_level))
print('zi_trig_delay: {}'.format(zi_trig_delay))
print('zi_trig_hyst: {}'.format(zi_trig_hyst))
try:
if tasks_to_perform is None:
#plot, data = do1d_M(qdac_channel, q_start, q_stop, npoints, delay, scope_avger)
plot, data = do1d(qdac_channel, q_start, q_stop, npoints, delay, *scope_avger)
else:
#plot, data = do1d_M(qdac_channel, q_start, q_stop, npoints, delay, scope_avger, *tasks_to_perform)
plot, data = do1d(qdac_channel, q_start, q_stop, npoints, delay, *scope_avger, *tasks_to_perform)
if keysight_channel == 'ch01':
keysight.ch1_output('OFF')
elif keysight_channel == 'ch02':
keysight.ch2_output('OFF')
except KeyboardInterrupt:
if keysight_channel == 'ch01':
keysight.ch1_output('OFF')
elif keysight_channel == 'ch02':
keysight.ch2_output('OFF')
print('Measurement interrupted.')
raise KeyboardInterrupt
return plot, data