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)
"""
num_dacs = 3
freq = 50e6
_escape = b"\xa5"
_commands = "RESET TRIGGER ARM DCM START".split()
@ -146,6 +147,12 @@ class Pdq2:
def get_num_channels(self):
return self.num_channels
def get_freq(self):
return self.freq
def set_freq(self, freq):
self.freq = float(freq)
def close(self):
self.dev.close()
del self.dev
@ -172,6 +179,16 @@ class Pdq2:
def flush(self):
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):
for i, line in enumerate(data):
dac_divider = line.get("dac_divider", 1)

View File

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

View File

@ -2,7 +2,6 @@
# Copyright (C) 2012-2015 Robert Jordens <jordens@gmail.com>
import argparse
import time
from scipy import interpolate
import numpy as np
@ -31,12 +30,6 @@ def get_argparser():
parser.add_argument("-o", "--order", default=3, type=int,
help="interpolation (0: const, 1: lin, 2: quad,"
" 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",
help="software trigger [%(default)s]")
verbosity_args(parser)
@ -48,24 +41,10 @@ def main():
init_logger(args)
dev = Client(args.server, args.port, "pdq2")
if args.reset:
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
freq = dev.get_freq()
times = np.around(eval(args.times, globals(), {})*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))
if args.order:
tck = interpolate.splrep(times, voltages, k=args.order, s=0)
@ -84,12 +63,10 @@ def main():
})
program = [[] for i in range(args.frame)]
program.append(segment)
dev.park()
dev.program(program, [args.channel])
dev.unpark()
dev.cmd("TRIGGER", args.free)
dev.cmd("ARM", not args.disarm)
dev.cmd("START", True)
dev.flush()
if __name__ == "__main__":

View File

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