|
| 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