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
| """ Keithley I-V Sweep Demis D. John, October 2014, Univ. of California Santa Barbara Program to sweep voltage & measure current on Keithley SMU Known bugs: With PythonXY, the plot window opens *behind* the current window. Also, file is saved *usually* in same directory as this script - but at one point it kept saving into the PythonXY directory, which was confusing. Probably need to set the Python working directory to be sure. Edit/Run this file via Python(x,y) (click the 1st button to open the Spyder IDE) Installed PyVISA for GPIB communication. Spyder Editor. Based off Steve Nichols' Script from ~2010, Univ. of California Santa Barbara """
SaveFiles = False
DevName = 'I-V Curve 01' Keithley_GPIB_Addr = 18 SR400_GPIB_Addr = 32
SweepMode = 'Current' VoltageComp = 10 CurrentComp = 100.0e-3 start = 0 stop = +0.05 numpoints = 40
import pyvisa as visa import numpy as N import time import os import matplotlib.pyplot as plt
rm = visa.ResourceManager() keithley = rm.open_resource('GPIB0::' + str(Keithley_GPIB_Addr) + '::INSTR')
if SweepMode=='Current': keithley.write("*RST") print("reset the instrument") keithley.write(":SOUR:FUNC:MODE CURR") keithley.write(":SOURce:CURRent:MODE FIXed") keithley.write(":SOURce:CURRent:RANGe:AUTO 1") keithley.write(":SENS:FUNC \"VOLT\"") keithley.write(":SENS:VOLT:PROT:LEV " + str(VoltageComp)) keithley.write(":SENS:VOLT:RANGE:AUTO 1") keithley.write(":OUTP ON") print("keithley Current source initialized ...") elif SweepMode=='Voltage': keithley.write("*RST") print("reset the instrument") time.sleep(0.5) keithley.write(":SOUR:FUNC:MODE VOLT") keithley.write(":SENS:CURR:PROT:LEV " + str(CurrentComp)) keithley.write(":SENS:CURR:RANGE:AUTO 1") keithley.write(":OUTP ON") print("keithley Voltage source initialized ...") else: raise ValueError('SweepMode initialization error!')
Voltage = [] Current = [] Resistent = [] Timestamp = [] Status = [] plt.ion() if SweepMode=='Voltage': for V in N.linspace(start, stop, num=numpoints, endpoint=True): print("Voltage set to: " + str(V) + " V" ) keithley.write(":SOUR:VOLT " + str(V)) data = keithley.query(":READ?") answer = data.split(',') I = eval( answer.pop(1) ) * 1e3 Current.append( I ) vread = eval( answer.pop(0) ) Voltage.append(vread) resis = eval( answer.pop(0) ) Resistent.append(resis) t = eval( answer.pop(0) ) Timestamp.append(t) stat = eval( answer.pop(0) ) Status.append(stat) plt.clf() plt.plot(Current, Voltage, '*-') plt.xlabel("Current (mA)") plt.ylabel("Voltage (V)") plt.pause(0.01) plt.ioff() print("--> Current = " + str(Current[-1]) + ' mA') elif SweepMode=='Current': for I in N.linspace(start, stop, num=numpoints, endpoint=True): print("Current set to: " + str(I) + " A" ) keithley.write(":SOUR:CURR " + str(I)) data = keithley.query(":READ?") answer = data.split(',') I = eval( answer.pop(1) ) * 1e3 Current.append( I ) vread = eval( answer.pop(0) ) Voltage.append(vread) resis = eval( answer.pop(0) ) Resistent.append(resis) t = eval( answer.pop(0) ) Timestamp.append(t) stat = eval( answer.pop(0) ) Status.append(stat) print("--> Voltage = " + str(Voltage[-1]) + ' V')
keithley.write(":OUTP OFF") keithley.write(":SYSTem:BEEPer 1046, 0.1") time.sleep(0.1) keithley.write(":SYSTem:BEEPer 784, 0.1") time.sleep(0.1) keithley.write(":SYSTem:BEEPer 523, 0.1") time.sleep(0.1) keithley.write(":SYSTem:BEEPer 587, 0.2") keithley.write("SYSTEM:KEY 23") keithley.close()
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, 'I-V Curve - ' + DevName + ' - [' + curtime +']' ) data = np.array( zip(Current, Voltage) ) np.savetxt( SavePath + '.txt', data, fmt="%e", delimiter="\t", header="Current (A)\tVoltage (V)" )
|