Skip to content

Commit 545c162

Browse files
authored
Merge pull request #16 from zhinst/mehdia/add-q-control-files
Add Q control files
2 parents 9a4d1c5 + 106c7af commit 545c162

File tree

4 files changed

+2681
-0
lines changed

4 files changed

+2681
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## Resonance engineering of quality factor: the Q-control method
2+
3+
The contents of this folder belong to the blog post [Resonance engineering of quality factor: the Q-control method](https://www.zhinst.com/ch/en/blogs/resonance-engineering-quality-factor-q-control-method) and include:
4+
5+
- Settings file for MFLI Lock-in Amplifier and LabOne User Interface for Q-control experiment: [mfli_qcontrol.xml](mfli_qcontrol.xml).
6+
- MATLAB script to run Q-control on MFLI Lock-in Amplifier [mfli_qcontrol.m](mfli_qcontrol.m).
7+
- Python script to run Q-control on MFLI Lock-in Amplifier [mfli_qcontrol.py](mfli_qcontrol.py).
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
%% -----------------------------------------------------------------------
2+
% Copyright 2024 Zurich Instruments AG
3+
%
4+
% This example demonstrates how to perform Q-Control on a resonator using
5+
% a lock-in amplifer like MFLI or UHFLI. The instrument needs PID and MF
6+
% or MD options.
7+
%
8+
% Clear and close everything
9+
close all; clear; clc;
10+
% ------------------------------------------------------------------------
11+
12+
%% Required parameters ---------------------------------------------------
13+
% Parameters: device serial numbers, interface type, data server address
14+
% and port, api level
15+
16+
%%% UHFLI
17+
% device = 'dev2730'; % Device serial number in the rear panel
18+
% interface = '1GbE'; % When data server is not on device
19+
% host = '127.0.0.1'; % Address of data server away from device
20+
21+
%%% MFLI
22+
device = 'dev4022'; % Device serial number in the rear panel
23+
interface = 'PCIe'; % When data server runs on device
24+
host = '10.42.5.62'; % Address of data server on device
25+
26+
port = 8004; % Port data server listen to
27+
apilevel = 6; % Maximum API level for MFLI
28+
% ------------------------------------------------------------------------
29+
30+
%% Connection to device --------------------------------------------------
31+
% Close current API sessions
32+
clear ziDAQ
33+
34+
% Create an API session to the data server
35+
ziDAQ('connect', host, port, apilevel);
36+
37+
% Establish a connection between data server and device
38+
ziDAQ('connectDevice', device, interface);
39+
% ------------------------------------------------------------------------
40+
41+
%% Settings --------------------------------------------------------------
42+
% Initial settings for Q control
43+
ziDAQ('syncSetInt', ['/' device '/system/preset/index'], 0);
44+
ziDAQ('syncSetInt', ['/' device '/system/preset/load'], 1);
45+
pause(3);
46+
% Define all the settings in a "cell"
47+
device_settings = {
48+
% Signal Output
49+
['/' device '/sigouts/0/on'], 0;
50+
['/' device '/sigouts/0/imp50'], 0;
51+
['/' device '/sigouts/0/add'], 0;
52+
['/' device '/sigouts/0/range'], 1.0;
53+
['/' device '/sigouts/0/offset'], 0;
54+
['/' device '/sigouts/0/diff'], 0;
55+
['/' device '/sigouts/0/amplitudes/0'], 0;
56+
['/' device '/sigouts/0/amplitudes/1'], 0;
57+
['/' device '/sigouts/0/amplitudes/2'], 0;
58+
['/' device '/sigouts/0/amplitudes/3'], 0;
59+
['/' device '/sigouts/0/enables/0'], 0;
60+
['/' device '/sigouts/0/enables/1'], 1;
61+
['/' device '/sigouts/0/enables/2'], 1;
62+
['/' device '/sigouts/0/enables/3'], 1;
63+
% Signal Input
64+
['/' device '/sigins/0/imp50'], 1;
65+
['/' device '/sigins/0/float'], 0;
66+
['/' device '/sigins/0/diff'], 0;
67+
['/' device '/sigins/0/ac'], 0;
68+
['/' device '/sigins/0/range'], 0.3;
69+
% Demodulator
70+
['/' device '/extrefs/*/enable'], 0;
71+
['/' device '/demods/*/oscselect'], 0;
72+
['/' device '/demods/*/harmonic'], 1;
73+
['/' device '/demods/0/phaseshift'], 0.0;
74+
['/' device '/demods/1/phaseshift'], 0.0;
75+
['/' device '/demods/2/phaseshift'], 0.0;
76+
['/' device '/demods/3/phaseshift'], 90.0;
77+
['/' device '/demods/0/adcselect'], 0;
78+
% PIDs
79+
['/' device '/pids/*/enable'], 0;
80+
['/' device '/pids/2/input'], 0;
81+
['/' device '/pids/3/input'], 1;
82+
['/' device '/pids/2/inputchannel'], 0;
83+
['/' device '/pids/3/inputchannel'], 0;
84+
['/' device '/pids/2/setpoint'], 0;
85+
['/' device '/pids/3/setpoint'], 0;
86+
['/' device '/pids/2/demod/timeconstant'], 0.5e-3;
87+
['/' device '/pids/3/demod/timeconstant'], 0.5e-3;
88+
['/' device '/pids/2/demod/order'], 4;
89+
['/' device '/pids/3/demod/order'], 4;
90+
['/' device '/pids/2/demod/harmonic'], 1;
91+
['/' device '/pids/3/demod/harmonic'], 1;
92+
['/' device '/pids/2/output'], 0;
93+
['/' device '/pids/3/output'], 0;
94+
['/' device '/pids/2/outputchannel'], 2;
95+
['/' device '/pids/3/outputchannel'], 3;
96+
['/' device '/pids/2/center'], 0;
97+
['/' device '/pids/3/center'], 0;
98+
['/' device '/pids/2/limitlower'], -0.5;
99+
['/' device '/pids/3/limitlower'], -0.5;
100+
['/' device '/pids/2/limitupper'], +0.5;
101+
['/' device '/pids/3/limitupper'], +0.5;
102+
['/' device '/pids/2/p'], 0;
103+
['/' device '/pids/3/p'], 0;
104+
['/' device '/pids/2/i'], 0;
105+
['/' device '/pids/3/i'], 0;
106+
['/' device '/pids/2/d'], 0;
107+
['/' device '/pids/3/d'], 0;
108+
['/' device '/pids/2/keepint'], 0;
109+
['/' device '/pids/3/keepint'], 0;
110+
};
111+
ziDAQ('set', device_settings);
112+
% ------------------------------------------------------------------------
113+
114+
%% Drive Signal Output ---------------------------------------------------
115+
% Drive the resonator around its resonance
116+
resonance_frequency = 1.84342276e6; % [Hz]
117+
driving_amplitude = 0.1; % [V]
118+
device_settings = {
119+
% Signal Output
120+
['/' device '/oscs/0/freq'], resonance_frequency;
121+
['/' device '/sigouts/0/amplitudes/1'], driving_amplitude;
122+
['/' device '/pids/2/enable'], 1;
123+
['/' device '/pids/3/enable'], 1;
124+
['/' device '/sigouts/0/on'], 1;
125+
};
126+
ziDAQ('set', device_settings);
127+
% ------------------------------------------------------------------------
128+
129+
%% Apply feedback gain ---------------------------------------------------
130+
% Depending on the level and sign of the feedback gain we can control the
131+
% q-factor in different direction and intensity.
132+
feedback_gain = -10; % []
133+
feadback_settings = {
134+
['/' device '/pids/2/p'], feedback_gain;
135+
['/' device '/pids/3/p'], feedback_gain;
136+
};
137+
ziDAQ('set', feadback_settings);
138+
% ------------------------------------------------------------------------
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
# Copyright 2024 Zurich Instruments AG
2+
# Application: This script implements Q-Control method for a resonator using lock-in amplifiers.
3+
# Instruments: MFLI, UHFLI
4+
# Options: PID, MF (MD for MFLI)
5+
# Setup: 1.84-MHz resonator between Signal Input 1 and Signal Output 1
6+
7+
8+
from zhinst.core import ziDAQServer
9+
import time
10+
11+
12+
def api_session(device, host, interface):
13+
# API connection to the instrument
14+
session = ziDAQServer(host, 8004, 6)
15+
session.connectDevice(device, interface)
16+
return session
17+
18+
19+
def device_initialization(session, device):
20+
# Initial settings for Q control
21+
session.syncSetInt(f'/{device}/system/preset/index', 0)
22+
session.syncSetInt(f'/{device}/system/preset/load', 0)
23+
time.sleep(3)
24+
initial_settings = [
25+
# Signal Output
26+
(f'/{device}/sigouts/0/on', 0),
27+
(f'/{device}/sigouts/0/imp50', 0),
28+
(f'/{device}/sigouts/0/add', 0),
29+
(f'/{device}/sigouts/0/range', 1.0),
30+
(f'/{device}/sigouts/0/offset', 0.0),
31+
(f'/{device}/sigouts/0/diff', 0),
32+
(f'/{device}/sigouts/0/amplitudes/0', 0.00),
33+
(f'/{device}/sigouts/0/amplitudes/1', 0.0),
34+
(f'/{device}/sigouts/0/amplitudes/2', 0.0),
35+
(f'/{device}/sigouts/0/amplitudes/3', 0.0),
36+
(f'/{device}/sigouts/0/enables/0', 0),
37+
(f'/{device}/sigouts/0/enables/1', 1),
38+
(f'/{device}/sigouts/0/enables/2', 1),
39+
(f'/{device}/sigouts/0/enables/3', 1),
40+
# Signal Input
41+
(f'/{device}/sigins/0/imp50', 1),
42+
(f'/{device}/sigins/0/float', 0),
43+
(f'/{device}/sigins/0/diff', 0),
44+
(f'/{device}/sigins/0/ac', 0),
45+
(f'/{device}/sigins/0/range', 0.3),
46+
# Demodulators
47+
(f'/{device}/extrefs/*/enable', 0),
48+
(f'/{device}/demods/*/oscselect', 0),
49+
(f'/{device}/demods/*/harmonic', 1),
50+
(f'/{device}/demods/0/phaseshift', 0.0),
51+
(f'/{device}/demods/1/phaseshift', 0.0),
52+
(f'/{device}/demods/2/phaseshift', 0.0),
53+
(f'/{device}/demods/3/phaseshift', 90.0),
54+
(f'/{device}/demods/*/adcselect', 0),
55+
# PIDs
56+
(f'/{device}/pids/*/enable', 0),
57+
(f'/{device}/pids/2/input', 0),
58+
(f'/{device}/pids/3/input', 1),
59+
(f'/{device}/pids/2/inputchannel', 0),
60+
(f'/{device}/pids/3/inputchannel', 0),
61+
(f'/{device}/pids/2/setpoint', 0.0),
62+
(f'/{device}/pids/3/setpoint', 0.0),
63+
(f'/{device}/pids/2/demod/timeconstant', 0.5e-3),
64+
(f'/{device}/pids/3/demod/timeconstant', 0.5e-3),
65+
(f'/{device}/pids/2/demod/order', 4),
66+
(f'/{device}/pids/3/demod/order', 4),
67+
(f'/{device}/pids/2/demod/harmonic', 1),
68+
(f'/{device}/pids/3/demod/harmonic', 1),
69+
(f'/{device}/pids/2/output', 0),
70+
(f'/{device}/pids/3/output', 0),
71+
(f'/{device}/pids/2/outputchannel', 2),
72+
(f'/{device}/pids/3/outputchannel', 3),
73+
(f'/{device}/pids/2/center', 0.0),
74+
(f'/{device}/pids/3/center', 0.0),
75+
(f'/{device}/pids/2/limitlower', -0.5),
76+
(f'/{device}/pids/3/limitlower', -0.5),
77+
(f'/{device}/pids/2/limitupper', +0.5),
78+
(f'/{device}/pids/3/limitupper', +0.5),
79+
(f'/{device}/pids/2/p', 0.0),
80+
(f'/{device}/pids/3/p', 0.0),
81+
(f'/{device}/pids/2/i', 0.0),
82+
(f'/{device}/pids/3/i', 0.0),
83+
(f'/{device}/pids/2/d', 0.0),
84+
(f'/{device}/pids/3/d', 0.0),
85+
(f'/{device}/pids/2/keepint', 0),
86+
(f'/{device}/pids/3/keepint', 0),
87+
]
88+
session.set(initial_settings)
89+
90+
91+
def drive_signal_output(session, device, amplitude):
92+
drive_settings = [
93+
(f'/{device}/sigouts/0/amplitudes/1', amplitude),
94+
(f'/{device}/pids/2/enable', 1),
95+
(f'/{device}/pids/3/enable', 1),
96+
(f'/{device}/sigouts/0/on', 1),
97+
]
98+
session.set(drive_settings)
99+
100+
101+
def adjust_feedback_gain(session, device, gain):
102+
feedback_settings = [
103+
(f'/{device}/pids/2/p', - gain),
104+
(f'/{device}/pids/3/p', - gain),
105+
]
106+
session.set(feedback_settings)
107+
108+
109+
if __name__ == "__main__":
110+
111+
device = "dev4022"
112+
host = "10.42.5.62"
113+
interface = "PCIe"
114+
#device = "dev2730"
115+
#host = "127.0.0.1"
116+
#interface = "1GbE"
117+
118+
daq = api_session(device, host, interface)
119+
device_initialization(daq, device)
120+
121+
resonance_frequency = 1.84342276e6 # [Hz]
122+
daq.set(f'/{device}/oscs/0/freq', resonance_frequency),
123+
124+
driving_amplitude = 0.1 # [V]
125+
drive_signal_output(daq, device, driving_amplitude)
126+
127+
feedback_gain = +10 # []
128+
adjust_feedback_gain(daq, device, feedback_gain)

0 commit comments

Comments
 (0)