-
Notifications
You must be signed in to change notification settings - Fork 351
Expand file tree
/
Copy pathkeithley.py
More file actions
190 lines (158 loc) · 6.42 KB
/
keithley.py
File metadata and controls
190 lines (158 loc) · 6.42 KB
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
from __future__ import annotations
import time
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from qcodes.instrument import Instrument
from qcodes.instrument_drivers.Keithley import Keithley26xx
from qcodes.parameters import Parameter
src_FS_map = {
"200e-3": 180e-3,
"2": 1.8,
"20": 18,
"200": 180,
"100e-3": 80e-3,
"1": 0.8,
"6": 5.6,
"40": 38,
}
def setup_dmm(dmm: Instrument) -> None:
dmm.aperture_time(1.0)
dmm.autozero("OFF")
dmm.autorange("OFF")
def save_calibration(
smu: Keithley26xx, calibration_due_in_years_from_today: float = 1.0
) -> None:
"""Saves calibration for Keithley 2600 SMUs and sets a calibration due date
based on years.
Args:
smu: Keithley 2600 SMU
calibration_due_in_years_from_today: Period added to current date, used to set due date. Defaults to 1.0.
"""
calibration_date = int(time.time())
ONE_YEAR_IN_SECONDS = 31536000
recalibration_due_period = int(
ONE_YEAR_IN_SECONDS * calibration_due_in_years_from_today
)
for smu_channel in smu.channels:
smu.write(f"{smu_channel.channel}.cal.adjustdate = {calibration_date}")
smu.write(f"{smu_channel.channel}.cal.date = {calibration_date}")
smu.write(
f"{smu_channel.channel}.cal.due = {calibration_date + recalibration_due_period}"
)
smu.write(f"{smu_channel.channel}.cal.save()")
def calibrate_keithley_smu_v(
smu: Keithley26xx,
dmm: Instrument,
src_Z: float = 1e-30,
time_delay: float = 3.0,
save_calibrations: bool = False,
calibration_due_in_years_from_today: float = 1.0,
dmm_range_per_smu_range_mapping: dict[str, float] | None = None,
) -> None:
if dmm_range_per_smu_range_mapping is None:
dmm_range_per_smu_range_mapping = {
"200e-3": 1,
"2": 10,
"20": 100,
}
else:
wrong_smu_range_keys = set(dmm_range_per_smu_range_mapping.keys()) - set(
src_FS_map.keys()
)
if len(wrong_smu_range_keys) > 0:
raise ValueError(
f"dmm_range_per_smu_range_mapping contains unknown keys {wrong_smu_range_keys}, "
f"the possible keys are {set(src_FS_map.keys())}"
)
setup_dmm(dmm)
for smu_channel in smu.channels:
input(
f"Please connect channel {smu_channel.channel} to V input on calibrated DMM."
)
for smu_range, dmm_range in dmm_range_per_smu_range_mapping.items():
dmm.range(dmm_range)
calibrate_keithley_smu_v_single(
smu, smu_channel.channel, dmm.volt, smu_range, src_Z, time_delay
)
if save_calibrations:
save_calibration(
smu, calibration_due_in_years_from_today=calibration_due_in_years_from_today
)
def calibrate_keithley_smu_v_single(
smu: Keithley26xx,
channel: str,
dmm_param_volt: Parameter,
v_range: str,
src_Z: float = 1e-30,
time_delay: float = 3.0,
) -> None:
assert channel in {smu_channel.channel for smu_channel in smu.channels}
assert v_range in src_FS_map.keys()
src_FS = src_FS_map[v_range]
sense_modes = ["SENSE_LOCAL"]
for sense_mode in sense_modes:
print("Sense mode: " + sense_mode)
smu.write(f'{channel}.cal.unlock("KI0026XX")')
smu.write(f"{channel}.reset()")
smu.write(f"{channel}.source.func = {channel}.OUTPUT_DCVOLTS")
smu.write(f"{channel}.source.rangev = {v_range}")
smu.write(f"{channel}.source.output = {channel}.OUTPUT_OFF")
smu.write(f"{channel}.sense = {channel}." + sense_mode)
time.sleep(time_delay)
# Start positive calibration:
smu.write(f"{channel}.cal.polarity = {channel}.CAL_POSITIVE")
smu.write(f"{channel}.source.levelv = {src_Z}")
smu.write(f"{channel}.source.output = {channel}.OUTPUT_ON")
# Measure positive zero voltage with SMU and DMM:
time.sleep(time_delay)
smu.write(f"Z_rdg = {channel}.measure.v()")
DMM_Z_rdg = dmm_param_volt()
smu.write(f"{channel}.source.output = {channel}.OUTPUT_OFF")
smu.write(f"{channel}.source.levelv = {src_FS:.8e}")
smu.write(f"{channel}.source.output = {channel}.OUTPUT_ON")
# Measure positive full scale voltage with SMU and DMM:
time.sleep(time_delay)
smu.write(f"FS_rdg = {channel}.measure.v()")
DMM_FS_rdg = dmm_param_volt()
# Write positive v_range calibration to SMU:
smu.write(f"{channel}.source.output = {channel}.OUTPUT_OFF")
time.sleep(time_delay)
smu.write(
f"{channel}.source.calibratev({v_range}, {src_Z}, {DMM_Z_rdg:.8e}, {src_FS:.8e}, {DMM_FS_rdg:.8e})"
)
if sense_mode != "SENSE_CALA":
time.sleep(time_delay)
smu.write(
f"{channel}.measure.calibratev({v_range}, Z_rdg, {DMM_Z_rdg:.8e}, FS_rdg, {DMM_FS_rdg:.8e})"
)
time.sleep(time_delay)
# Start negative calibration:
smu.write(f"{channel}.cal.polarity = {channel}.CAL_NEGATIVE")
smu.write(f"{channel}.source.levelv = -{src_Z}")
smu.write(f"{channel}.source.output = {channel}.OUTPUT_ON")
# Measure negative zero voltage with SMU and DMM:
time.sleep(time_delay)
smu.write(f"Z_rdg = {channel}.measure.v()")
DMM_Z_rdg = dmm_param_volt()
smu.write(f"{channel}.source.output = {channel}.OUTPUT_OFF")
smu.write(f"{channel}.source.levelv = -{src_FS:.8e}")
smu.write(f"{channel}.source.output = {channel}.OUTPUT_ON")
# Measure negative full scale voltage with DMM:
time.sleep(time_delay)
smu.write(f"FS_rdg = {channel}.measure.v()")
DMM_FS_rdg = dmm_param_volt()
# Write negative v_range calibration to SMU:
smu.write(f"{channel}.source.output = {channel}.OUTPUT_OFF")
time.sleep(time_delay)
smu.write(
f"{channel}.source.calibratev(-{v_range}, -{src_Z}, {DMM_Z_rdg:.8e}, -{src_FS:.8e}, {DMM_FS_rdg:.8e})"
)
if sense_mode != "SENSE_CALA":
time.sleep(time_delay)
smu.write(
f"{channel}.measure.calibratev(-{v_range}, Z_rdg, {DMM_Z_rdg:.8e}, FS_rdg, {DMM_FS_rdg:.8e})"
)
time.sleep(time_delay)
smu.write(f"{channel}.cal.polarity = {channel}.CAL_AUTO")
# Reset the smu to default state
smu.write(f"{channel}.source.levelv = {src_Z}")