Skip to content

Commit b8d8cfd

Browse files
committed
Reduce max events from 2499 to 2498
Buffer sometimes contains two false zeros.
1 parent 7fb7c4e commit b8d8cfd

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

PSL/logic_analyzer.py

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -220,20 +220,20 @@ def measure_duty_cycle(self, channel: str, timeout: float = 1) -> Tuple[float]:
220220
self.configure_trigger(trigger_channel=channel, trigger_mode="rising")
221221
tmp_map = self._channel_one_map
222222
self._channel_one_map = channel
223-
t = self.capture(1, 2, modes=["any"], timeout=timeout)[0]
223+
t = self.capture(1, 3, modes=["any"], timeout=timeout)[0]
224224
self._channel_one_map = tmp_map
225225
self.configure_trigger(tmp_trigger_channel, tmp_trigger_mode)
226226

227-
period = t[1]
227+
period = t[2]
228228
# First change is HIGH -> LOW since we trigger on rising.
229-
duty_cycle = t[0] / t[1]
229+
duty_cycle = t[1] / t[2]
230230

231231
return period, duty_cycle
232232

233233
def capture(
234234
self,
235235
channels: int,
236-
events: int = CP.MAX_SAMPLES // 4 - 1,
236+
events: int = CP.MAX_SAMPLES // 4 - 2,
237237
timeout: float = None,
238238
modes: List[str] = 4 * ("any",),
239239
e2e_time: float = None,
@@ -250,7 +250,7 @@ def capture(
250250
ID2, ID3, and ID4, in that order.
251251
events : int, optional
252252
Number of logic events to capture on each channel. The default and maximum
253-
value is 2499.
253+
value is 2498.
254254
timeout : float, optional
255255
Timeout in seconds before cancelling measurement. By default there is
256256
no timeout.
@@ -289,7 +289,6 @@ def capture(
289289
RuntimeError is the timeout is exceeded.
290290
"""
291291
self._check_arguments(channels, events)
292-
events += 1 # Capture an extra event in case we get a spurious zero.
293292
self.clear_buffer(0, CP.MAX_SAMPLES)
294293
self._configure_trigger(channels)
295294
modes = [digital_channel.MODES[m] for m in modes]
@@ -300,6 +299,8 @@ def capture(
300299
):
301300
c = self._channels[c]
302301
c.events_in_buffer = events
302+
# Capture an extra event in case we get a spurious zero.
303+
c._events_in_buffer = events + 2
303304
c.datatype = "long" if channels < 3 else "int"
304305
c.buffer_idx = 2500 * e * (1 if c.datatype == "int" else 2)
305306
c._logic_mode = modes[e]
@@ -312,19 +313,16 @@ def capture(
312313
self._capture_four(e2e_time)
313314

314315
if block:
315-
self._wait_for_progress(old_progress, timeout)
316-
self._timeout(events, timeout)
316+
self._wait_for_progress(timeout)
317+
self._timeout(events + 2, start_time, timeout)
317318
else:
318319
return
319320

320-
timestamps = self.fetch_data()
321-
timestamps = [t[: events - 1] for t in timestamps] # Remove extra events.
322-
323-
return timestamps[:channels] # Discard 4:th channel if user asked for 3.
321+
return self.fetch_data()[:channels] # Discard 4:th channel if user asked for 3.
324322

325323
@staticmethod
326324
def _check_arguments(channels: int, events: int):
327-
max_events = CP.MAX_SAMPLES // 4 - 1
325+
max_events = CP.MAX_SAMPLES // 4 - 2
328326
if events > max_events:
329327
raise ValueError(f"Events must be fewer than {max_events}.")
330328
elif channels < 0 or channels > 4:
@@ -434,7 +432,10 @@ def fetch_data(self) -> List[np.ndarray]:
434432
raw_timestamps = self._fetch_long(c)
435433
else:
436434
raw_timestamps = self._fetch_int(c)
437-
counter_values.append(self._trim_zeros(c, raw_timestamps))
435+
# Remove extra events.
436+
raw_timestamps = self._trim_zeros(c, raw_timestamps)
437+
raw_timestamps = raw_timestamps[: c.events_in_buffer]
438+
counter_values.append(raw_timestamps)
438439

439440
prescaler = [1 / 64, 1 / 8, 1.0, 4.0][self._prescaler]
440441
timestamps = [cv * prescaler for cv in counter_values]
@@ -474,8 +475,6 @@ def _fetch_long(self, channel: digital_channel.DigitalInput) -> np.ndarray:
474475
self._device.get_ack()
475476

476477
while lsb[-1] == 0:
477-
if len(lsb) == 0:
478-
return np.array([])
479478
lsb = lsb[:-1]
480479

481480
# Second half of each long is stored in positions 2501-5000,
@@ -533,14 +532,16 @@ def get_progress(self) -> int:
533532
buffer, the lowest value will be returned.
534533
"""
535534
active_channels = []
535+
a = 0
536536
for c in self._channels.values():
537537
if c.events_in_buffer:
538-
active_channels.append(c)
538+
active_channels.append(a * (1 if c.datatype == "int" else 2))
539+
a += 1
539540

540541
p = CP.MAX_SAMPLES // 4
541542
progress = self._get_initial_states_and_progress()[1]
542-
for i in range(len(active_channels)):
543-
p = min(progress[i], p)
543+
for a in active_channels:
544+
p = min(progress[a], p)
544545

545546
return p
546547

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy