Skip to content

Commit 521f9ce

Browse files
authored
Merge pull request #281 from dmiskovic-NV/dejan-nv-dirty-psu-fix
hopeful fix for dirty PSUs [ready for review and testing]
2 parents 6a3e2cb + 2980f54 commit 521f9ce

File tree

2 files changed

+65
-19
lines changed

2 files changed

+65
-19
lines changed

ptd_client_server/lib/server.py

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,13 @@ def is_finished(self) -> bool:
132132
return self._cur_number >= len(self.words) - 1
133133

134134

135-
def max_volts_amps(
135+
def max_volts_amps_avg_watts(
136136
log_fname: str, mark: str, start_channel: int, amount_of_channels: int
137-
) -> Tuple[str, str]:
137+
) -> Tuple[str, str, str]:
138138
maxVolts = Decimal("-1")
139139
maxAmps = Decimal("-1")
140+
avgWatts = Decimal("-1")
141+
watts = []
140142
with open(log_fname, "r") as f:
141143
for line in f:
142144
m = RE_PTD_LOG.match(line.rstrip("\r\n"))
@@ -145,7 +147,12 @@ def max_volts_amps(
145147
parser.lit("Time")
146148
parser.skip()
147149
parser.lit("Watts")
148-
parser.skip()
150+
if amount_of_channels == 0:
151+
watts_raw = parser.decimal()
152+
if watts_raw > 0:
153+
watts.append(watts_raw)
154+
else:
155+
parser.skip()
149156
parser.lit("Volts")
150157
volts = parser.decimal()
151158
parser.lit("Amps")
@@ -167,7 +174,7 @@ def max_volts_amps(
167174
channel_range.pop(0)
168175
parser.skip()
169176
parser.lit("Watts")
170-
parser.skip()
177+
watts_raw = parser.decimal()
171178
parser.lit("Volts")
172179
volts = parser.decimal()
173180
parser.lit("Amps")
@@ -177,15 +184,19 @@ def max_volts_amps(
177184
if is_sutable_channel:
178185
maxVolts = max(maxVolts, volts)
179186
maxAmps = max(maxAmps, amps)
187+
if watts_raw > 0:
188+
watts.append(watts_raw)
180189
if len(channel_range) == 0:
181190
break
182191
if len(channel_range):
183192
raise ExtraChannelError(
184193
f"There are extra ptd channels in configuration"
185194
)
186-
if maxVolts <= 0 or maxAmps <= 0:
187-
raise MaxVoltsAmpsNegativeValuesError(f"Could not find values for {mark!r}")
188-
return str(maxVolts), str(maxAmps)
195+
if len(watts) >= 1:
196+
avgWatts = Decimal(sum(watts) / len(watts))
197+
else:
198+
avgWatts = Decimal(-1)
199+
return str(maxVolts), str(maxAmps), str("%.6f" % avgWatts)
189200

190201

191202
def read_log(log_fname: str, mark: str) -> str:
@@ -812,6 +823,8 @@ def __init__(self, server: Server, label: str) -> None:
812823
self._state = SessionState.INITIAL
813824
self._maxAmps: Optional[str] = None
814825
self._maxVolts: Optional[str] = None
826+
self._avgWatts: Optional[str] = None
827+
self._desirableCurrentRange: Optional[str] = None
815828

816829
def start(self, mode: Mode) -> bool:
817830
if mode == Mode.RANGING and self._state == SessionState.RANGING:
@@ -855,7 +868,7 @@ def start(self, mode: Mode) -> bool:
855868
self._server._summary.phase("testing", 0)
856869
self._ptd.start()
857870
self._ptd.cmd(f"SR,V,{self._maxVolts}")
858-
self._ptd.cmd(f"SR,A,{self._maxAmps}")
871+
self._ptd.cmd(f"SR,A,{self._desirableCurrentRange}")
859872
with common.sig:
860873
time.sleep(ANALYZER_SLEEP_SECONDS)
861874
logging.info("Starting testing mode")
@@ -914,13 +927,29 @@ def stop(self, mode: Mode) -> bool:
914927
if len(self._server._config.ptd_channel) == 2:
915928
channels_amount = self._server._config.ptd_channel[1]
916929

917-
self._maxVolts, self._maxAmps = max_volts_amps(
930+
(
931+
self._maxVolts,
932+
self._maxAmps,
933+
self._avgWatts,
934+
) = max_volts_amps_avg_watts(
918935
self._server._config.ptd_logfile,
919936
self._id + "_ranging",
920937
start_channel,
921938
channels_amount,
922939
)
923940

941+
# we will query average power consumed and depending on that, we will add fix to crest factor
942+
# default is crest factor 3 (pek current is 3x rms current)
943+
# PSUs under 75W don't have mandatory Power Factor Correction, so they can be arbitrarily dirty
944+
# Tektronix' app note on power supplies claims that power supplies typically exhibit crest factor between 4 and 10
945+
# https://assets.testequity.com/te1/Documents/pdf/power-measurements_AC-DC-an.pdf
946+
# in order to achieve same peak detection, range should be 3.3 higher than max measured RMS (since crest factor of meter is 3 and 3*3.3 is almost 10 :) )
947+
948+
if float(self._avgWatts) < 75:
949+
self._desirableCurrentRange = str(float(self._maxAmps) * 3.3)
950+
else:
951+
self._desirableCurrentRange = str(float(self._maxAmps) * 1.1)
952+
924953
except MaxVoltsAmpsNegativeValuesError as e:
925954
if test_duration < 1:
926955
raise MeasurementEndedTooFastError(

ptd_client_server/tests/unit/test_server.py

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def test_tcp_port_is_occupied() -> None:
4949
assert server.tcp_port_is_occupied(9999) is False
5050

5151

52-
def test_max_volts_amps(tmp_path: Path) -> None:
52+
def test_max_volts_amps_avg_watts(tmp_path: Path) -> None:
5353
with open(tmp_path / "logs_tmp", "wb") as f:
5454
f.write(
5555
b"Time,11-07-2020 17:49:06.145,NOTICE,Analyzer identity response of 32 bytes: YOKOGAWA,WT310,C2PH13047V,F1.03\n"
@@ -65,30 +65,47 @@ def test_max_volts_amps(tmp_path: Path) -> None:
6565
b"Time,11-13-2020 22:39:00.239,Watts,275.630000,Volts,-1.000000,Amps,-1.000000,PF,-1.000000,Mark,notset1,Ch1,Watts1,91.960000,Volts,120.910000,Amps,0.810300,PF,0.938600,Ch2,Watts,91.870000,Volts,120.830000,Amps,0.810400,PF,0.938500,Ch3,Watts,91.800000,Volts,120.730000,Amps,0.810200,PF,0.938400\n"
6666
)
6767

68-
assert server.max_volts_amps(str(tmp_path / "logs_tmp"), "notset", 3, 1) == (
68+
assert server.max_volts_amps_avg_watts(
69+
str(tmp_path / "logs_tmp"), "notset", 3, 1
70+
) == (
6971
"120.750000",
7072
"0.810300",
73+
"91.500000",
7174
)
72-
assert server.max_volts_amps(str(tmp_path / "logs_tmp"), "notset", 2, 2) == (
75+
assert server.max_volts_amps_avg_watts(
76+
str(tmp_path / "logs_tmp"), "notset", 2, 2
77+
) == (
7378
"120.850000",
7479
"0.810400",
80+
"91.535000",
7581
)
7682
with pytest.raises(server.ExtraChannelError) as excinfo:
77-
server.max_volts_amps(str(tmp_path / "logs_tmp"), "notset", 2, 4)
83+
server.max_volts_amps_avg_watts(str(tmp_path / "logs_tmp"), "notset", 2, 4)
7884
assert "There are extra ptd channels in configuration" in str(excinfo.value)
7985

80-
assert server.max_volts_amps(str(tmp_path / "logs_tmp"), "notset", 1, 3) == (
86+
assert server.max_volts_amps_avg_watts(
87+
str(tmp_path / "logs_tmp"), "notset", 1, 3
88+
) == (
8189
"120.950000",
8290
"0.832100",
91+
"91.576667",
8392
)
84-
assert server.max_volts_amps(
93+
assert server.max_volts_amps_avg_watts(
8594
str(tmp_path / "logs_tmp"), "2021-01-22_15-05-02_loadgen_ranging", 0, 0
86-
) == ("227.370000", "0.225410")
95+
) == (
96+
"227.370000",
97+
"0.225410",
98+
"24.980000",
99+
)
87100

88-
assert server.max_volts_amps(
101+
assert server.max_volts_amps_avg_watts(
89102
str(tmp_path / "logs_tmp"), "2021-01-22_15-05-02_loadgen_ranging", 1, 0
90-
) == ("227.370000", "0.225410")
103+
) == (
104+
"227.370000",
105+
"0.225410",
106+
"24.980000",
107+
)
91108

92109
with pytest.raises(server.LitNotFoundError) as excinfo:
93-
server.max_volts_amps(str(tmp_path / "logs_tmp"), "notset1", 1, 3)
110+
server.max_volts_amps_avg_watts(str(tmp_path / "logs_tmp"), "notset1", 1, 3)
94111
assert "Expected 'Watts', got 'Watts1'" in str(excinfo.value)

0 commit comments

Comments
 (0)