@@ -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
191202def 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 (
0 commit comments