forked from mbrennwa/pypsucurvetrace
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcurvetrace
executable file
·815 lines (672 loc) · 27.4 KB
/
curvetrace
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
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
#!/usr/bin/env python3
# This file is part of PyPSUcurvetrace, a toolbox for I/V curve tracing of electronic parts using programmable power supplies.
#
# PyPSUcurvetrace is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# PyPSUcurvetrace is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with PyPSUcurvetrace. If not, see <http://www.gnu.org/licenses/>.
# imports:
import time
import math
import datetime
import configparser
import argparse
import numpy as np
### from termcolor import colored
import lib.powersupply as powersupply
##########################################
# function to get number input from user #
##########################################
def __get_number(text,allowNegative = False,allowZero = True,typ='float'):
input_ok = False
while not input_ok:
try:
if typ.upper()=='FLOAT':
val = float(input(text))
elif typ.upper()=='INT':
val = int(input(text))
if not allowNegative:
if val < 0.0:
raise ValueError
if not allowZero:
if val == 0.0:
raise ValueError
input_ok = True
except ValueError:
print (' Invalid input! Try again...')
return val
#############################################################
# function to print output both to console and to data file #
#############################################################
def printit(text,f='',comm=''):
print(text)
if f:
if len(comm):
text = comm + ' ' + text
print(text,file=f)
f.flush()
return
###########################
# connect to power supply #
###########################
def connect_PSU(configPSU,label):
if not (label in configPSU):
# print(label + ' not specified in configuration file. Leaving ' + label + ' unconfigured.')
P = powersupply.PSU(label=label) # init empty PSU object
else:
# read COMPORT field (mandatory):
if 'COMPORT' in configPSU[label]:
port=configPSU[label]['COMPORT']
else:
print ('No COMPORT field in the PSU configuration file! Cannot continue.')
exit()
# check if this is a single PSU unit, or a stack of serial connected PSUs:
num_PSU = 1 # number of PSUs
try:
x = eval(port)
if type(x) is tuple:
num_PSU = len(x)
port = x
except:
pass
# read TYPE field (mandatory):
if 'TYPE' in configPSU[label]:
commandset = configPSU[label]['TYPE']
else:
print ('No TYPE field in the PSU configuration file! Cannot continue.')
exit()
if num_PSU > 1:
try:
x = eval(commandset)
if type(x) is not tuple:
raise ValueError
commandset = x
except ValueError:
print("Could not parse TYPEs of stacked PSUs.")
exit()
# connect to PSU(s):
print ('Connecting to power supply ' + label + '...')
P = powersupply.PSU(port,commandset,label)
# set number of consistent readings for measurements (optional):
if 'NUMSTABLEREAD' in configPSU[label]:
P.NSTABLEREADINGS = int(configPSU[label]['NUMSTABLEREAD'])
else:
print ('Number of consistent measurement readings not configured! Using N = 1...')
P.NSTABLEREADINGS = 1
if P.CONNECTED:
# make sure the PSU output is turned off:
P.turnOff()
# show summary
for k in range(len(P._PSU)):
if len(P._PSU) > 1:
print ('* Command set (unit '+str(k+1)+'): ' + P._PSU[k].COMMANDSET)
print ('* Model (unit '+str(k+1)+'): ' + P._PSU[k].MODEL)
else:
print ('* Command set: ' + P._PSU[k].COMMANDSET)
print ('* Model: ' + P._PSU[k].MODEL)
print ('* Min. voltage: ' + str(P.VMIN) + ' V')
print ('* Max. voltage: ' + str(P.VMAX) + ' V')
print ('* Max. current: ' + str(P.IMAX) + ' A')
print ('* Max. power: ' + str(P.PMAX) + ' W')
print ('* Voltage setting resolution: ' + str(P.VRESSET) + ' V')
print ('* Current setting resolution: ' + str(P.IRESSET) + ' A')
print ('* Voltage reading resolution: ' + str(P.VRESREAD) + ' V')
print ('* Current reading resolution: ' + str(P.IRESREAD) + ' A')
print ('* Number of consistent readings for measurements: ' + str(P.NSTABLEREADINGS))
### print ('* Settle time: ' + str(PSU.settletime()) + ' s')
return P
###############################
# configure PSU test settings #
###############################
def configure_test_PSU(PSU,configDUT = []):
if not PSU.CONNECTED:
print ('\n' + PSU.LABEL + ' is not connected (or connection is not configured).')
PSU.CONFIGURED = False
else:
print ('\n' + 'Configuring ' + PSU.LABEL + ' test settings...')
# take parameters from DUT config file where available, otherwise ask user:
if 'VSTART' in configDUT:
PSU.TEST_VSTART = float(configDUT['VSTART'])
else:
PSU.TEST_VSTART = __get_number('* ' + PSU.LABEL + ' start voltage (V): ',allowZero=True,allowNegative=False,typ='float')
if 'VEND' in configDUT:
PSU.TEST_VEND = float(configDUT['VEND'])
else:
PSU.TEST_VEND = __get_number('* ' + PSU.LABEL + ' end voltage (V): ',allowZero=True,allowNegative=False,typ='float')
if PSU.TEST_VSTART == PSU.TEST_VEND:
PSU.TEST_VSTEP = 0
else:
if 'VSTEP' in configDUT:
PSU.TEST_VSTEP = float(configDUT['VSTEP'])
else:
PSU.TEST_VSTEP = __get_number('* ' + PSU.LABEL + ' voltage step size (V): ',allowZero=False,allowNegative=False,typ='float')
if 'IMAX' in configDUT:
PSU.TEST_ILIMIT = float(configDUT['IMAX'])
else:
PSU.TEST_ILIMIT = __get_number('* ' + PSU.LABEL + ' maximum allowed current (A): ',allowZero=False,allowNegative=False,typ='float')
if 'PMAX' in configDUT:
PSU.TEST_PLIMIT = float(configDUT['PMAX'])
else:
PSU.TEST_PLIMIT = __get_number('* ' + PSU.LABEL + ' maximum allowed power (W): ',allowZero=False,allowNegative=False,typ='float')
if 'POLARITY' in configDUT:
PSU.TEST_POLARITY = int(configDUT['POLARITY'])
else:
try:
pol = (input('* OPTIONAL: ' + PSU.LABEL + ' polarity of outputs -- N: normal / I: inverted [default=N]: '))
except ValueError:
print (' Using default: normal polarity.')
pol = 'N'
if pol.upper() == 'I':
PSU.TEST_POLARITY = -1
else:
PSU.TEST_POLARITY = 1;
PSU.CONFIGURED = True
return PSU
###############################
# configure PSU idle settings #
###############################
def configure_idle_PSU(PSU,configDUT):
if PSU.CONFIGURED:
if configDUT:
# take configuration from DUT config file:
PSU.TEST_VIDLE = float(configDUT['VIDLE'])
if not 'VIDLE_MIN' in configDUT:
PSU.TEST_VIDLE_MIN = PSU.TEST_VIDLE # fixed idle voltage
else:
PSU.TEST_VIDLE_MIN = float(configDUT['VIDLE_MIN'])
if not 'VIDLE_MAX' in configDUT:
PSU.TEST_VIDLE_MAX = PSU.TEST_VIDLE # fixed idle voltage
else:
PSU.TEST_VIDLE_MAX = float(configDUT['VIDLE_MAX'])
if not 'PIDLEMAX' in configDUT:
PSU.TEST_PIDLELIMIT = PSU.TEST_PLIMIT # use same power limit as for test conditions
else:
PSU.TEST_PIDLELIMIT = float(configDUT['PIDLEMAX'])
if not 'IDLE_GM' in configDUT:
PSU.TEST_IDLE_GM = None # unknown transconductance
else:
PSU.TEST_IDLE_GM = float(configDUT['IDLE_GM']) # unknown transconductance (delta-I1 / delta-U2 or delta-U2 / delta-I1 in A/V)
PSU.TEST_IIDLE = float(configDUT['IIDLE'])
print(PSU.TEST_VIDLE_MAX)
print('*******************************************')
else:
print ('\n' + 'configure ' + PSU.LABEL + ' idle settings:')
PSU.TEST_VIDLE = __get_number('* ' + PSU.LABEL + ' idle voltage (V): ',allowZero=True,allowNegative=False,typ='float')
try:
PSU.TEST_VIDLE_MIN = float(input('* OPTIONAL: ' + PSU.LABEL + ' idle voltage range, minimum value (V): '))
except ValueError:
PSU.TEST_VIDLE_MIN = PSU.TEST_VIDLE # fixed idle voltage
PSU.TEST_VIDLE_MAX = PSU.TEST_VIDLE # fixed idle voltage
try:
PSU.TEST_VIDLE_MAX = float(input('* OPTIONAL: ' + PSU.LABEL + ' idle voltage range, maximum value (V): '))
except ValueError:
PSU.TEST_VIDLE_MAX = PSU.TEST_VIDLE # fixed idle voltage
if PSU.TEST_VIDLE_MAX == PSU.TEST_VIDLE_MIN:
PSU.TEST_IDLE_GM = None # unknown transconductance
else:
PSU.TEST_IDLE_GM = __get_number('* ' + PSU.LABEL + ' DUT transconductance at idle conditions (in A/V): ',allowZero=False,allowNegative=False,typ='float')
PSU.TEST_IIDLE = __get_number('* ' + PSU.LABEL + ' idle current (A): ',allowZero=True,allowNegative=False,typ='float')
return PSU
######################
# do idle / pre-heat #
######################
def do_idle(PSU1,PSU2,seconds,file=None):
REG = None
if PSU1.CONFIGURED and PSU2.CONFIGURED:
if not PSU1.TEST_VIDLE_MIN == PSU1.TEST_VIDLE_MAX:
REG = PSU1
FIX = PSU2
elif not PSU2.TEST_VIDLE_MIN == PSU2.TEST_VIDLE_MAX:
REG = PSU2
FIX = PSU1
if REG == None: # no regulation of idle bias, just fixed values:
for p in [PSU1, PSU2]:
if p.CONFIGURED:
p.setCurrent(p.TEST_IIDLE,False)
p.setVoltage(p.TEST_VIDLE,False) # don't check for stable voltage, since current limiter may upset the the voltage value
# wait pre-heat time:
time.sleep(seconds)
else: # fixed output on FIX power supply and regulated output on REG power supply
IFIXLIM = min (FIX.TEST_ILIMIT,FIX.TEST_PIDLELIMIT/FIX.TEST_VIDLE); # current limit set at fixed PSU
# sleep time (seconds):
dt = 0.2
# Set output limits at the fixed PSU:
PSU1.setCurrent(IFIXLIM,False)
PSU1.setVoltage(FIX.TEST_VIDLE,True)
# Set output at the regulating PSU:
REG.setCurrent(REG.TEST_IIDLE,False) # current limit
REG.setVoltage(REG.TEST_VIDLE,True) # set last-used idle setting
# start idling:
t0 = time.time()
timenow = time.time()
while timenow < t0+seconds:
# read and print voltages and currents at FIX and REG outputs:
f = FIX.read()
r = REG.read()
Uf = f[0]
If = f[1]
Ur = r[0]
Ir = r[1]
b = "U0={:.3f} V".format(Uf) + ' ' + "I0={:.3f} A".format(If) + ' ' + "Uc={:.3f} V".format(Ur) + ' ' + "Ic={:.3f} A".format(Ir)
t = "Idling ({:.1f}".format(time.time()-t0) + ' of ' + "{:.1f}".format(seconds) + ' s): '
print (t + b + ' '*12, end="\r")
if f[2] == "CC":
If = IFIXLIM * (1+(FIX.TEST_VIDLE-Uf)/FIX.TEST_VIDLE)
dIf = If-FIX.TEST_IIDLE # deviation of the observed idle current from the target value
if not dIf == 0.0:
# determine the voltage changed needed for Ur voltage:
dUr = 0.65 * dIf / REG.TEST_IDLE_GM
if REG.TEST_VIDLE - dUr < REG.TEST_VIDLE_MIN:
REG.TEST_VIDLE = REG.TEST_VIDLE_MIN
elif REG.TEST_VIDLE - dUr > REG.TEST_VIDLE_MAX:
REG.TEST_VIDLE = REG.TEST_VIDLE_MIN
else:
REG.TEST_VIDLE = REG.TEST_VIDLE - dUr
PSU2.setVoltage(REG.TEST_VIDLE,True)
time.sleep(dt)
timenow = time.time()
# Clear the terminal:
print (' '*72, end="\r")
# write idle / preheat conditions to file:
if file is not None:
printit("* OPERATING POINT AT END OF PREHEAT / IDLE: Uc = " "U0={:.3f} V".format(Uf) + ' ' + "I0={:.3f} A".format(If) + ' ' + "Uc={:.3f} V".format(Ur) + ' ' + "Ic={:.3f} A".format(Ir) , file , '%')
################
# main program #
################
# parse input arguments (if any):
parser = argparse.ArgumentParser(description='PyPSUcurvetrace is a Python program for I-V curve tracing of electronic parts using programmable power supplies.')
parser.add_argument('-c', help='configuration file with test parameters (name/path)')
args = parser.parse_args()
# Say Hello:
print('\n')
print('***** PyPSUcurvetrace')
print('***** Python program for I-V curve tracing of electronic parts using programmable power supplies')
print('***** Disclaimer: NO WARRANTIES OF ANY KIND!!!')
print('***** Disclaimer: Users are advised to study the code in order to understand how this program works.')
print('\n')
# read PSU config file:
configPSU = configparser.ConfigParser()
configPSU.read('config_PSU.txt')
# read DUT configPSU file (if any):
configDUT = []
if args.c:
print ('Reading DUT configuration in file ' + args.c + '...\n')
configDUT = configparser.ConfigParser()
configDUT.read(args.c)
# connect to PSUs:
PSU1 = connect_PSU(configPSU,'PSU1'); print( )
PSU2 = connect_PSU(configPSU,'PSU2'); print( )
# ask for sample name:
samplename = ''
while not samplename:
samplename = input('Enter sample name / label: ')
samplename = samplename.strip()
# start logfile:
logfilename = samplename + '.dat'
logfile = open(logfilename,'w')
if logfile:
print('\nLogging output to ' + logfilename + '...')
else:
print('Could not open log file!')
exit()
# configure voltage values / current and power limits:
if 'PSU1' in configDUT:
PSU1 = configure_test_PSU (PSU1,configDUT['PSU1'])
else:
PSU1 = configure_test_PSU (PSU1)
if 'PSU2' in configDUT:
PSU2 = configure_test_PSU (PSU2,configDUT['PSU2'])
else:
PSU2 = configure_test_PSU (PSU2)
# check if at least one of the power supplies is configured:
if not PSU1.CONFIGURED:
if not PSU2.CONFIGURED:
print('No power supply configured. Good bye.')
exit()
# set up repeats:
if 'EXTRA' in configDUT:
N_rep = int(configDUT['EXTRA']['NREP'])
else:
try:
N_rep = int(input('\nOPTIONAL: Number of repeats per reading [default=1]: '))
except ValueError:
print (' Using default: single reading.')
N_rep = 1
if N_rep <= 0:
raise ValueError('Number of repeats must be positive.')
# set up idle time between readings:
if 'EXTRA' in configDUT:
T_idle = int(configDUT['EXTRA']['IDLESECS'])
else:
try:
T_idle = float(input('\nOPTIONAL: idle time between readings (s) [default=0]: '))
except ValueError:
print (' Using default: no idle time.')
T_idle = 0.0
if T_idle < 0:
raise ValueError('Idle time must not be negative.')
# set up pre-heat time between readings:
if 'EXTRA' in configDUT:
T_preheat = int(configDUT['EXTRA']['PREHEATSECS'])
else:
try:
T_preheat = float(input('\nOPTIONAL: pre-heat time before starting the test (s) [default=0]: '))
except ValueError:
print (' Using default: no pre-heating.')
T_preheat = 0.0
if T_preheat < 0:
raise ValueError('Pre-heat time must not be negative.')
# set up idle conditions (for pre-heat or idle between readings)
if (T_idle > 0.0) or (T_preheat > 0.0):
if PSU1.CONFIGURED:
if 'PSU1' in configDUT:
PSU1 = configure_idle_PSU (PSU1,configDUT['PSU1'])
else:
PSU1 = configure_idle_PSU (PSU1,None)
if PSU2.CONFIGURED:
if 'PSU2' in configDUT:
PSU2 = configure_idle_PSU (PSU2,configDUT['PSU2'])
else:
PSU2 = configure_idle_PSU (PSU2,None)
if PSU1.CONNECTED and PSU2.CONNECTED:
if (not PSU1.TEST_VIDLE_MAX == PSU1.TEST_VIDLE_MIN) and (not PSU2.TEST_VIDLE_MAX == PSU2.TEST_VIDLE_MIN):
print('Both PSUs are configured with variable idle voltages. This cannot work. Goodbye!')
exit()
# check voltage / power / current limits (and fix where possible and necessary):
print ('\nChecking voltage / current settings...')
for p in [PSU1,PSU2]:
if p.CONNECTED:
if p.TEST_VSTART < p.VMIN:
print (' ' + p.LABEL + ': Adjusting start voltage to min. value possible with the power supply (' + str(p.VMIN) + ' V).')
p.TEST_VSTART = p.VMIN
if p.TEST_VSTART > p.VMAX:
print (' ' + p.LABEL + ': Adjusting start voltage to max. value possible with the power supply (' + str(p.VMAX) + ' V).')
p.TEST_VSTART = p.VMAX
if p.TEST_VEND < p.VMIN:
print (' ' + p.LABEL + ': Adjusting end voltage to min. value possible with the power supply (' + str(p.VMIN) + ' V).')
p.TEST_VEND = p.VMIN
if p.TEST_VEND > p.VMAX:
print (' ' + p.LABEL + ': Adjusting end voltage to max. value possible with the power supply (' + str(p.VMAX) + ' V).')
p.TEST_VEND = p.VMAX
if p.TEST_VEND == p.TEST_VSTART:
# print (' ' + p.LABEL + ': Same start and end voltage, test will run at fixed voltage (' + str(p.TEST_VSTART) + ' V).')
p.TEST_VSTEP = 0
if abs(p.TEST_VEND-p.TEST_VSTART) < p.VRESSET:
print (' ' + p.LABEL + ': Test voltage range is less than voltage setting resolution of the PSU. Test will run at fixed voltage (' + str(p.TEST_VSTART) + ' V).')
p.TEST_VSTEP = 0
p.TEST_VEND = p.TEST_VSTART
if p.TEST_VSTEP > 0.0:
if p.TEST_VSTEP > abs(p.TEST_VEND-p.TEST_VSTART):
p.TEST_VSTEP = abs(p.TEST_VEND-p.TEST_VSTART)
print (' ' + p.LABEL + ': Voltage step size exceeds test voltage range. Adjusting step size to ' + str(p.TEST_VSTEP) + ' V.')
if p.TEST_VSTEP < p.VRESSET:
print (' ' + p.LABEL + ': Voltage step size is less than PSU resolution of voltage setting. Adjusting step size to ' + str(p.VRESSET) + ' V.')
p.TEST_VSTEP = p.VRESSET
if p.TEST_VSTEP/p.VRESSET < p.VRESSET:
print (' ' + p.LABEL + ': Voltage step size is less than PSU resolution of voltage setting. Adjusting step size to ' + str(p.VRESSET) + ' V.')
p.TEST_VSTEP = p.VRESSET
if not ( p.TEST_VSTEP / p.VRESSET == round(p.TEST_VSTEP / p.VRESSET) ):
u = p.TEST_VSTEP
p.TEST_VSTEP = round(p.TEST_VSTEP / p.VRESSET) * p.VRESSET
print (' ' + p.LABEL + ': Voltage step size (' + str(u) + ' V) is not consistent with PSU resolution of voltage setting. Adjusting step size to ' + str(p.TEST_VSTEP) + ' V.')
if p.TEST_ILIMIT > p.IMAX:
print (' ' + p.LABEL + ': Adjusting current limit to max. value possible with the power supply (' + str(p.IMAX) + ' A).')
p.TEST_ILIMIT = p.IMAX
if p.TEST_PLIMIT > p.PMAX:
print (' ' + p.LABEL + ': Adjusting power limit to max. value possible with the power supply (' + str(p.PMAX) + ' W).')
p.TEST_PLIMIT = p.PMAX
if (T_idle > 0.0) or (T_preheat > 0.0):
if p.TEST_PIDLELIMIT > p.PMAX:
print (' ' + p.LABEL + ': Adjusting idle power limit to max. value possible with the power supply (' + str(p.PMAX) + ' W).')
p.TEST_PIDLELIMIT = p.PMAX
if p.TEST_VIDLE > p.VMAX:
print (' ' + p.LABEL + ': Adjusting idle voltage to max. value possible with the power supply (' + str(p.VMAX) + ' V).')
p.TEST_VIDLE = p.VMAX
if p.TEST_VIDLE < p.VMIN:
print (' ' + p.LABEL + ': Adjusting idle voltage to min. value possible with the power supply (' + str(p.VMIN) + ' V).')
p.TEST_VIDLE = p.VMIN
if p.TEST_VIDLE_MAX > p.VMAX:
print (' ' + p.LABEL + ': Adjusting max.-idle voltage to max. value possible with the power supply (' + str(p.VMAX) + ' V).')
p.TEST_VIDLE_MAX = p.VMAX
if p.TEST_VIDLE_MAX < p.VMIN:
print (' ' + p.LABEL + ': Adjusting max.-idle voltage to min. value possible with the power supply (' + str(p.VMIN) + ' V).')
p.TEST_VIDLE_MAX = p.VMIN
if p.TEST_VIDLE_MIN > p.VMAX:
print (' ' + p.LABEL + ': Adjusting min.-idle voltage to max. value possible with the power supply (' + str(p.VMAX) + ' V).')
p.TEST_VIDLE_MIN = p.VMAX
if p.TEST_VIDLE_MIN < p.VMIN:
print (' ' + p.LABEL + ': Adjusting min.-idle voltage to min. value possible with the power supply (' + str(p.VMIN) + ' V).')
p.TEST_VIDLE_MIN = p.VMIN
if p.TEST_VIDLE_MIN > p.TEST_VIDLE_MAX:
print (' ' + p.LABEL + ': Adjusting min.-idle voltage to ' + str(p.TEST_VIDLE) + ' V).')
p.TEST_VIDLE_MIN = p.TEST_VIDLE
if p.TEST_VIDLE_MAX < p.TEST_VIDLE_MIN:
print (' ' + p.LABEL + ': Adjusting max.-idle voltage to ' + str(p.TEST_VIDLE) + ' V).')
p.TEST_VIDLE_MAX = p.TEST_VIDLE
if p.TEST_IIDLE > p.IMAX:
print (' ' + p.LABEL + ': Adjusting idle current to max. value possible with the power supply (' + str(p.IMAX) + ' V).')
p.TEST_IIDLE = p.IMIN
if p.TEST_VIDLE * p.TEST_IIDLE > p.PMAX:
p.TEST_IIDLE = p.PMAX / p.TEST_VIDLE
print (' ' + p.LABEL + ': Idle current limit is higher than PSU power limit (' + str(p.PMAX) + ' W). Adjusting idle current limit to ' + str(p.TEST_IIDLE) + ' A.' )
# Print summary of test setup:
print('\nTest setup:')
printit('* Sample: ' + samplename,logfile,'%')
printit('* Date / time: ' + str(datetime.datetime.now()),logfile,'%')
for p in [PSU1, PSU2]:
if not p.CONNECTED:
printit ('* ' + p.LABEL + ': Not connected',logfile,'%')
elif not p.CONFIGURED:
printit ('* ' + p.LABEL + ': Test parameters not configured',logfile,'%')
else:
printit ('* ' + p.LABEL + ':',logfile,'%')
for k in range(len(p._PSU)):
if len(p._PSU) == 1:
printit (' - Type: ' + str(p._PSU[k].COMMANDSET) + ' / ' + p._PSU[k].MODEL,logfile,'%')
else:
printit (' - Type (unit '+str(k+1)+'): ' + str(p._PSU[k].COMMANDSET) + ' / ' + p._PSU[k].MODEL,logfile,'%')
if p.TEST_VSTEP == 0:
printit (' - voltage output = ' + str(p.TEST_VSTART) + ' V (fixed)',logfile,'%')
else:
printit (' - voltage output = ' + str(p.TEST_VSTART) + ' V ... ' + str(p.TEST_VEND) + ' V (' + str(p.TEST_VSTEP) + ' V steps)',logfile,'%')
printit (' - current limit = ' + str(p.TEST_ILIMIT) + ' A',logfile,'%')
printit (' - power limit = ' + str(p.TEST_PLIMIT) + ' W',logfile,'%')
if p.TEST_POLARITY == 1:
printit (' - polarity: normal',logfile,'%')
else:
printit (' - polarity: inverted',logfile,'%')
printit ('* Repeats per reading = ' + str(N_rep),logfile,'%')
if T_idle == 0.0:
printit ('* No idle time between measurements',logfile,'%')
else:
printit ('* Idle time between measurements: ' + str(T_idle) + ' s',logfile,'%')
if T_preheat == 0.0:
printit ('* No pre-heating before measurements',logfile,'%')
else:
printit ('* Pre-heat time before measurements (at idle conditions): ' + str(T_preheat) + ' seconds',logfile,'%')
if (T_idle > 0.0) or (T_preheat > 0.0):
for p in [PSU1, PSU2]:
if p.CONNECTED == False:
printit ('* ' + p.LABEL + ' Idle / pre-heat conditions not configured',logfile,'%')
else:
if p.TEST_VIDLE_MAX == p.TEST_VIDLE_MIN:
printit ('* ' + p.LABEL + ' idle / pre-heat voltage = ' + str(p.TEST_VIDLE) + ' V (fixed value)',logfile,'%')
else:
printit ('* ' + p.LABEL + ' idle / pre-heat voltage range = ' + str(p.TEST_VIDLE_MIN) + ' V ... ' + str(p.TEST_VIDLE_MAX) + ' V.',logfile,'%')
printit ('* ' + p.LABEL + ' idle / pre-heat current = ' + str(p.TEST_IIDLE) + ' A',logfile,'%')
printit ('* ' + p.LABEL + ' max. idle / pre-heat power = ' + str(p.TEST_PIDLELIMIT) + ' W',logfile,'%')
# Ask if okay to start the test
input ('\nReady? Press ENTER to start testing or CTRL+C to abort...')
# Run the test:
printit ('Column 1: PSU1 nominal voltage setting (V)',logfile,'%')
printit ('Column 2: PSU1 nominal current setting (A)',logfile,'%')
printit ('Column 3: PSU1 voltage measurement (V)',logfile,'%')
printit ('Column 4: PSU1 current measurement (I)',logfile,'%')
printit ('Column 5: PSU1 limiter flag',logfile,'%')
printit ('Column 6: PSU2 nominal voltage setting (V)',logfile,'%')
printit ('Column 7: PSU2 nominal current setting (A)',logfile,'%')
printit ('Column 8: PSU2 voltage measurement (V)',logfile,'%')
printit ('Column 9: PSU2 current measurement (I)',logfile,'%')
printit ('Column 10: PSU2 limiter flag',logfile,'%')
print ('\n')
AVGFUNCTION = 'MEAN'
# AVGFUNCTION = 'MEDIAN'
I1LIM = 0.0
I2LIM = 0.0
# determine voltage step values:
V_steps = []
for p in [PSU1,PSU2]:
if not p.CONFIGURED:
V_steps.append( [ 0 ] )
else:
if p.TEST_VSTEP == 0:
# V_steps.append( np.linspace(p.TEST_VSTART,p.TEST_VSTART,1) )
V_steps.append( [ p.TEST_VSTART ] )
else:
if p.TEST_VSTART <= p.TEST_VEND:
u = np.arange( p.TEST_VSTART , p.TEST_VEND+PSU1.TEST_VSTEP , p.TEST_VSTEP )
u = [i for i in u if (i >= p.TEST_VSTART) and (i <= p.TEST_VEND) ] # filter out "outliers" that may happen with large VSTEPs
else:
u = np.arange( p.TEST_VSTART , p.TEST_VEND-PSU1.TEST_VSTEP , -p.TEST_VSTEP )
u = [i for i in u if (i >= p.TEST_VEND) and (i <= p.TEST_VSTART) ] # filter out "outliers" that may happen with large VSTEPs
V_steps.append(u)
try:
# turn on PSU outputs:
for p in [PSU1, PSU2]:
if p.CONFIGURED:
p.setCurrent(0,False)
p.setVoltage(p.VMIN,False)
p.turnOn()
if T_preheat > 0.0:
print ('Pre-heating...\n')
# set idle conditions:
do_idle(PSU1,PSU2,T_preheat,logfile)
print ('Test started...\n')
for V2 in V_steps[1]:
# outer loop (V2)
# get rid of numerical imprecisions (truncate values to voltage resolution of PSU):
# V2 = round(V2/PSU2.VRESSET) * PSU2.VRESSET
limit = 0 # number of CC events at a given step
limit_max = 2 # max. number of CC events before breaking from the loop
if PSU2.CONFIGURED:
# Determine PSU2 current limit (based on DUT limits):
if V2 > 0.0:
I2LIM = min (PSU2.TEST_ILIMIT,PSU2.TEST_PLIMIT/V2)
else:
I2LIM = PSU2.TEST_ILIMIT
# Check if current limit is within power capability of PSU2 (and adjust if necessary):
if (V2*I2LIM) > PSU2.PMAX:
I2LIM = PSU2.PMAX / V2
# set PSU2 voltage + current:
PSU2.setCurrent(I2LIM,False)
PSU2.setVoltage(V2,True)
for V1 in V_steps[0]:
# inner loop (V1)
# get rid of numerical imprecisions (truncate values to voltage resolution of PSU):
# V1 = round(V1/PSU1.VRESSET) * PSU1.VRESSET
# init measurement values
V1MEAS = []
I1MEAS = []
LIMIT1 = 0
V2MEAS = []
I2MEAS = []
LIMIT2 = 0
# measurement loop:
for i in range(N_rep):
if T_idle > 0.0:
do_idle(PSU1,PSU2,T_idle)
# return to required PSU2 output:
if PSU2.CONFIGURED:
PSU2.setCurrent(I2LIM,False)
PSU2.setVoltage(V2,True)
# Determine PSU1 current limit:
if V1 > 0.0:
I1LIM = min (PSU1.TEST_ILIMIT,PSU1.TEST_PLIMIT/V1)
else:
I1LIM = PSU1.TEST_ILIMIT
# Check if current limit is within power capability of PSU1 (and adjust if necessary):
if (V1*I1LIM) > PSU1.PMAX:
I1LIM = PSU1.PMAX / V1
# set up PSU1 measurement conditions:
if PSU1.CONFIGURED:
PSU1.setCurrent(I1LIM,False) # set current limit at PSU1
PSU1.setVoltage(V1,True) # set voltage at PSU1
# wait a bit to get stable conditions before taking the reading:
time.sleep(0.2)
# read PSU output voltages and currents:
r = []
for p in [PSU1, PSU2]:
if p.CONFIGURED:
r.append(p.read(p.NSTABLEREADINGS))
else:
r.append([0.0,0.0,'NONE'])
V1MEAS.append(r[0][0])
I1MEAS.append(r[0][1])
V2MEAS.append(r[1][0])
I2MEAS.append(r[1][1])
if r[0][2] == 'CC':
LIMIT1 = LIMIT1 + 1
if r[1][2] == 'CC':
LIMIT2 = LIMIT2 + 1
# Determine median or mean of repeated readings:
if AVGFUNCTION == 'MEDIAN':
V1MEAS = np.median(V1MEAS)
I1MEAS = np.median(I1MEAS)
V2MEAS = np.median(V2MEAS)
I2MEAS = np.median(I2MEAS)
else:
V1MEAS = np.mean(V1MEAS)
I1MEAS = np.mean(I1MEAS)
V2MEAS = np.mean(V2MEAS)
I2MEAS = np.mean(I2MEAS)
# Check current limits (some PSUs are not very careful with this):
if I1MEAS > I1LIM:
LIMIT1 = 1
if I2MEAS > I2LIM:
LIMIT2 = 1
# Parse limiter flags:
if LIMIT1 > 0:
LIMIT1 = 1
else:
LIMIT1 = 0
if LIMIT2 > 0:
LIMIT2 = 1
else:
LIMIT2 = 0
# Check if current / power limit has been reached:
if (LIMIT1 == 0) and (LIMIT2 == 0):
limit = 0 # reset counter
else:
limit = limit + 1
if limit >= limit_max:
break # break out of the inner loop (V1 steps) and continue with the next V2 step
# Print results:
printit ( "{:10.6f}".format(V1*PSU1.TEST_POLARITY) + ' ' +
"{:10.6f}".format(I1LIM*PSU1.TEST_POLARITY) + ' ' +
"{:10.6f}".format(V1MEAS*PSU1.TEST_POLARITY) + ' ' +
"{:10.6f}".format(I1MEAS*PSU1.TEST_POLARITY) + ' ' +
"{:5d}".format(LIMIT1) + ' ' +
"{:10.6f}".format(V2*PSU2.TEST_POLARITY) + ' ' +
"{:10.6f}".format(I2LIM*PSU2.TEST_POLARITY) + ' ' +
"{:10.6f}".format(V2MEAS*PSU2.TEST_POLARITY) + ' ' +
"{:10.6f}".format(I2MEAS*PSU2.TEST_POLARITY) + ' ' +
"{:5d}".format(LIMIT2) ,
logfile )
print ('Test completed.')
for p in [PSU1, PSU2]:
if p.CONNECTED:
p.turnOff()
except:
print ('\nOooops, something went wrong during testing! Trying to turn off the PSUs...\n')
for p in [PSU1, PSU2]:
if p.CONNECTED:
p.turnOff()
raise