-
Notifications
You must be signed in to change notification settings - Fork 2
/
run_adc_self_test.py
executable file
·167 lines (132 loc) · 7.71 KB
/
run_adc_self_test.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
#!/usr/bin/python
from Test import Test
from HwInterface.ADS124 import ADS124
from multiprocessing import Pipe
import sys
class ADC(Test):
def __init__(self, conn, board_sn=-1, tester='', device=1, bus=3, cshigh=False, max_speed=5000000, read_reg=False, write_reg=False, register=None, value=None):
self.info_dict = {'name': "ADC Self Test", 'board_sn': board_sn, 'tester': tester}
self.conn = conn
Test.__init__(self, self.adc, self.info_dict, conn, device=device, bus=bus, cshigh=cshigh, max_speed=max_speed, read_reg=read_reg, write_reg=write_reg, register=register, value=value)
def adc(self, **kwargs):
self.passed = True
self.test_data = {}
passed_list = [True for i in range(7)]
device = kwargs['device']
bus = kwargs['bus']
cshigh = kwargs['cshigh']
max_speed = kwargs['max_speed']
read_reg = kwargs['read_reg']
write_reg = kwargs['write_reg']
register = kwargs['register']
value = kwargs['value']
print(device, bus)
for device in range(0,4):
self.test_data["device_{}".format(device)] = {}
self.conn.send("Initializing test for device {}".format(device))
thisADS124 = ADS124(bus, device, cshigh, max_speed)
if write_reg:
thisADS124.write_reg(register,value)
if read_reg:
data = thisADS124.read_reg(register)
print(data)
thisADS124.wakeup()
thisADS124.reset()
print('resetting POR flag')
thisADS124.reset_POR_flag()
print('status register: '+ str(bin(thisADS124.read_reg(thisADS124.STATUS_REG)[0])))
thisADS124.ref_input(2)
thisADS124.ref_config(2)
thisADS124.self_offset_cal()
thisADS124.set_gain(gain=1)
thisADS124.conversion_mode(continuous=False)
print('set to single shot conversion mode')
#print('datarate register: ' + str(bin(thisADS124.read_reg(thisADS124.DATARATE_REG)[0])))
print('-------------------------------------------------------')
print('set to system monitor mode 1')
thisADS124.sys_monitor_config(config=1)
thisADS124.start()
print('PGA inputs shorted to (AVDD + AVSS) / 2 and disconnected from AINx and the multiplexer; gain is set to ' + str(thisADS124.get_gain()) )
#print('system monitor register: ' + str(bin(thisADS124.read_reg(thisADS124.SYS_REG)[0])))
result1 = thisADS124.read_volts()
if result1 > 0.01:
passed_list[0] = False
self.test_data["device_{}".format(device)]["test_1"] = {"Passed": passed_list[0], "Result": f'{result1:.3f} volts', "Raw_Result": str(thisADS124.read_data())}
self.conn.send("Result 1: {} V =< 0.01 V \t {}".format(result1, passed_list[0]))
print(self.test_data["device_{}".format(device)]["test_1"])
print('-------------------------------------------------------')
print('set to system monitor mode 2')
thisADS124.sys_monitor_config(config=2)
thisADS124.start()
print('Internal temperature sensor measurement; gain set to ' + str(thisADS124.get_gain()) )
result2 = thisADS124.read_volts()*(10.0**5)*(1.0/403.0)*9.0/5.0 + 32.0
if result2 >= 100 or result2 <= 80:
passed_list[1] = False
self.test_data["device_{}".format(device)]["test_2"] = {"Passed": passed_list[1], "Result": f'{result2:.3f} degrees (F)', "Raw_Result": str(thisADS124.read_data())}
self.conn.send("Result 2: {} Degrees F \t {} ".format(result2, passed_list[1]))
print(self.test_data["device_{}".format(device)]["test_2"])
print('-------------------------------------------------------')
print('set to system monitor mode 3')
thisADS124.sys_monitor_config(config=3)
thisADS124.start()
print("Gain Set to: " + str(thisADS124.get_gain()) )
result3 = thisADS124.read_volts()
if result3 >= 0.84 or result3 <= 0.82:
passed_list[2] = False
self.test_data["device_{}".format(device)]["test_3"] = {"Passed": passed_list[2], "Result": f'{result3:.3f} volts', "Raw_Result": str(thisADS124.read_data())}
self.conn.send("Result 3: {} V ~ 0.83 V \t {} ".format(result3, passed_list[2]))
print(self.test_data["device_{}".format(device)]["test_3"])
print('-------------------------------------------------------')
print('set to system monitor mode 4')
thisADS124.sys_monitor_config(config=4)
thisADS124.start()
print('DVDD / 4 measurement; gain set to ' + str(thisADS124.get_gain()) )
result4 = thisADS124.read_volts()
if result4 >= 0.84 or result4 <= 0.82:
passed_list[3] = False
self.test_data["device_{}".format(device)]["test_4"] = {"Passed": passed_list[3], "Result": f'{result4:.3f} volts', "Raw_Result": str(thisADS124.read_data())}
self.conn.send("Result 4: {} V ~ 0.83 V \t {} ".format(result4, passed_list[3]))
print(self.test_data["device_{}".format(device)]["test_4"])
print('-------------------------------------------------------')
#print('set to system monitor mode 5')
#thisADS124.sys_monitor_config(config=5)
#thisADS124.start()
#print('Burn-out current sources enabled, 0.2 uA setting; gain set to ' + str(thisADS124.get_gain()) )
#result5 = thisADS124.read_volts()
#if result5 >= 0.002 or result5 <= 0.001:
# passed_list[4] = False
#self.test_data["test_5"] = {"Passed": passed_list[4], "Result": f'{result5:.4f} volts', "Raw_Result": str(thisADS124.read_data())}
#print(self.test_data["test_5"])
#print('-------------------------------------------------------')
#print('set to system monitor mode 6')
#thisADS124.sys_monitor_config(config=6)
#thisADS124.start()
#print('Burn-out current sources enabled, 1 uA setting; gain set to ' + str(thisADS124.get_gain()) )
#result6 = thisADS124.read_volts()
#if result6 >= 0.01 or result6 <= 0.005:
# passed_list[5] = False
#self.test_data["test_6"] = {"Passed": passed_list[5], "Result": f'{result6:.4f} volts', "Raw_Result": str(thisADS124.read_data())}
#print(self.test_data["test_6"])
#print('-------------------------------------------------------')
#print('set to system monitor mode 7')
#thisADS124.sys_monitor_config(config=7)
#thisADS124.start()
#print('Burn-out current sources enabled, 10 uA setting; gain set to ' + str(thisADS124.get_gain()) )
#result7 = thisADS124.read_volts()
#if result7 >= 0.1 or result7 <= 0.05:
# passed_list[6] = False
#self.test_data["test_7"] = {"Passed": passed_list[6], "Result": f'{result7:.4f} volts', "Raw_Result": str(thisADS124.read_data())}
#print(self.test_data["test_7"])
self.passed &= all(passed_list)
#self.conn.send("LCD ; Passed:{} Test:1".format(self.passed))
thisADS124.close()
self.conn.send("Done.")
print('Done.')
#print({"pass": self.passed, "data": self.test_data})
return self.passed, self.test_data
if __name__ == '__main__':
c1, c2 = Pipe()
sn = sys.argv[1]
tester = sys.argv[2]
test_info = {'board_sn': str(sn), 'tester': tester}
ADC(c1, **test_info)