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
| """ Keithley 2450 I-source V-Sweep (V-I curve) Du X.C., March 2023, Univ. of Electronic Science and Technology of China Program to sweep current & measure voltage on Keithley 2450 SMU Installed PyVISA for GPIB communication, and pymeasure for Keithley macro-lib (supported by CasperSchippers) """
SaveFiles = True RealTime = True
DevName = '210-1-7' Keithley_GPIB_Addr = 18 SR400_GPIB_Addr = 32
SweepMode = 'Current' VoltageComp = 8.0e-0 CurrentComp = +10.0e-3 bottom = -6.0e-3 top = +6.0e-3 start = 0 stop = 0 polar = True numcycles = 2 numpoints = 400
R_ser = 1014.4595;
from pymeasure.instruments.keithley import keithley2450 import numpy as np import scipy.io import time import os import warnings import matplotlib.pyplot as plt
keithley = keithley2450.Keithley2450('GPIB0::' + str(Keithley_GPIB_Addr) + '::INSTR') keithley.apply_current()
'''A floating point property that controls the source current range in Amps, which can take values between -1.05 and +1.05 A. Auto-range is disabled when this property is set. ''' keithley.compliance_voltage = VoltageComp keithley.source_current = 0 keithley.measure_voltage() keithley.enable_source()
T_init = time.time()
_sentinel = object() def sweeplist(bottom, top, start = _sentinel, stop = _sentinel, polarity = True, Ncycle:int = 1, Npoint:int = 100, RemoveNLP = True): if polarity: start = bottom if start == _sentinel else start stop = (Ncycle%2)*top+((Ncycle+1)%2)*bottom if stop == _sentinel else stop if (Ncycle == 1) & (stop <= start): stop = top warnings.warn("Meaningless variable 'stop', correct to top!") else: start = top if start == _sentinel else start stop = (Ncycle%2)*bottom+((Ncycle+1)%2)*top if stop == _sentinel else stop if (Ncycle == 1) & (stop >= start): stop = bottom warnings.warn("Meaningless variable 'stop', correct to bottom!") linespace = np.linspace(bottom, top, num=Npoint) ss = np.array([start, stop]) mask = np.isin(ss, linespace) linespace = np.sort(np.append(linespace,ss[~mask])) if not polarity: linespace = np.flipud(linespace) loc = np.append(np.where(linespace == start), np.where(linespace == stop)) first_loop = linespace[loc[0]:loc[1]+1] seconde_loop = np.append(linespace[loc[1]+1:], np.flipud(linespace[loc[1]:-1])) third_loop = np.append(np.flipud(linespace[:loc[1]]), linespace[1:loc[1]+1]) add_loop = np.append(third_loop, seconde_loop) if Ncycle == 1: slist = first_loop elif Ncycle >= 2: if (polarity & (stop <= start))|(not polarity & (stop >= start)): first_loop = linespace[loc[0]:] seconde_loop = np.flipud(linespace[loc[1]:-1]) start_loop = np.append(first_loop, seconde_loop) else: start_loop = np.append(first_loop, seconde_loop) slist = np.append(start_loop, np.tile(add_loop, int(np.floor((Ncycle-2)/2)))) if Ncycle%2 == 1: slist = np.append(slist, third_loop) if RemoveNLP: if not mask[0]: loc_start = np.argwhere(slist==ss[0]) slist = np.delete(slist, loc_start[1:]) if not mask[1]: loc_stop = np.argwhere(slist==ss[1]) slist = np.delete(slist, loc_stop[:-1]) return slist
Voltage, Current_set, Current, Resistance, Time = ([] for i in range(5)) if RealTime: plt.ion()
for I in sweeplist(bottom, top, start, stop, polarity = polar, Ncycle = numcycles, Npoint = numpoints): if not RealTime: pass print("Current set to: " + str(I) + " A" ) keithley.ramp_to_current(I, steps=2, pause=20e-3) ''' Ramps to a target current from the set current value over a certain number of linear steps, each separated by a pause duration. :param target_current: A current in Amps :param steps: An integer number of steps :param pause: A pause duration in seconds to wait between steps
try-> keithley.source_current = I which use SPIC macro as ":SOUR:CURR?", ":SOUR:CURR:LEV %g" ''' Current_set.append(I) keithley.measure_voltage(nplc=1.0, voltage=21.0, auto_range=True) vread = keithley.voltage Voltage.append(vread) cread = keithley.source_current Current.append(cread) if cread == 0.0: rread = float("inf") else: rread = vread/cread Resistance.append(rread) tread = time.time() - T_init Time.append(tread) if not RealTime: print("--> Voltage = " + str(Voltage[-1]) + ' V') if RealTime: plt.clf() plt.scatter(np.array(Current[-1])*1e3, np.array(Voltage[-1])-R_ser*np.array(Current[-1]),\ marker = '.', c = 'red', s = 200, zorder = 2) plt.plot(np.array(Current)*1e3, np.array(Voltage)-R_ser*np.array(Current), '*-', zorder = 1) plt.xlabel("Current (mA)") plt.ylabel("Voltage (V)") plt.pause(0.01) plt.ioff()
keithley.shutdown() keithley.triad(440, 0.2)
plt.subplot(221) plt.plot(np.array(Current)*1e3, np.array(Voltage)-R_ser*np.array(Current), '*-') plt.xlabel("Current (mA)") plt.ylabel("Voltage (V)")
plt.subplot(222) plt.plot(Time, Resistance, 'r*-') plt.xlabel("Time (s)") plt.ylabel("Resistance (Ohm)") ax = plt.gca() ax.ticklabel_format(style='sci', scilimits=(-1,2), axis='y')
plt.subplot(223) dT = np.array(Time[1:])-np.array(Time[:-1]) plt.plot(np.array(Current[:-1])*1e3, dT, 'g*-') plt.xlabel("Current (mA)") plt.ylabel("dT (s)")
plt.subplot(224) with warnings.catch_warnings(): warnings.simplefilter("ignore") rate = np.array(Current_set)/np.array(Current) - 1.0 plt.hist(rate[~np.isnan(rate)], 30) ax = plt.gca() ax.ticklabel_format(style='sci', scilimits=(-1,2), axis='x')
if SaveFiles: if not os.path.isdir(DevName): os.mkdir(DevName) curtime = time.strftime('%y-%m-%d_%H-%M-%S') SavePath = os.path.join(DevName, 'Isweep_' + DevName + '_[' + curtime +']' ) data = np.array((Voltage, Current_set, Current, Resistance, Time)) np.savetxt(SavePath + '.txt', data.T, fmt="%e", delimiter="\t",\ header="Voltage(V)\tCurrent_set(A)\tCurrent(A)\tResistance(Ohm)\tTime(s)") scipy.io.savemat(SavePath +'.mat', \ mdict = {'volt':Voltage, 'curr':Current, 'curr_set':Current_set, \ 'resis':Resistance, 't':Time})
|