From c5db95ddb131c2af1471581814c63faa20b56b05 Mon Sep 17 00:00:00 2001 From: Jonathan Hogg Date: Thu, 30 Mar 2017 15:00:59 +0100 Subject: [PATCH] Fix bug in calculating SampleAddress that was breaking mixed signal capture --- README.md | 2 ++ scope.py | 13 ++++++------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 4dbf453..29e1e5d 100644 --- a/README.md +++ b/README.md @@ -5,4 +5,6 @@ - Only tested against a BitScope Micro (BS05) - Requires Python >3.6 and the **pyserial** package +- Also requires **NumPy** and **SciPy** if you want to do analog range calibration +- Having **Pandas** is useful for wrapping capture results for further processing diff --git a/scope.py b/scope.py index 0f19dd6..d4d78e3 100755 --- a/scope.py +++ b/scope.py @@ -157,9 +157,10 @@ class Scope(vm.VirtualMachine): nsamples = int(round(period / ticks / self.capture_clock_period / clock_scale / len(analog_channels))) * len(analog_channels) else: nsamples = int(round(period / ticks / self.capture_clock_period / clock_scale)) - total_samples = nsamples*2 if logic_channels and analog_channels else nsamples buffer_width = self.capture_buffer_size // capture_mode.sample_width - if total_samples > buffer_width: + if logic_channels and analog_channels: + buffer_width //= 2 + if nsamples > buffer_width: raise RuntimeError("Capture buffer too small for requested capture") if raw: @@ -234,15 +235,13 @@ class Scope(vm.VirtualMachine): start_timestamp += 1<<32 timestamp += 1<<32 address = int((await self.read_replies(1))[0], 16) - if capture_mode.BufferMode in {vm.BufferMode.Chop, vm.BufferMode.Dual, vm.BufferMode.MacroChop}: + if capture_mode.BufferMode in {vm.BufferMode.Chop, vm.BufferMode.MacroChop, vm.BufferMode.ChopDual}: address -= address % 2 - elif capture_mode.BufferMode == vm.BufferMode.ChopDual: - address -= address % 4 traces = DotDict() for dump_channel, channel in enumerate(sorted(analog_channels)): asamples = nsamples // len(analog_channels) async with self.transaction(): - await self.set_registers(SampleAddress=(address - total_samples) % buffer_width, + await self.set_registers(SampleAddress=(address - nsamples) % buffer_width, DumpMode=vm.DumpMode.Native if capture_mode.sample_width == 2 else vm.DumpMode.Raw, DumpChan=dump_channel, DumpCount=asamples, DumpRepeat=1, DumpSend=1, DumpSkip=0) await self.issue_program_spock_registers() @@ -259,7 +258,7 @@ class Scope(vm.VirtualMachine): if logic_channels: async with self.transaction(): - await self.set_registers(SampleAddress=(address - total_samples) % buffer_width, + await self.set_registers(SampleAddress=(address - nsamples) % buffer_width, DumpMode=vm.DumpMode.Raw, DumpChan=128, DumpCount=nsamples, DumpRepeat=1, DumpSend=1, DumpSkip=0) await self.issue_program_spock_registers() await self.issue_analog_dump_binary()