From 1d5f467da7584b487b5aea764c1ae973de4c9ea3 Mon Sep 17 00:00:00 2001 From: Robert Jordens Date: Sun, 5 Apr 2015 03:55:11 -0600 Subject: [PATCH] pdq2: implement changes in trigger/jump semantics, add unittest The unittests now runs the compute_samples.Synthesizer against the actual gateware and verifies similarity (up to integer rounding errors). --- artiq/devices/pdq2/driver.py | 19 +++++----- artiq/test/pdq2.py | 69 +++++++++++++++++++++++++++--------- 2 files changed, 64 insertions(+), 24 deletions(-) diff --git a/artiq/devices/pdq2/driver.py b/artiq/devices/pdq2/driver.py index 1dd218003..c6d3ad566 100644 --- a/artiq/devices/pdq2/driver.py +++ b/artiq/devices/pdq2/driver.py @@ -22,14 +22,14 @@ class Segment: self.data = b"" def line(self, typ, duration, data, trigger=False, silence=False, - aux=False, shift=0, jump=False, clear=False, wait_trigger=False): + aux=False, shift=0, jump=False, clear=False, wait=False): assert len(data) % 2 == 0, data assert len(data)//2 <= 14 #assert dt*(1 << shift) > 1 + len(data)//2 header = ( 1 + len(data)//2 | (typ << 4) | (trigger << 6) | (silence << 7) | (aux << 8) | (shift << 9) | (jump << 13) | (clear << 14) | - (wait_trigger << 15) + (wait << 15) ) self.data += struct.pack(" 10: + yij -= 20 + self.assertAlmostEqual(yij, yij_ref, 2, + "foo t={}, c={}".format(i, j)) + + @unittest.skipUnless(pdq2_gateware, "no pdq2 gateware") + @unittest.skip("manual/visual test") + def test_run_plot(self): + from matplotlib import pyplot as plt + import numpy as np + y_ref = self.test_synth() + y_ref = np.array(y_ref) + y = self.run_gateware() + y = np.array(y, dtype=np.uint16).view(np.int16) + y = y*20./2**16 + plt.step(np.arange(len(y)), y) + plt.step(np.arange(len(y_ref)), y_ref, "k") plt.show() _test_program = [ [ { + "trigger": True, "duration": 20, "channel_data": [ {"bias": {"amplitude": [0, 0, 2e-3]}}, {"bias": {"amplitude": [1, 0, -7.5e-3, 7.5e-4]}}, {"dds": { "amplitude": [0, 0, 4e-3, 0], - "phase": [.5, .05], + "phase": [.25, .025], }}, ], }, @@ -68,7 +107,7 @@ _test_program = [ }}, {"dds": { "amplitude": [.8, .08, -4e-3, 0], - "phase": [.5, .05, .04/40], + "phase": [.25, .025, .02/40], "clear": True, }}, ], @@ -80,11 +119,9 @@ _test_program = [ {"bias": {"amplitude": [.5, 0, -7.5e-3, 7.5e-4]}}, {"dds": { "amplitude": [.8, -.08, 4e-3, 0], - "phase": [-.5], + "phase": [-.25], }}, ], - "wait_trigger": True, - "jump": True, }, ] ]