forked from M-Labs/artiq
pdq2: pep8
This commit is contained in:
parent
ea0773ccb5
commit
88ad4fbf23
|
@ -82,14 +82,14 @@ class Pdq2:
|
||||||
"""
|
"""
|
||||||
PDQ DAC (a.k.a. QC_Waveform)
|
PDQ DAC (a.k.a. QC_Waveform)
|
||||||
"""
|
"""
|
||||||
max_val = 1<<15 # signed 16 bit DAC
|
max_val = 1 << 15 # signed 16 bit DAC
|
||||||
max_out = 10.
|
max_out = 10.
|
||||||
freq = 50e6 # samples/s
|
freq = 50e6 # samples/s
|
||||||
max_time = 1<<16 # unsigned 16 bit timer
|
max_time = 1 << 16 # unsigned 16 bit timer
|
||||||
num_dacs = 3
|
num_dacs = 3
|
||||||
num_frames = 8
|
num_frames = 8
|
||||||
num_channels = 9
|
num_channels = 9
|
||||||
max_data = 4*(1<<10) # 8kx16 8kx16 4kx16
|
max_data = 4*(1 << 10) # 8kx16 8kx16 4kx16
|
||||||
escape_char = b"\xa5"
|
escape_char = b"\xa5"
|
||||||
cordic_gain = 1.
|
cordic_gain = 1.
|
||||||
for i in range(16):
|
for i in range(16):
|
||||||
|
@ -123,8 +123,8 @@ class Pdq2:
|
||||||
return self.write(self.cmd(cmd))
|
return self.write(self.cmd(cmd))
|
||||||
|
|
||||||
def escape(self, data):
|
def escape(self, data):
|
||||||
return data.replace(self.escape_char, self.escape_char +
|
return data.replace(self.escape_char,
|
||||||
self.escape_char)
|
self.escape_char + self.escape_char)
|
||||||
|
|
||||||
def write(self, *segments):
|
def write(self, *segments):
|
||||||
"""
|
"""
|
||||||
|
@ -206,15 +206,15 @@ class Pdq2:
|
||||||
head = np.zeros(len(t) - 1, "<u2")
|
head = np.zeros(len(t) - 1, "<u2")
|
||||||
head[:] |= length # 4
|
head[:] |= length # 4
|
||||||
if p is not None:
|
if p is not None:
|
||||||
head[:] |= 1<<4 # typ # 2
|
head[:] |= 1 << 4 # typ # 2
|
||||||
head[0] |= trigger<<6 # 1
|
head[0] |= trigger << 6 # 1
|
||||||
head[-1] |= (not stop and silence)<<7 # 1
|
head[-1] |= (not stop and silence) << 7 # 1
|
||||||
if aux is not None:
|
if aux is not None:
|
||||||
head[:] |= aux[:len(head)]<<8 # 1
|
head[:] |= aux[:len(head)] << 8 # 1
|
||||||
head[:] |= shift<<9 # 4
|
head[:] |= shift << 9 # 4
|
||||||
head[-1] |= (not stop and end)<<13 # 1
|
head[-1] |= (not stop and end) << 13 # 1
|
||||||
head[0] |= clear<<14 # 1
|
head[0] |= clear << 14 # 1
|
||||||
head[-1] |= (not stop and wait)<<15 # 1
|
head[-1] |= (not stop and wait) << 15 # 1
|
||||||
parts.append((head, "u2"))
|
parts.append((head, "u2"))
|
||||||
|
|
||||||
t, tr, dt = self.line_times(t, shift)
|
t, tr, dt = self.line_times(t, shift)
|
||||||
|
@ -243,13 +243,15 @@ class Pdq2:
|
||||||
|
|
||||||
if stop:
|
if stop:
|
||||||
if p is not None:
|
if p is not None:
|
||||||
frame += struct.pack("<HH hiihih H ii", (15<<0) | (1<<4) |
|
frame += struct.pack("<HH hiihih H ii", (15 << 0) | (1 << 4) |
|
||||||
(silence<<7) | (end<<13) | (wait<<15),
|
(silence << 7) |
|
||||||
|
(end << 13) |
|
||||||
|
(wait << 15),
|
||||||
1, int(v[-1]*2**15), 0, 0, 0, 0, 0,
|
1, int(v[-1]*2**15), 0, 0, 0, 0, 0,
|
||||||
int(p[-1]*2**16), int(f[-1]*2**31), 0)
|
int(p[-1]*2**16), int(f[-1]*2**31), 0)
|
||||||
else:
|
else:
|
||||||
frame += struct.pack("<HH h", (2<<0) |
|
frame += struct.pack("<HH h", (2 << 0) | (silence << 7) |
|
||||||
(silence<<7) | (end<<13) | (wait << 15),
|
(end << 13) | (wait << 15),
|
||||||
1, int(v[-1]*2**15))
|
1, int(v[-1]*2**15))
|
||||||
return frame
|
return frame
|
||||||
|
|
||||||
|
|
|
@ -35,12 +35,14 @@ def _main():
|
||||||
default="(1-np.cos(t/t[-1]*2*np.pi))/2",
|
default="(1-np.cos(t/t[-1]*2*np.pi))/2",
|
||||||
help="sample voltages (V) [%(default)s]")
|
help="sample voltages (V) [%(default)s]")
|
||||||
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, 3: cubic)"
|
help="interpolation"
|
||||||
|
" (0: const, 1: lin, 2: quad, 3: cubic)"
|
||||||
" [%(default)s]")
|
" [%(default)s]")
|
||||||
parser.add_argument("-m", "--dcm", default=None, type=int,
|
parser.add_argument("-m", "--dcm", default=None, type=int,
|
||||||
help="choose fast 100MHz clock [%(default)s]")
|
help="choose fast 100MHz clock [%(default)s]")
|
||||||
parser.add_argument("-x", "--demo", default=False, action="store_true",
|
parser.add_argument("-x", "--demo", default=False, action="store_true",
|
||||||
help="demo mode: pulse and chirp, 1V*ch+0.1V*frame [%(default)s]")
|
help="demo mode: pulse and chirp,"
|
||||||
|
" 1V*ch+0.1V*frame [%(default)s]")
|
||||||
parser.add_argument("-p", "--plot", help="plot to file [%(default)s]")
|
parser.add_argument("-p", "--plot", help="plot to file [%(default)s]")
|
||||||
parser.add_argument("-d", "--debug", default=False,
|
parser.add_argument("-d", "--debug", default=False,
|
||||||
action="store_true", help="debug communications")
|
action="store_true", help="debug communications")
|
||||||
|
@ -87,8 +89,8 @@ def _main():
|
||||||
f.append(b"".join([
|
f.append(b"".join([
|
||||||
dev.frame(times, vi, order=args.order, end=False),
|
dev.frame(times, vi, order=args.order, end=False),
|
||||||
dev.frame(2*times, voltages, pi, fi, trigger=False),
|
dev.frame(2*times, voltages, pi, fi, trigger=False),
|
||||||
#dev.frame(2*times, 0*vi+.1, 0*pi, 0*fi+1e6),
|
# dev.frame(2*times, 0*vi+.1, 0*pi, 0*fi+1e6),
|
||||||
#dev.frame(times, 0*vi, order=args.order, silence=True),
|
# dev.frame(times, 0*vi, order=args.order, silence=True),
|
||||||
]))
|
]))
|
||||||
board, dac = divmod(channel, dev.num_dacs)
|
board, dac = divmod(channel, dev.num_dacs)
|
||||||
dev.write_data(dev.add_mem_header(board, dac, dev.map_frames(f)))
|
dev.write_data(dev.add_mem_header(board, dac, dev.map_frames(f)))
|
||||||
|
@ -97,14 +99,15 @@ def _main():
|
||||||
t = np.arange(2*16) * 1.
|
t = np.arange(2*16) * 1.
|
||||||
v = [-1, 0, -1]
|
v = [-1, 0, -1]
|
||||||
for i in range(15):
|
for i in range(15):
|
||||||
vi = 1<<i
|
vi = 1 << i
|
||||||
v.extend([vi - 1, vi])
|
v.extend([vi - 1, vi])
|
||||||
v = np.array(v)*dev.max_out/(1<<15)
|
v = np.array(v)*dev.max_out/(1 << 15)
|
||||||
t, v = t[:3], v[:3]
|
t, v = t[:3], v[:3]
|
||||||
#print(t, v)
|
# print(t, v)
|
||||||
for channel in range(dev.num_channels):
|
for channel in range(dev.num_channels):
|
||||||
dev.write_data(dev.multi_frame([(t, v)], channel=channel,
|
dev.write_data(dev.multi_frame([(t, v)], channel=channel,
|
||||||
order=0, map=map, shift=15, stop=False, trigger=False))
|
order=0, map=map, shift=15,
|
||||||
|
stop=False, trigger=False))
|
||||||
else:
|
else:
|
||||||
tv = [(times, voltages)]
|
tv = [(times, voltages)]
|
||||||
map = [None] * dev.num_frames
|
map = [None] * dev.num_frames
|
||||||
|
|
Loading…
Reference in New Issue