-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathCurve Tracer.py
323 lines (247 loc) · 9.07 KB
/
Curve Tracer.py
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
# Plot output characteristic for BJTs and MOSFETs
import math
from utime import ticks_ms, ticks_add, ticks_diff, sleep_ms
from eez import scpi, setU, setI, getOutputMode, getI, dlogTraceData
TYPE_NPN = 0
TYPE_PNP = 1
TYPE_N_CH = 2
TYPE_P_CH = 3
deviceType = TYPE_NPN
deviceName = None
Uce_max = 15
Ic_max = 0.2
Uds_max = 15
Id_max = 2
def error(message):
scpi('DISP:ERROR "' + message + '"')
def updateData(name, unit, value):
scpi('DISP:DIALog:DATA "' + name + '",FLOAT,' + unit + ',' + str(value))
def inputVoltage(name, voltage, min, max):
value = scpi('DISP:INPUT? "' + name + '",NUMBER,VOLT,' + str(min) + ',' + str(max) + ',' + str(voltage))
if value != None:
voltage = float(value)
updateData(name, 'VOLT', voltage)
return voltage
def inputAmperage(name, amperage, min, max):
value = scpi('DISP:INPUT? "' + name + '",NUMBER,AMPER,' + str(min) + ',' + str(max) + ',' + str(amperage))
if value != None:
amperage = float(value)
updateData(name, 'AMPER', amperage)
return amperage
def select_device_type():
global deviceType
value = scpi('DISP:SELECT? ' + str(deviceType + 1) + ',"NPN BJT","PNP BJT","N-Ch MOSFET","P-Ch MOSFET"')
if value != None and value != 0:
deviceType = value - 1
scpi("DISP:DIALog:DATA \"device_type\",INTEGER," + str(deviceType))
def input_device_name():
global deviceName
value = scpi('disp:input? "Device name",TEXT,1,20,"' + (deviceName if deviceName != None else "") + '"')
if value != None:
deviceName = value
scpi('DISP:DIALog:DATA "device_name",STRING,"' + deviceName + '"')
scpi('DISP:DIALog:DATA "can_start",INTEGER,1')
def input_Uce_max():
global Uce_max
Uce_max = inputVoltage("Uce_max", Uce_max, 1.0, 40.0)
def input_Ic_max():
global Ic_max
Ic_max = inputAmperage("Ic_max", Ic_max, 0.001, 5.0)
def input_Uds_max():
global Uds_max
Uds_max = inputVoltage("Uds_max", Uds_max, 1.0, 40.0)
def input_Id_max():
global Id_max
Id_max = inputAmperage("Id_max", Id_max, 0.001, 5.0)
def start():
if deviceName == None:
error("Enter device name")
return
scpi("DISP:DIALog:CLOSe")
try:
scpi("*SAV 10")
scpi("MEM:STAT:FREEze ON")
if deviceType == TYPE_NPN:
start_BJT(True)
elif deviceType == TYPE_PNP:
start_BJT(False)
elif deviceType == TYPE_N_CH:
start_MOSFET(True)
elif deviceType == TYPE_P_CH:
start_MOSFET(False)
finally:
scpi("ABOR:DLOG")
scpi("*RCL 10")
scpi("MEM:STAT:FREEze OFF")
def start_BJT(cgnd):
global deviceName, Uce_max, Ic_max
TIME_ON_MS = 30
TIME_OFF_MS = 0
# Ch1 B-E
Ib = [50e-6, 100e-6, 150e-6, 200e-6, 250e-6, 300e-6, 350e-6, 400e-6]
Ube = 10.0
# Ch2 C-E
Uce_min = 0.1
NUM_U_DS_STEPS = 400
Uce_step = Uce_max / NUM_U_DS_STEPS
if cgnd:
scpi("INST:COUP:TRAC CGND")
scpi("INST ch1")
scpi("OUTP 0")
scpi("VOLT " + str(Ube))
scpi("CURR 0")
scpi("OUTP:DPR 1")
scpi("SENS:CURR:RANG 0.05")
scpi("INST ch2")
scpi("OUTP 0")
scpi("VOLT 0")
scpi("CURR " + str(Ic_max))
scpi("SENS:CURR:RANG BEST")
scpi("SENS:DLOG:CLE")
scpi('SENS:DLOG:TRAC:REM "Device name = ' + deviceName + '; Uce,max = ' + str(Uce_max) + '; Ic,max = ' + str(Ic_max) + '"')
scpi("SENS:DLOG:TRAC:X:UNIT VOLT")
scpi("SENS:DLOG:TRAC:X:RANG:MIN " + str(Uce_min))
scpi("SENS:DLOG:TRAC:X:RANG:MAX " + str(Uce_max))
scpi("SENS:DLOG:TRAC:X:STEP " + str(Uce_step))
scpi("SENS:DLOG:TRAC:X:SCALE LIN")
scpi('SENS:DLOG:TRAC:X:LABel "Uce"')
num_ib_steps = len(Ib)
scpi("SENS:DLOG:TRAC:Y:UNIT AMPER")
scpi("SENS:DLOG:TRAC:Y:RANG:MIN 0")
scpi("SENS:DLOG:TRAC:Y:RANG:MAX " + str(Ic_max * 1.1))
scpi('SENS:DLOG:TRAC:Y:LABel "Ic"')
for ib_step_counter in range(num_ib_steps):
scpi('SENS:DLOG:TRAC:Y' + str(ib_step_counter+1) + ':LABel "Ib=' + str(Ib[ib_step_counter] * 1E6) + 'uA"')
scpi('INIT:DLOG:TRACE "/Recordings/' + deviceName + '.dlog"')
scpi("INST ch1")
scpi("OUTP 1")
scpi("INST ch2")
scpi("OUTP 1")
scpi("DISP:WINDOW:DLOG")
iMonValues = [0.0] * num_ib_steps
t = ticks_ms()
for uce_step_counter in range(NUM_U_DS_STEPS):
Uce = Uce_min + uce_step_counter * Uce_step
setU(2, Uce)
for ib_step_counter in range(num_ib_steps):
setI(1, Ib[ib_step_counter])
t = ticks_add(t, TIME_ON_MS)
sleep_ms(ticks_diff(t, ticks_ms()))
iMonValues[ib_step_counter] = getI(2)
if TIME_OFF_MS > 0:
setI(1, 0)
t = ticks_add(t, TIME_OFF_MS)
sleep_ms(ticks_diff(t, ticks_ms()))
try:
dlogTraceData(iMonValues)
except:
error('DLOG stopped')
break
def start_MOSFET(cgnd):
global deviceName, Uds_max, Id_max
TIME_ON_MS = 15
TIME_OFF_MS = 6
# Ch1 G-S
Ugs = [3.5, 4, 4.5, 5, 5.5, 6]
Ig = 5.0
# Ch2 D-S
Uds_min = 0.1
NUM_U_DS_STEPS = 400
SIMULATOR = 0
if SIMULATOR:
TIME_ON_MS = 10
TIME_OFF_MS = 0
Ugs = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Ig = 5.0
#Uds_step = Uds_max / NUM_U_DS_STEPS
Uds_logMin = math.log(Uds_min) / math.log(10)
Uds_logMax = math.log(Uds_max) / math.log(10)
Uds_step = (Uds_logMax - Uds_logMin) / (NUM_U_DS_STEPS - 1)
if cgnd:
scpi("INST:COUP:TRAC CGND")
scpi("INST ch1")
scpi("OUTP 0")
scpi("VOLT 0")
scpi("CURR " + str(Ig))
scpi("OUTP:DPR 1")
scpi("INST ch2")
scpi("OUTP 0")
scpi("VOLT 0")
scpi("CURR " + str(Id_max))
scpi('SENS:DLOG:TRAC:REM "Device name = ' + deviceName + '; Uds,max = ' + str(Uds_max) + '; Id,max = ' + str(Id_max) + '"')
scpi("SENS:DLOG:TRAC:X:UNIT VOLT")
scpi("SENS:DLOG:TRAC:X:RANG:MIN " + str(Uds_logMin))
scpi("SENS:DLOG:TRAC:X:RANG:MAX " + str(Uds_logMax))
scpi("SENS:DLOG:TRAC:X:STEP " + str(Uds_step))
scpi("SENS:DLOG:TRAC:X:SCALE LOG")
scpi('SENS:DLOG:TRAC:X:LABel "Uds"')
num_ugs_steps = len(Ugs)
scpi("SENS:DLOG:TRAC:Y:UNIT AMPER")
scpi("SENS:DLOG:TRAC:Y:RANG:MIN 0")
scpi("SENS:DLOG:TRAC:Y:RANG:MAX " + str(Id_max * 1.1))
scpi('SENS:DLOG:TRAC:Y:LABel "Id"')
scpi('SENS:DLOG:TRAC:Y:SCALe LOG')
for ugs_step_counter in range(num_ugs_steps):
scpi('SENS:DLOG:TRAC:Y' + str(ugs_step_counter+1) + ':LABel "Ugs=' + str(Ugs[ugs_step_counter]) + 'V"')
scpi('INIT:DLOG:TRACE "/Recordings/' + deviceName + '.dlog"')
scpi("INST ch1")
scpi("OUTP 1")
scpi("INST ch2")
scpi("OUTP 1")
if SIMULATOR:
scpi("SIMU:LOAD:STATE ON,CH2")
scpi("DISP:WINDOW:DLOG")
iMonValues = [0.0] * num_ugs_steps
t = ticks_ms()
for uds_step_counter in range(NUM_U_DS_STEPS):
Uds = math.pow(10, Uds_logMin + uds_step_counter * Uds_step)
setU(2, Uds)
for ugs_step_counter in range(num_ugs_steps):
if SIMULATOR:
if Uds < 10:
scpi("SIMU:LOAD " + str(20 / Ugs[ugs_step_counter]) + ",CH2")
else:
scpi("SIMU:LOAD " + str((20 / 10) * Uds / Ugs[ugs_step_counter]) + ",CH2")
setU(1, Ugs[ugs_step_counter])
t = ticks_add(t, TIME_ON_MS)
sleep_ms(ticks_diff(t, ticks_ms()))
iMonValues[ugs_step_counter] = getI(2)
if TIME_OFF_MS > 0:
setU(1, 0)
t = ticks_add(t, TIME_OFF_MS)
sleep_ms(ticks_diff(t, ticks_ms()))
try:
dlogTraceData(iMonValues)
except:
error('DLOG stopped')
break
ch1Model = scpi("SYSTem:CHANnel:MODel? ch1")
ch2Model = scpi("SYSTem:CHANnel:MODel? ch2")
if ch1Model.startswith("DCP405") and ch2Model.startswith("DCP405"):
scpi("DISP:DIALog:OPEN \"/Scripts/Curve Tracer.res\"")
updateData('Uce_max', 'VOLT', Uce_max)
updateData('Ic_max', 'AMPER', Ic_max)
updateData('Uds_max', 'VOLT', Uds_max)
updateData('Id_max', 'AMPER', Id_max)
while True:
action = scpi("DISP:DIALog:ACTIon?")
if action == "select_device_type":
select_device_type()
if action == "input_device_name":
input_device_name()
elif action == "input_Uce_max":
input_Uce_max()
elif action == "input_Ic_max":
input_Ic_max()
elif action == "input_Uds_max":
input_Uds_max()
elif action == "input_Id_max":
input_Id_max()
elif action == "start":
start()
break
elif action == "close" or action == 0:
scpi("DISP:DIALog:CLOSe")
break
else:
scpi('DISP:INPUT? "Requires DCP405 on Ch1 and Ch2", MENU, BUTTON, "Close"')