-
Notifications
You must be signed in to change notification settings - Fork 7
/
hp3245a_service.c
331 lines (261 loc) · 7.9 KB
/
hp3245a_service.c
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
from __future__ import print_function
import sys
import time
import hp3458a
import hp3245a
class hp3245service(object):
def __init__(self, dvm, dut, chan):
self.dvm = dvm
self.dut = dut
self.chan = chan
self.term = {
0: "Front Out-A",
1: "Back Out-A",
100: "Front Out-B",
101: "Back Out-B",
}.get(chan)
if self.term is None:
print("Wrong channel [0,1,100,101]")
exit(2)
self.fo = None
self.cable = None
def prompt(self, txt):
print(txt)
sys.stdout.flush()
sys.stdin.readline()
def cable_voltage(self):
if self.cable != "voltage":
self.prompt(self.term + " -> DVM Voltage input")
self.cable = "voltage"
def cable_current(self):
if self.cable != "current":
self.prompt(self.term + " -> DVM Current input")
self.cable = "current"
def dvm_cmds(self, c):
for i in c:
self.dvm.wr(i)
self.dvm.wait_cmd()
self.dvm.AOK()
def dut_cmds(self, c, tmo=10000):
for i in c:
self.dut.wr(i)
self.dut.wait_cmd(tmo)
self.dvm.AOK()
def dut_rst(self):
self.dut_cmds(["RESET %d" % self.chan, "USE %d" % self.chan])
def dvm_rst(self):
self.dvm.reset()
self.dvm_cmds(["NPLC 100", "NDIG 8"])
def dvm_rd(self):
t0 = time.time()
self.dvm.wr("T")
self.dvm.wait_data(tmo=25000)
a = self.dvm.rd()
t1 = time.time()
if t1 - t0 > 15:
print("DT", t1 - t0)
return float(a)
def calibrate(self, calcode=3245):
self.dut_rst()
self.dvm.reset()
self.dvm_cmds(["NPLC 100", "NDIG 8"])
self.cable_voltage()
self.dut_cmds(["CAL %d" % calcode])
for i in range(1,45):
a = self.dvm_rd()
print("%2d" % i, "%13.9f" % a)
self.dut_cmds(["CAL VALUE %.9f" % a])
i = 45
self.dvm_cmds(["RANGE 100"])
a = self.dvm_rd()
print("%2d" % i, "%13.9f" % a)
self.dut_cmds(["CAL VALUE %.9f" % a])
self.dvm_cmds(["RANGE AUTO"])
for i in (46, 47):
a = self.dvm_rd()
print("%2d" % i, "%13.9f" % a)
self.dut_cmds(["CAL VALUE %.9f" % a])
self.dvm_cmds(["DCI"])
self.cable_current()
for i in range(48, 71):
a = self.dvm_rd()
print("%2d" % i, "%13.9f" % a)
self.dut_cmds(["CAL VALUE %.9f" % a])
i = 72
a = self.dvm_rd()
print("%2d" % i, "%13.9f" % a)
self.dut_cmds(["CAL VALUE %.9f" % a], tmo=60000)
def hdr(self, txt):
print()
print(txt)
print("-" * len(txt))
if not self.fo is None:
self.fo.write("\n" + txt + "\n")
self.fo.write("-" * len(txt) + "\n")
def one_test(self, lo, target, hi, unit, cmds=None):
if not cmds is None:
self.dut_cmds(cmds)
s = ""
a = self.dvm_rd()
if a < lo or a > hi:
t = "FAIL"
else:
t = "PASS"
s += "[%13.9f" % lo
if target is None:
r = " "
s += "%13s" % ""
else:
r = "%5.1f%%" % (100.0 * (a - target) / (hi - lo))
s += " %13.9f" % target
s += " %13.9f]" % hi
s += " %13.9f" % a
s += " %-3s" % unit
s += " " + r
s += " " + t
print(s)
if not self.fo is None:
self.fo.write(s + "\n")
def sym_test(self, target, band, unit, cmds=None):
self.one_test(target - band, target, target + band, unit, cmds)
def asym_test(self, app, target, band, unit, goal=None):
if goal is None:
goal = target
self.one_test(goal - band, goal, goal + band, unit,
cmds = ["APPLY " + app + " %.6f" % target])
def operational_verification(self):
self.fo = open(
"_hp3245_operational_verification_%d.txt" % self.chan, "w")
if True:
self.op_ver_dcv()
if True:
self.op_ver_acv()
if True:
self.op_ver_offset()
if True:
self.op_ver_flatness()
self.cable_current()
if True:
self.op_ver_dci()
self.fo.close()
self.fo = None
def op_ver_dcv(self):
self.hdr("DCV Amplitude Accuracy - High Res")
self.dvm_rst()
self.dut_rst()
self.cable_voltage()
self.dut_cmds(["RANGE 1"])
self.asym_test("DCV", 1.25, 84e-6, "V")
self.asym_test("DCV", 0.00, 31e-6, "V")
self.asym_test("DCV", -1.25, 84e-6, "V")
self.dut_cmds(["RANGE 10"])
self.asym_test("DCV", 10.25, 570e-6, "V")
self.asym_test("DCV", 0.00, 180e-6, "V")
self.asym_test("DCV", -10.25, 570e-6, "V")
self.hdr("DCV Amplitude Accuracy - Low Res")
self.dut_rst()
self.dut_cmds(["DCRES LOW", "RANGE .15625"])
self.asym_test("DCV", .15625, 1.00e-3, "V")
self.asym_test("DCV", .00000, .73e-3, "V")
self.asym_test("DCV", -.15625, 1.00e-3, "V")
self.dut_cmds(["RANGE 10"])
self.asym_test("DCV", 10.0, 54e-3, "V")
self.asym_test("DCV", 0.0, 37e-3, "V")
self.asym_test("DCV", -10.0, 54e-3, "V")
self.hdr("DCV Zero Ohm Output Resistance")
self.dut_rst()
self.dvm_cmds(["OHM"])
self.one_test(0, None, .5, "Ohm")
def op_ver_dci(self):
self.hdr("DCI Amplitude Accuracy - High Res")
self.dut_rst()
self.dvm_rst()
self.dvm_cmds(["DCI"])
self.cable_current()
self.dut_cmds(["RANGE 0.0001"])
self.asym_test("DCI", .0001, 8.5e-9, "A")
self.asym_test("DCI", .0000, 3.3e-9, "A")
self.asym_test("DCI", -.0001, 8.5e-9, "A")
self.dut_cmds(["RANGE 0.1"])
self.asym_test("DCI", .1, 23.3e-6, "A")
self.asym_test("DCI", .0, 3.3e-6, "A")
self.asym_test("DCI", -.1, 23.3e-6, "A")
self.hdr("DCI Amplitude Accuracy - Low Res")
self.dut_rst()
self.dut_cmds(["DCRES LOW", "RANGE 0.0001"])
self.asym_test("DCI", .0001, 630e-9, "A")
self.asym_test("DCI", .0000, 380e-9, "A")
self.asym_test("DCI", -.0001, 630e-9, "A")
self.dut_cmds(["RANGE 0.1"])
self.asym_test("DCI", .1, 720e-6, "A")
self.asym_test("DCI", .0, 400e-6, "A")
self.asym_test("DCI", -.1, 720e-6, "A")
def op_ver_acv(self):
self.dvm_cmds(["ACV", "ACBAND 1000"])
self.dut_rst()
self.dvm_rst()
self.dvm_cmds(["ACV"])
self.cable_voltage()
self.hdr("ACV Amplitude Accuracy - Sine Wave")
self.dut_cmds(["IMP 50", "APPLY ACV .15625", "RANGE .15625"])
self.asym_test("ACV", .15625, 720e-6, "V", .11047)
self.asym_test("ACV", .11719, 640e-6, "V", .08282)
self.asym_test("ACV", .07813, 560e-6, "V", .05523)
self.dut_cmds(["ARANGE ON", "APPLY ACV 10", "RANGE 10"])
self.asym_test("ACV", 10.0, 46e-3, "V", 7.070)
self.asym_test("ACV", 7.5, 41e-3, "V", 5.303)
self.asym_test("ACV", 5.0, 36e-3, "V", 3.535)
self.dut_rst()
self.hdr("ACV Amplitude Accuracy - Square Wave")
self.dut_cmds(["IMP 50", "APPLY SQV .15625", "RANGE .15625"])
self.asym_test("SQV", .15625, 1.27e-3, "V")
self.asym_test("SQV", .11719, 1.15e-3, "V")
self.asym_test("SQV", .07813, 1.04e-3, "V")
self.dut_cmds(["ARANGE ON", "APPLY SQV 10", "RANGE 10"])
self.asym_test("SQV", 10.0, 81e-3, "V")
self.asym_test("SQV", 7.5, 74e-3, "V")
self.asym_test("SQV", 5.0, 67e-3, "V")
self.dut_rst()
def op_ver_offset(self):
self.hdr("Offset Accuracy")
self.dut_rst()
self.dvm_rst()
self.cable_voltage()
self.dvm_cmds(["DCV"])
self.dut_cmds(["IMP 50", "APPLY ACV 5", "FREQ 600"])
self.dut_cmds(["DCOFF -2.5"])
self.asym_test("ACV", 5.0, 86.5e-3, "V", -5.0)
self.dut_cmds(["DCOFF 2.5"])
self.asym_test("ACV", 5.0, 86.5e-3, "V", +5.0)
self.dut_cmds(["DCOFF 0.0390625"])
self.asym_test("ACV", .078125, 1.352e-3, "V", 0.078125)
self.dut_cmds(["DCOFF -0.0390625"])
self.asym_test("ACV", .078125, 1.352e-3, "V", -0.078125)
def op_ver_flatness(self):
self.hdr("Flatness")
self.dut_rst()
self.dvm_rst()
self.cable_voltage()
self.dvm_cmds(["ACDCV"])
self.dut_cmds(["IMP 50", "APPLY ACV 10", "FREQ 1000"])
self.asym_test("ACV", 10.0, 54e-3, "V", 7.070)
self.dvm_cmds(["SMATH 9", "MATH DB"])
self.dut_cmds(["FREQ 10000"])
self.asym_test("ACV", 10.0, .07, "dB", 0.0)
self.dut_cmds(["FREQ 1000000"])
self.asym_test("ACV", 10.0, 2.0, "dB", 0.0)
if __name__ == "__main__":
dvm = hp3458a.hp3458a()
dut = hp3245a.hp3245a()
for a in sys.argv[1:]:
if a == "-cal_a":
hp3245service(dvm, dut, 0).calibrate()
elif a == "-cal_b":
hp3245service(dvm, dut, 100).calibrate()
elif a == "-check_a":
hp3245service(dvm, dut, 0).operational_verification()
elif a == "-check_b":
hp3245service(dvm, dut, 100).operational_verification()
else:
print("Unknown argument")
exit(2)