forked from M-Labs/artiq
1
0
Fork 0

wavesynth: implement silence, add defaults, fix bias

This commit is contained in:
Robert Jördens 2015-04-05 01:14:19 -06:00
parent 051b01f58e
commit 1f545346e3
1 changed files with 29 additions and 15 deletions

View File

@ -48,9 +48,14 @@ class Wave:
def __init__(self): def __init__(self):
self.bias = Spline() self.bias = Spline()
self.dds = DDS() self.dds = DDS()
self.last = 0.
self.silence = False
def next(self): def next(self):
return self.bias.next() + self.dds.next() v = self.bias.next() + self.dds.next()
if not self.silence:
self.last = v
return self.last
class TriggerError(Exception): class TriggerError(Exception):
@ -78,33 +83,41 @@ class Synthesizer:
while True: while True:
line = next(self.line_iter) line = next(self.line_iter)
if line["dac_divider"] != 1: if line.get("dac_divider", 1) != 1:
raise NotImplementedError raise NotImplementedError
for channel, channel_data in zip(self.channels, for channel, channel_data in zip(self.channels,
line["channel_data"]): line["channel_data"]):
if "bias" in channel_data: if "bias" in channel_data:
channel.bias.set_coefficients(channel_data["bias"]) channel.bias.set_coefficients(channel_data["bias"]["amplitude"])
if "dds" in channel_data: if "dds" in channel_data:
channel.dds.amplitude.set_coefficients( channel.dds.amplitude.set_coefficients(
channel_data["dds"]["amplitude"]) channel_data["dds"]["amplitude"])
if "phase" in channel_data["dds"]:
channel.dds.phase.set_coefficients( channel.dds.phase.set_coefficients(
channel_data["dds"]["phase"]) channel_data["dds"]["phase"])
if channel_data["dds"]["clear"]: if channel_data["dds"].get("clear", False):
channel.dds.phase.clear() channel.dds.phase.clear()
channel.silence = channel_data.get("silence", False)
for channel, rc in zip(self.channels, r): for channel, rc in zip(self.channels, r):
for i in range(line["duration"]): for i in range(line["duration"]):
rc.append(channel.next()) rc.append(channel.next())
if line["wait_trigger"] and line["jump"]: if line.get("wait_trigger", False):
raise ValueError("Line cannot both jump and wait for trigger")
if line["wait_trigger"]:
return r return r
if line["jump"]: if line.get("jump", False):
if not line.get("wait_trigger", False):
raise ValueError("Jumps should be with wait_trigger")
try:
next(self.line_iter)
raise ValueError("Jump in the middle of a frame")
except StopIteration:
pass
self.line_iter = None self.line_iter = None
return r return r
def main(): def main():
from artiq.test.wavesynth import TestSynthesizer from artiq.test.wavesynth import TestSynthesizer
import cairoplot import cairoplot
@ -114,5 +127,6 @@ def main():
x, y = t.drive() x, y = t.drive()
cairoplot.scatter_plot("plot.png", [x, y]) cairoplot.scatter_plot("plot.png", [x, y])
if __name__ == "__main__": if __name__ == "__main__":
main() main()