pdq2: move initialization and park/unpark to driver

This commit is contained in:
Robert Jördens 2016-02-21 18:13:20 +01:00
parent bc81be1345
commit 1b410abc2c
4 changed files with 42 additions and 35 deletions

View File

@ -128,6 +128,7 @@ class Pdq2:
PDQ DAC (a.k.a. QC_Waveform) PDQ DAC (a.k.a. QC_Waveform)
""" """
num_dacs = 3 num_dacs = 3
freq = 50e6
_escape = b"\xa5" _escape = b"\xa5"
_commands = "RESET TRIGGER ARM DCM START".split() _commands = "RESET TRIGGER ARM DCM START".split()
@ -146,6 +147,12 @@ class Pdq2:
def get_num_channels(self): def get_num_channels(self):
return self.num_channels return self.num_channels
def get_freq(self):
return self.freq
def set_freq(self, freq):
self.freq = float(freq)
def close(self): def close(self):
self.dev.close() self.dev.close()
del self.dev del self.dev
@ -172,6 +179,16 @@ class Pdq2:
def flush(self): def flush(self):
self.dev.flush() self.dev.flush()
def park(self):
self.cmd("START", False)
self.cmd("TRIGGER", True)
self.flush()
def unpark(self):
self.cmd("TRIGGER", False)
self.cmd("START", True)
self.flush()
def program_segments(self, segments, data): def program_segments(self, segments, data):
for i, line in enumerate(data): for i, line in enumerate(data):
dac_divider = line.get("dac_divider", 1) dac_divider = line.get("dac_divider", 1)

View File

@ -172,6 +172,8 @@ class CompoundPDQ2:
frame._invalidate() frame._invalidate()
self.frames = [] self.frames = []
self.armed = False self.armed = False
for dev in self.pdq2s:
dev.park()
def arm(self): def arm(self):
if self.armed: if self.armed:
@ -196,6 +198,8 @@ class CompoundPDQ2:
frame_program.append(line) frame_program.append(line)
program.append(frame_program) program.append(frame_program)
pdq2.program(program) pdq2.program(program)
for pdq2 in self.pdq2s:
pdq2.unpark()
def create_frame(self): def create_frame(self):
if self.armed: if self.armed:

View File

@ -2,7 +2,6 @@
# Copyright (C) 2012-2015 Robert Jordens <jordens@gmail.com> # Copyright (C) 2012-2015 Robert Jordens <jordens@gmail.com>
import argparse import argparse
import time
from scipy import interpolate from scipy import interpolate
import numpy as np import numpy as np
@ -31,12 +30,6 @@ def get_argparser():
parser.add_argument("-o", "--order", default=3, type=int, parser.add_argument("-o", "--order", default=3, type=int,
help="interpolation (0: const, 1: lin, 2: quad," help="interpolation (0: const, 1: lin, 2: quad,"
" 3: cubic) [%(default)s]") " 3: cubic) [%(default)s]")
parser.add_argument("-r", "--reset", default=False,
action="store_true", help="do reset before")
parser.add_argument("-m", "--multiplier", default=False,
action="store_true", help="100MHz clock [%(default)s]")
parser.add_argument("-n", "--disarm", default=False, action="store_true",
help="disarm group [%(default)s]")
parser.add_argument("-e", "--free", default=False, action="store_true", parser.add_argument("-e", "--free", default=False, action="store_true",
help="software trigger [%(default)s]") help="software trigger [%(default)s]")
verbosity_args(parser) verbosity_args(parser)
@ -48,24 +41,10 @@ def main():
init_logger(args) init_logger(args)
dev = Client(args.server, args.port, "pdq2") dev = Client(args.server, args.port, "pdq2")
if args.reset: freq = dev.get_freq()
dev.write(b"\x00\x00") # flush any escape
dev.cmd("RESET", True)
time.sleep(.1)
dev.cmd("DCM", args.multiplier)
freq = 50e6
if args.multiplier:
freq *= 2
times = np.around(eval(args.times, globals(), {})*freq) times = np.around(eval(args.times, globals(), {})*freq)
voltages = eval(args.voltages, globals(), dict(t=times/freq)) voltages = eval(args.voltages, globals(), dict(t=times/freq))
dev.cmd("START", False)
dev.cmd("ARM", True)
dev.cmd("TRIGGER", True)
dev.flush()
dt = np.diff(times.astype(np.int)) dt = np.diff(times.astype(np.int))
if args.order: if args.order:
tck = interpolate.splrep(times, voltages, k=args.order, s=0) tck = interpolate.splrep(times, voltages, k=args.order, s=0)
@ -84,12 +63,10 @@ def main():
}) })
program = [[] for i in range(args.frame)] program = [[] for i in range(args.frame)]
program.append(segment) program.append(segment)
dev.park()
dev.program(program, [args.channel]) dev.program(program, [args.channel])
dev.unpark()
dev.cmd("TRIGGER", args.free) dev.cmd("TRIGGER", args.free)
dev.cmd("ARM", not args.disarm)
dev.cmd("START", True)
dev.flush()
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -2,6 +2,7 @@
import argparse import argparse
import sys import sys
import time
from artiq.devices.pdq2.driver import Pdq2 from artiq.devices.pdq2.driver import Pdq2
from artiq.protocols.pc_rpc import simple_server_loop from artiq.protocols.pc_rpc import simple_server_loop
@ -11,14 +12,15 @@ from artiq.tools import *
def get_argparser(): def get_argparser():
parser = argparse.ArgumentParser(description="PDQ2 controller") parser = argparse.ArgumentParser(description="PDQ2 controller")
simple_network_args(parser, 3252) simple_network_args(parser, 3252)
parser.add_argument( parser.add_argument("-d", "--device", default=None, help="serial port")
"-d", "--device", default=None, help="serial port.") parser.add_argument("--simulation", action="store_true",
parser.add_argument( help="do not open any device but dump data")
"--simulation", action="store_true", parser.add_argument("--dump", default="pdq2_dump.bin",
help="Put the driver in simulation mode, even if --device is used.") help="file to dump simulation data into")
parser.add_argument( parser.add_argument("-r", "--reset", default=False,
"--dump", default="pdq2_dump.bin", action="store_true", help="reset device [%(default)s]")
help="file to dump pdq2 data into, for later simulation") parser.add_argument("-b", "--boards", default=3, type=int,
help="number of boards [%(default)s]")
verbosity_args(parser) verbosity_args(parser)
return parser return parser
@ -35,8 +37,15 @@ def main():
if args.simulation: if args.simulation:
port = open(args.dump, "wb") port = open(args.dump, "wb")
dev = Pdq2(url=args.device, dev=port) dev = Pdq2(url=args.device, dev=port, num_boards=args.boards)
try: try:
if args.reset:
dev.write(b"\x00\x00") # flush any escape
dev.cmd("RESET", True)
dev.flush()
time.sleep(.1)
dev.cmd("ARM", True)
dev.park()
simple_server_loop({"pdq2": dev}, bind_address_from_args(args), simple_server_loop({"pdq2": dev}, bind_address_from_args(args),
args.port, description="device=" + str(args.device)) args.port, description="device=" + str(args.device))
finally: finally: