|
42 | 42 | # Changes_done:Working |
43 | 43 | # ------------------------------------------------------------------------ |
44 | 44 |
|
45 | | -import pymeasure |
46 | 45 | import numpy as np |
47 | 46 | import matplotlib.pyplot as plt |
48 | 47 | from time import sleep |
49 | 48 | # import pyvisa |
50 | 49 | from pymeasure.instruments.keithley import Keithley2400 |
51 | 50 | import pandas as pd |
52 | 51 |
|
53 | | -# object creation ---------------------------------- |
54 | | -# rm1 = pyvisa.ResourceManager() |
55 | | -# keithley_2182= rm1.open_resource("GPIB::7") |
56 | | -# keithley_2182.write("*rst; status:preset; *cls") |
57 | | -keithley_2400 = Keithley2400("GPIB::4") |
58 | | -keithley_2400.disable_buffer() |
59 | | - |
60 | | -sleep(10) |
61 | | - |
62 | | -I = [] |
63 | | -# I1=[] |
64 | | -Volt = [] |
65 | | -# interval = 1 |
66 | | -# number_of_readings = 2 |
67 | | - |
68 | | -i = 0 |
69 | | -# user input ---------------------------------- |
70 | | -I_range = float(input( |
71 | | - "Enter value of I: (in micro A , Highest value of Current fror -I to I) ")) |
72 | | -I_step = float(input("Enter steps: (The step size , in micro A) ")) |
73 | | -filename = input("Enter filename:") |
74 | | - |
75 | | - |
76 | | -print("Current (A) || Voltage(V) ") |
77 | | - |
78 | | -keithley_2400.apply_current() # Sets up to source current |
79 | | -# Sets the source current range to 1 mA |
80 | | -keithley_2400.source_current_range = 1e-6 |
81 | | -keithley_2400.compliance_voltage = 210 # Sets the compliance voltage to 210 V |
82 | | -keithley_2400.source_current = 0 # Sets the source current to 0 mA |
83 | | -keithley_2400.enable_source() # Enables the source output |
84 | | -keithley_2400.measure_voltage() |
85 | | -''' |
86 | | -
|
87 | | -
|
88 | | -#initial set up keithley_2400 |
89 | | -keithley_2400.apply_current() # Sets up to source current |
90 | | -keithley_2400.source_current_range = 1e-3 # Sets the source current range to 1 mA |
91 | | -sleep(10) |
92 | | -keithley_2400.compliance_voltage = 210 # Sets the compliance voltage to 210 V |
93 | | -keithley_2400.source_current = 0 # Sets the source current to 0 mA |
94 | | -keithley_2400.enable_source() # Enables the source output |
95 | | -sleep(15) |
96 | | -keithley_2400.measure_voltage() |
97 | | -sleep(1) |
98 | | -# current loop voltage measured ------------------------------ |
99 | | -
|
100 | | -''' |
101 | | - |
102 | | - |
103 | | -def IV_Measure(cur): |
104 | | - |
105 | | - keithley_2400.ramp_to_current(cur * 1e-6) |
106 | | - |
107 | | - sleep(1.5) |
108 | | - v_meas = keithley_2400.voltage |
109 | | - sleep(1) |
110 | | - # I.append(keithley_2400.current) # actual current in 2400 (in Amps) |
111 | | - I.append(cur * 1e-3) |
112 | | - |
113 | | - Volt.append(v_meas) # voltage |
114 | | - |
115 | | - print(str(cur * 1e-6) + " " + str(Volt[i])) |
116 | | - |
117 | | - ''' |
118 | | - keithley_2182.write("status:measurement:enable 512; *sre 1") |
119 | | - keithley_2182.write("sample:count %d" % number_of_readings) |
120 | | - keithley_2182.write("trigger:source bus") |
121 | | - keithley_2182.write("trigger:delay %f" % (interval)) |
122 | | - keithley_2182.write("trace:points %d" % number_of_readings) |
123 | | - keithley_2182.write("trace:feed sense1; feed:control next") |
124 | | - keithley_2182.write("initiate") |
125 | | - keithley_2182.assert_trigger() |
126 | | - sleep(1) |
127 | | - keithley_2182.wait_for_srq() |
128 | | - sleep(1) |
129 | | - voltages = keithley_2182.query_ascii_values("trace:data?") |
130 | | - keithley_2182.query("status:measurement?") |
131 | | - keithley_2182.write("trace:clear; feed:control next") |
132 | | -
|
133 | | - v_avr=sum(voltages) / len(voltages) |
134 | | -
|
135 | | - sleep(1) |
136 | | - #I.append(keithley_2400.current) # actual current in 2400 (in Amps) |
137 | | - I.append(cur*1e-3) |
138 | | - Volt.append(v_avr) #voltage avg list |
139 | | - print(str(cur*1e-3)+" "+str(v_avr)) |
140 | | - keithley_2182.write("*rst; status:preset; *cls") |
141 | | -
|
142 | | - keithley_2182.clear() |
143 | | -
|
144 | | - ''' |
145 | | - sleep(1) |
146 | | - |
147 | | - |
148 | | -# loop1--------------------------------------------- |
149 | | -print("In loop 1") |
150 | | -for i1 in np.arange(0, I_range + I_step, I_step): |
151 | | - IV_Measure(i1) |
152 | | - i = i + 1 |
153 | | -# -------------------------------------------------- |
154 | | - |
155 | | -''' |
156 | | -#loop2--------------------------------------------- |
157 | | -print("In loop 2") |
158 | | -for i2 in np.arange(I_range,0-I_step,-I_step): |
159 | | - IV_Measure(i2) |
160 | | -#-------------------------------------------------- |
161 | | -#loop3--------------------------------------------- |
162 | | -print("In loop 3") |
163 | | -for i3 in np.arange(0,-I_range-I_step,-I_step): |
164 | | - IV_Measure(i3) |
165 | | -#-------------------------------------------------- |
166 | | -#loop4--------------------------------------------- |
167 | | -print("In loop 4") |
168 | | -for i4 in np.arange(-I_range,0+I_step,I_step): |
169 | | - IV_Measure(i4) |
170 | | -#-------------------------------------------------- |
171 | | -#loop5--------------------------------------------- |
172 | | -print("In loop 5") |
173 | | -for i5 in np.arange(0,I_range+I_step,I_step): |
174 | | - IV_Measure(i5) |
175 | | -#-------------------------------------------------- |
176 | | -''' |
177 | | -# data saving in file ---------------------------- |
178 | | - |
179 | | -df = pd.DataFrame() |
180 | | -df['I'] = pd.DataFrame(I) |
181 | | -df['V'] = pd.DataFrame(Volt) |
182 | | -print("Current (A) || Voltage(V) \n") |
183 | | - |
184 | | -print(df) |
185 | | - |
186 | | -# df.to_csv(r'E:\Prathamesh\Python Stuff\IV Only 2400\'str(filename)+str(filename)'+'.txt', index=None, sep=' ', mode='w') |
187 | | -df.to_csv(r'C:/Users/Instrument-DSL/Desktop/LED_IV/' + |
188 | | - str(filename) + '.txt', index=None, sep=' ', mode='w') |
189 | | - |
190 | | - |
191 | | -# turning of instrument ---------------------------- |
192 | | -sleep(0.5) |
193 | | -keithley_2400.shutdown() |
194 | | -print("keithley_2400.shutdown") |
195 | | -sleep(0.5) # Ramps the current to 0 mA and disables output |
196 | | -# keithley_2182.clear() |
197 | | -# keithley_2182.close() |
198 | | - |
199 | | -# graph ploting ---------------------------- |
200 | | - |
201 | | -plt.plot(I, Volt, marker='o', linestyle='-', color='g', label='Square') |
202 | | -plt.xlabel('I') |
203 | | -plt.ylabel('V') |
204 | | -plt.title('IV curve') |
205 | | -plt.legend('I') |
206 | | -plt.show() |
| 52 | + |
| 53 | +def main(): |
| 54 | + """ |
| 55 | + Main function to run the I-V sweep measurement. |
| 56 | + """ |
| 57 | + # object creation ---------------------------------- |
| 58 | + keithley_2400 = Keithley2400("GPIB::4") |
| 59 | + keithley_2400.disable_buffer() |
| 60 | + sleep(2) |
| 61 | + |
| 62 | + i = 0 |
| 63 | + I = [] |
| 64 | + Volt = [] |
| 65 | + |
| 66 | + # user input ---------------------------------- |
| 67 | + I_range = float(input("Enter value of I: (in micro A, Highest value of Current from -I to I) ")) |
| 68 | + I_step = float(input("Enter steps: (The step size, in micro A) ")) |
| 69 | + filename = input("Enter filename:") |
| 70 | + |
| 71 | + print("Current (A) || Voltage(V) ") |
| 72 | + |
| 73 | + keithley_2400.apply_current() |
| 74 | + keithley_2400.source_current_range = 1e-6 |
| 75 | + keithley_2400.compliance_voltage = 210 |
| 76 | + keithley_2400.source_current = 0 |
| 77 | + keithley_2400.enable_source() |
| 78 | + keithley_2400.measure_voltage() |
| 79 | + |
| 80 | + def IV_Measure(cur): |
| 81 | + nonlocal i |
| 82 | + keithley_2400.ramp_to_current(cur * 1e-6) |
| 83 | + sleep(1.5) |
| 84 | + v_meas = keithley_2400.voltage |
| 85 | + sleep(1) |
| 86 | + I.append(cur * 1e-6) # Use the actual sourced value |
| 87 | + Volt.append(v_meas) |
| 88 | + print(f"{cur * 1e-6:.3e} A {v_meas:.4f} V") |
| 89 | + i += 1 |
| 90 | + |
| 91 | + print("In loop 1") |
| 92 | + for i1 in np.arange(0, I_range + I_step, I_step): |
| 93 | + IV_Measure(i1) |
| 94 | + |
| 95 | + df = pd.DataFrame({'I': I, 'V': Volt}) |
| 96 | + print("\n--- Measurement Complete ---") |
| 97 | + print(df) |
| 98 | + |
| 99 | + save_path = os.path.join('C:/Users/Instrument-DSL/Desktop/LED_IV/', f"{filename}.txt") |
| 100 | + df.to_csv(save_path, index=None, sep='\t', mode='w') |
| 101 | + print(f"Data saved to {save_path}") |
| 102 | + |
| 103 | + sleep(0.5) |
| 104 | + keithley_2400.shutdown() |
| 105 | + print("Keithley 2400 shutdown complete.") |
| 106 | + |
| 107 | + plt.plot(I, Volt, marker='o', linestyle='-', color='g', label='I-V Data') |
| 108 | + plt.xlabel('Current (A)') |
| 109 | + plt.ylabel('Voltage (V)') |
| 110 | + plt.title('I-V Curve') |
| 111 | + plt.legend() |
| 112 | + plt.grid(True) |
| 113 | + plt.show() |
| 114 | + |
| 115 | + |
| 116 | +if __name__ == "__main__": |
| 117 | + main() |
0 commit comments