2014-10-14 16:38:02 +08:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2014-10-25 11:38:42 +08:00
|
|
|
# Based on code by Robert Jordens <jordens@gmail.com>, 2012
|
2014-10-14 16:38:02 +08:00
|
|
|
|
|
|
|
import argparse
|
|
|
|
import time
|
|
|
|
|
|
|
|
from scipy import interpolate
|
|
|
|
import numpy as np
|
|
|
|
|
2014-10-25 11:38:42 +08:00
|
|
|
from artiq.management.pc_rpc import Client
|
2014-10-14 16:38:02 +08:00
|
|
|
|
|
|
|
|
2014-10-25 11:38:42 +08:00
|
|
|
def _get_args():
|
|
|
|
parser = argparse.ArgumentParser(description="""PDQ2 client.
|
|
|
|
Evaluates times and voltages, interpolates and uploads
|
|
|
|
them to the controller.""")
|
|
|
|
parser.add_argument("-s", "--server", default="::1",
|
2014-10-27 20:34:33 +08:00
|
|
|
help="hostname or IP of the controller to connect to")
|
2014-10-25 11:38:42 +08:00
|
|
|
parser.add_argument("--port", default=8889, type=int,
|
2014-10-27 20:34:33 +08:00
|
|
|
help="TCP port to use to connect to the controller")
|
2014-10-14 16:38:02 +08:00
|
|
|
parser.add_argument("-c", "--channel", default=0, type=int,
|
2014-10-14 17:02:25 +08:00
|
|
|
help="channel: 3*board_num+dac_num [%(default)s]")
|
2014-10-14 16:38:02 +08:00
|
|
|
parser.add_argument("-f", "--frame", default=0, type=int,
|
2014-10-14 17:02:25 +08:00
|
|
|
help="frame [%(default)s]")
|
2014-10-14 16:38:02 +08:00
|
|
|
parser.add_argument("-e", "--free", default=False,
|
2014-10-14 17:02:25 +08:00
|
|
|
action="store_true",
|
|
|
|
help="software trigger [%(default)s]")
|
2014-10-14 16:38:02 +08:00
|
|
|
parser.add_argument("-n", "--disarm", default=False,
|
2014-10-14 17:02:25 +08:00
|
|
|
action="store_true",
|
|
|
|
help="disarm group [%(default)s]")
|
2014-10-14 16:38:02 +08:00
|
|
|
parser.add_argument("-t", "--times",
|
2014-10-14 17:02:25 +08:00
|
|
|
default="np.arange(5)*1e-6",
|
|
|
|
help="sample times (s) [%(default)s]")
|
2014-10-14 16:38:02 +08:00
|
|
|
parser.add_argument("-v", "--voltages",
|
2014-10-14 17:02:25 +08:00
|
|
|
default="(1-np.cos(t/t[-1]*2*np.pi))/2",
|
|
|
|
help="sample voltages (V) [%(default)s]")
|
2014-10-14 16:38:02 +08:00
|
|
|
parser.add_argument("-o", "--order", default=3, type=int,
|
2014-10-14 17:02:25 +08:00
|
|
|
help="interpolation"
|
|
|
|
" (0: const, 1: lin, 2: quad, 3: cubic)"
|
|
|
|
" [%(default)s]")
|
2014-10-14 16:38:02 +08:00
|
|
|
parser.add_argument("-m", "--dcm", default=None, type=int,
|
2014-10-14 17:02:25 +08:00
|
|
|
help="choose fast 100MHz clock [%(default)s]")
|
2014-10-14 16:38:02 +08:00
|
|
|
parser.add_argument("-x", "--demo", default=False, action="store_true",
|
2014-10-14 17:02:25 +08:00
|
|
|
help="demo mode: pulse and chirp,"
|
|
|
|
" 1V*ch+0.1V*frame [%(default)s]")
|
2014-10-14 16:38:02 +08:00
|
|
|
parser.add_argument("-p", "--plot", help="plot to file [%(default)s]")
|
|
|
|
parser.add_argument("-r", "--reset", default=False,
|
2014-10-14 17:02:25 +08:00
|
|
|
action="store_true", help="do reset before")
|
2014-10-14 16:38:02 +08:00
|
|
|
parser.add_argument("-b", "--bit", default=False,
|
2014-10-14 17:02:25 +08:00
|
|
|
action="store_true", help="do bit test")
|
2014-10-25 11:38:42 +08:00
|
|
|
return parser.parse_args()
|
2014-10-14 16:38:02 +08:00
|
|
|
|
|
|
|
|
2014-10-25 11:38:42 +08:00
|
|
|
def _main():
|
|
|
|
args = _get_args()
|
2014-10-28 15:45:56 +08:00
|
|
|
dev = Client(args.server, args.port, "pdq2")
|
2014-10-25 11:38:42 +08:00
|
|
|
dev.init()
|
2014-10-14 16:38:02 +08:00
|
|
|
|
|
|
|
if args.reset:
|
2014-10-25 11:38:42 +08:00
|
|
|
dev.flush_escape()
|
2014-10-14 16:38:02 +08:00
|
|
|
dev.write_cmd("RESET_EN")
|
|
|
|
time.sleep(.1)
|
|
|
|
if args.dcm:
|
|
|
|
dev.write_cmd("DCM_EN")
|
2014-10-25 11:38:42 +08:00
|
|
|
dev.set_freq(100e6)
|
2014-10-14 16:38:02 +08:00
|
|
|
elif args.dcm == 0:
|
|
|
|
dev.write_cmd("DCM_DIS")
|
2014-10-25 11:38:42 +08:00
|
|
|
dev.set_freq(50e6)
|
2014-10-14 16:38:02 +08:00
|
|
|
dev.write_cmd("START_DIS")
|
|
|
|
|
2014-10-25 11:38:42 +08:00
|
|
|
num_channels = dev.get_num_channels()
|
|
|
|
num_frames = dev.get_num_frames()
|
|
|
|
times = eval(args.times, globals(), {})
|
|
|
|
voltages = eval(args.voltages, globals(), dict(t=times))
|
|
|
|
|
2014-10-14 16:38:02 +08:00
|
|
|
if args.demo:
|
2014-10-25 11:38:42 +08:00
|
|
|
# FIXME
|
|
|
|
channels = [args.channel] if args.channel < num_channels \
|
|
|
|
else range(num_channels)
|
|
|
|
frames = [args.frame] if args.frame < num_frames \
|
|
|
|
else range(num_frames)
|
2014-10-14 16:38:02 +08:00
|
|
|
for channel in channels:
|
|
|
|
f = []
|
|
|
|
for frame in frames:
|
|
|
|
vi = .1*frame + channel + voltages
|
|
|
|
pi = 2*np.pi*(.01*frame + .1*channel + 0*voltages)
|
|
|
|
fi = 10e6*times/times[-1]
|
|
|
|
f.append(b"".join([
|
|
|
|
dev.frame(times, vi, order=args.order, end=False),
|
|
|
|
dev.frame(2*times, voltages, pi, fi, trigger=False),
|
2014-10-14 17:02:25 +08:00
|
|
|
# dev.frame(2*times, 0*vi+.1, 0*pi, 0*fi+1e6),
|
|
|
|
# dev.frame(times, 0*vi, order=args.order, silence=True),
|
2014-10-14 16:38:02 +08:00
|
|
|
]))
|
|
|
|
board, dac = divmod(channel, dev.num_dacs)
|
|
|
|
dev.write_data(dev.add_mem_header(board, dac, dev.map_frames(f)))
|
|
|
|
elif args.bit:
|
2014-10-25 11:38:42 +08:00
|
|
|
map = [0] * num_frames
|
2014-10-14 16:38:02 +08:00
|
|
|
t = np.arange(2*16) * 1.
|
|
|
|
v = [-1, 0, -1]
|
|
|
|
for i in range(15):
|
2014-10-14 17:02:25 +08:00
|
|
|
vi = 1 << i
|
2014-10-14 16:38:02 +08:00
|
|
|
v.extend([vi - 1, vi])
|
2014-10-25 11:38:42 +08:00
|
|
|
v = np.array(v)*dev.get_max_out()/(1 << 15)
|
2014-10-14 16:38:02 +08:00
|
|
|
t, v = t[:3], v[:3]
|
2014-10-14 17:02:25 +08:00
|
|
|
# print(t, v)
|
2014-10-25 11:38:42 +08:00
|
|
|
for channel in range(num_channels):
|
|
|
|
dev.multi_frame([(t, v)], channel=channel, order=0, map=map,
|
|
|
|
shift=15, stop=False, trigger=False)
|
2014-10-14 16:38:02 +08:00
|
|
|
else:
|
|
|
|
tv = [(times, voltages)]
|
2014-10-25 11:38:42 +08:00
|
|
|
map = [None] * num_frames
|
2014-10-14 16:38:02 +08:00
|
|
|
map[args.frame] = 0
|
2014-10-25 11:38:42 +08:00
|
|
|
dev.multi_frame(tv, channel=args.channel, order=args.order, map=map)
|
2014-10-14 16:38:02 +08:00
|
|
|
|
|
|
|
dev.write_cmd("START_EN")
|
|
|
|
if not args.disarm:
|
|
|
|
dev.write_cmd("ARM_EN")
|
|
|
|
if args.free:
|
|
|
|
dev.write_cmd("TRIGGER_EN")
|
|
|
|
|
|
|
|
if args.plot:
|
|
|
|
from matplotlib import pyplot as plt
|
|
|
|
fig, ax0 = plt.subplots()
|
|
|
|
ax0.plot(times, voltages, "xk", label="points")
|
|
|
|
if args.order:
|
|
|
|
spline = interpolate.splrep(times, voltages, k=args.order)
|
2014-10-25 11:38:42 +08:00
|
|
|
ttimes = np.arange(0, times[-1], 1/dev.get_freq())
|
2014-10-14 16:38:02 +08:00
|
|
|
vvoltages = interpolate.splev(ttimes, spline)
|
|
|
|
ax0.plot(ttimes, vvoltages, ",b", label="interpolation")
|
|
|
|
fig.savefig(args.plot)
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
_main()
|