From bc6f585e2bae4b3a717428d258ab8c354e5e921d Mon Sep 17 00:00:00 2001 From: Jonathan Hogg Date: Mon, 27 Mar 2017 13:31:28 +0100 Subject: [PATCH] More work on triggering --- scope.py | 61 ++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 37 insertions(+), 24 deletions(-) diff --git a/scope.py b/scope.py index a3c69f8..732b7ed 100755 --- a/scope.py +++ b/scope.py @@ -6,6 +6,7 @@ import logging import math import os import struct +import sys import streams import vm @@ -57,7 +58,7 @@ class Scope(vm.VirtualMachine): self.analog_max = 8 self.capture_clock_period = 25e-9 self.capture_buffer_size = 12*1024 - self.trigger_timeout_tick = 6.4e-6 + self.timeout_clock_period = 6.4e-6 self.trigger_low = -7.517 self.trigger_high = 10.816 # await self.load_params() XXX switch this off until I understand EEPROM better @@ -101,7 +102,7 @@ class Scope(vm.VirtualMachine): return dl, dh async def capture(self, channels=['A'], trigger_channel=None, trigger_level=None, trigger_type='rising', hair_trigger=False, - period=1e-3, nsamples=1000, timeout=None, low=None, high=None, raw=False): + period=1e-3, nsamples=1000, timeout=None, low=None, high=None, raw=False, trigger_point=0.5): channels = list(channels) analog_channels = [channel for channel in channels if channel in {'A', 'B'}] logic = 'L' in channels @@ -121,13 +122,14 @@ class Scope(vm.VirtualMachine): continue break else: - raise RuntimeError(f"Unsupported clock period: {ticks}") + raise RuntimeError("Unable to find appropriate capture mode") if capture_mode.clock_max is not None and ticks > capture_mode.clock_max: ticks = capture_mode.clock_max nsamples = int(round(period / ticks / self.capture_clock_period / clock_scale)) - total_samples = nsamples*2 if logic else nsamples + total_samples = nsamples*2 if logic and analog_channels else nsamples buffer_width = self.capture_buffer_size // capture_mode.sample_width - assert total_samples <= buffer_width + if total_samples > buffer_width: + raise RuntimeError("Capture buffer too small for requested capture") if raw: lo, hi = low, high @@ -138,9 +140,6 @@ class Scope(vm.VirtualMachine): high = self.analog_max lo, hi = self.calculate_lo_hi(low, high) - if self._generator_running: - kitchen_sink_b |= vm.KitchenSinkB.WaveformGeneratorEnable - analog_enable = 0 if 'A' in channels: analog_enable |= 1 @@ -178,7 +177,7 @@ class Scope(vm.VirtualMachine): spock_option = vm.SpockOption.TriggerTypeSampledAnalog kitchen_sink_a = kitchen_sink_b = trigger_mask = trigger_logic = 0 if trigger_level is not None: - for channel, value in trigger_level: + for channel, value in trigger_level.items(): if channel.startswith('L'): mask = 1<] +In [5]: t.interpolate().plot() +Out[5]: -In [5]: +In [6]: """ async def main(): - global s, x, y, data + global s parser = argparse.ArgumentParser(description="scopething") parser.add_argument('device', nargs='?', default=None, type=str, help="Device to connect to") + parser.add_argument('--debug', action='store_true', default=False, help="Debug logging") args = parser.parse_args() + logging.basicConfig(level=logging.DEBUG if args.debug else logging.INFO, stream=sys.stdout) + s = await Scope.connect(args.device) #x = np.linspace(0, 2*np.pi, s.awg_wavetable_size, endpoint=False) #y = np.round((np.sin(x)**5)*127 + 128, 0).astype('uint8') @@ -391,7 +406,5 @@ def generate(*args, **kwargs): return await(s.start_generator(*args, **kwargs)) if __name__ == '__main__': - import sys - logging.basicConfig(level=logging.DEBUG, stream=sys.stderr) asyncio.get_event_loop().run_until_complete(main())