-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram file.py
More file actions
95 lines (68 loc) · 2.13 KB
/
Copy pathProgram file.py
File metadata and controls
95 lines (68 loc) · 2.13 KB
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
# Automated Load Transient Test
import pyvisa # Instrument communication
import time # Delay & timestamps
import csv # CSV logging
from datetime import datetime
# Test Parameters
INPUT_VOLTAGE = 5.0
LOAD_LOW = 0.5 # Amps
LOAD_HIGH = 2.0 # Amps
STEP_TIME = 0.01 # 10 ms
MAX_UNDERSHOOT = 0.2 # Volts (200mV)
MAX_OVERSHOOT = 0.2
CSV_FILE = "load_transient_results.csv"
# Connect to Instruments
rm = pyvisa.ResourceManager()
psu = rm.open_resource("USB0::PSU_ADDRESS::INSTR")
eload = rm.open_resource("USB0::ELOAD_ADDRESS::INSTR")
scope = rm.open_resource("USB0::SCOPE_ADDRESS::INSTR")
print("Instruments connected")
# Configure Power Supply
psu.write("VOLT {}".format(INPUT_VOLTAGE))
psu.write("OUTP ON")
# Configure Electronic Load
eload.write("MODE CC") # Constant Current
eload.write("CURR {}".format(LOAD_LOW))
eload.write("INPUT ON")
# Configure Oscilloscope
scope.write("TIM:SCAL 1E-3") # 1ms/div
scope.write("TRIG:EDGE:SOUR CH1")
scope.write("TRIG:EDGE:LEV 3.0")
# Open CSV File
with open(CSV_FILE, mode="w", newline="") as file:
writer = csv.writer(file)
writer.writerow([
"Timestamp",
"Undershoot (V)",
"Overshoot (V)",
"Pass/Fail"
])
# Run Load Transient Test
print("Starting load transient test")
# Apply high load
eload.write("CURR {}".format(LOAD_HIGH))
time.sleep(STEP_TIME)
# Return to low load
eload.write("CURR {}".format(LOAD_LOW))
time.sleep(0.05)
# Measure using Scope
undershoot = float(scope.query("MEAS:VMIN? CH1"))
overshoot = float(scope.query("MEAS:VMAX? CH1"))
# Pass / Fail Decision
if abs(undershoot) <= MAX_UNDERSHOOT and abs(overshoot) <= MAX_OVERSHOOT:
result = "PASS"
else:
result = "FAIL"
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
# Log to CSV
writer.writerow([
timestamp,
undershoot,
overshoot,
result
])
print("Test Result:", result)
# Turn OFF Instruments
eload.write("INPUT OFF")
psu.write("OUTP OFF")
print("Test completed")