-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathcurrent_source.py
More file actions
82 lines (63 loc) · 2.3 KB
/
current_source.py
File metadata and controls
82 lines (63 loc) · 2.3 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
import numpy as np
import csv
import logging
import pyvisa
import random
from datetime import datetime, timedelta
from instruments.sensor import *
from instruments.multimeter import *
from instruments.source import *
from instruments.switch import *
rm = pyvisa.ResourceManager()
instruments = dict()
logging.basicConfig(level=logging.INFO, format='%(asctime)s %(levelname)-8s %(message)s')
logging.info("Starting ...")
def current_source_output_impedance_test():
name = "Current_Source"
runs = 50
settling_time = 2.0 # seconds
start = -10.0
stop = +5.0
step = 1.0
setpoints = list(np.arange(start, stop + step, step))
measurements = {v: [] for v in setpoints}
instruments["2400"] = K2400(
rm,
'TCPIP::192.168.0.5::gpib0,24',
title='Keithley 2400'
)
smu = instruments["2400"]
smu.set_source_type("VOLT")
smu.instr.write(":SENSe:CURRent:NPLCycles 10")
smu.set_voltage_compliance(0.1)
smu.set_source_current_range(0.001)
smu.set_current_compliance(0.0006)
smu.set_output_on()
for run in range(runs):
logging.info(f"Run {run + 1} of {runs}")
randomized_setpoints = setpoints.copy()
random.shuffle(randomized_setpoints)
smu.instr.query(":READ?")
for counter, voltage in enumerate(randomized_setpoints, start=1):
smu.set_source_voltage(voltage)
time.sleep(settling_time)
reply = smu.instr.query(":READ?").split(',') # returns string voltage,current,....
current = float(reply[1])
measurements[voltage].append(current)
logging.info(
f"{counter:02}/{len(setpoints)} "
f"Vset={voltage:+e} V "
f"Imeas={current:+e} A"
)
timestamp = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
filename = f"{name}_{timestamp}.csv"
num_runs = max(len(v) for v in measurements.values())
header = ["Setpoint_V"] + [f"Run {i + 1}" for i in range(num_runs)]
with open(filename, "w", newline="") as f:
writer = csv.writer(f)
writer.writerow(header)
for setpoint in sorted(measurements.keys()):
row = [float(setpoint)] + measurements[setpoint]
writer.writerow(row)
smu.set_output_off()
current_source_output_impedance_test()