1
0
mirror of https://github.com/jonathanhogg/scopething synced 2025-07-14 03:02:09 +01:00
This commit is contained in:
Jonathan Hogg
2017-07-14 17:52:55 +01:00
parent 44194ab63e
commit b09acd6905

View File

@ -23,8 +23,6 @@ class DotDict(dict):
class Scope(vm.VirtualMachine): class Scope(vm.VirtualMachine):
PARAMS_MAGIC = 0xb0b2
AnalogParams = namedtuple('AnalogParams', ['rd', 'rr', 'rt', 'rb', 'scale', 'offset']) AnalogParams = namedtuple('AnalogParams', ['rd', 'rr', 'rt', 'rb', 'scale', 'offset'])
@classmethod @classmethod
@ -38,7 +36,7 @@ class Scope(vm.VirtualMachine):
Log.info(f"Connecting to remote scope at {host}:{port}") Log.info(f"Connecting to remote scope at {host}:{port}")
reader, writer = await asyncio.open_connection(host, int(port)) reader, writer = await asyncio.open_connection(host, int(port))
else: else:
raise ValueError(f"Don't know what to do with '{device}'") raise ValueError(f"Don't know what to do with {device!r}")
scope = cls(reader, writer) scope = cls(reader, writer)
await scope.setup() await scope.setup()
return scope return scope
@ -63,6 +61,7 @@ class Scope(vm.VirtualMachine):
self.capture_clock_period = 25e-9 self.capture_clock_period = 25e-9
self.capture_buffer_size = 12<<10 self.capture_buffer_size = 12<<10
self.timeout_clock_period = 6.4e-6 self.timeout_clock_period = 6.4e-6
self.timestamp_rollover = (1<<32) * self.capture_clock_period
else: else:
raise RuntimeError(f"Unsupported scope, revision: {revision}") raise RuntimeError(f"Unsupported scope, revision: {revision}")
self._awg_running = False self._awg_running = False
@ -335,7 +334,7 @@ class Scope(vm.VirtualMachine):
items = [] items = []
await self.start_generator(frequency=1000, waveform='square') await self.start_generator(frequency=1000, waveform='square')
for lo in np.linspace(self.analog_lo_min, 0.5, n, endpoint=False): for lo in np.linspace(self.analog_lo_min, 0.5, n, endpoint=False):
for hi in np.linspace(0.5, self.analog_hi_max, n, endpoint=False): for hi in np.linspace(0.5, self.analog_hi_max, n):
data = await self.capture(channels=['A','B'], period=2e-3, nsamples=2000, timeout=0, low=lo, high=hi, raw=True) data = await self.capture(channels=['A','B'], period=2e-3, nsamples=2000, timeout=0, low=lo, high=hi, raw=True)
A = np.fromiter(data['A'].values(), count=1000, dtype='float') A = np.fromiter(data['A'].values(), count=1000, dtype='float')
A.sort() A.sort()
@ -362,8 +361,8 @@ class Scope(vm.VirtualMachine):
if result.success: if result.success:
Log.info(f"Calibration succeeded: {result.message}") Log.info(f"Calibration succeeded: {result.message}")
params = self.analog_params = self.AnalogParams(*result.x) params = self.analog_params = self.AnalogParams(*result.x)
Log.info(f"Analog parameters: rd={params.rd:.1f}Ω rr={params.rr:.1f}Ω rt={params.rt:.1f} rb={params.rb:.1f}" Log.info(f"Analog parameters: rd={params.rd:.1f}Ω rr={params.rr:.1f}Ω rt={params.rt:.1f} rb={params.rb:.1f}"
f" scale={params.scale:.3f}V offset={params.offset:.3f}V") f"scale={params.scale:.3f}V offset={params.offset:.3f}V")
lo, hi, low, high, offset = items lo, hi, low, high, offset = items
clo, chi = self.calculate_lo_hi(low, high) clo, chi = self.calculate_lo_hi(low, high)
lo_error = np.sqrt((((clo-lo)/(hi-lo))**2).mean()) lo_error = np.sqrt((((clo-lo)/(hi-lo))**2).mean())
@ -410,15 +409,8 @@ async def main():
parser.add_argument('--debug', action='store_true', default=False, help="Debug logging") parser.add_argument('--debug', action='store_true', default=False, help="Debug logging")
args = parser.parse_args() args = parser.parse_args()
logging.basicConfig(level=logging.DEBUG if args.debug else logging.INFO, stream=sys.stdout) logging.basicConfig(level=logging.DEBUG if args.debug else logging.INFO, stream=sys.stdout)
s = await Scope.connect(args.device) s = await Scope.connect(args.device)
#await s.start_generator(2000, 'triangle')
#import numpy as np
#x = np.linspace(0, 2*np.pi, s.awg_wavetable_size, endpoint=False)
#y = (np.sin(x)**5 + 1) / 2
#await s.start_generator(1000, wavetable=y)
def await(g): def await(g):
return asyncio.get_event_loop().run_until_complete(g) return asyncio.get_event_loop().run_until_complete(g)