From 5c08423b29d83d57d467dbafe63e6b9452f6e7cd Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Fri, 8 May 2015 22:17:06 +0800 Subject: [PATCH] dds: support batches in driver --- artiq/coredevice/dds.py | 24 +++++++++++-- examples/master/ddb.pyon | 12 +++++-- examples/master/repository/dds_test.py | 8 +++-- .../master/repository/photon_histogram.py | 35 ++++++++++++++----- 4 files changed, 64 insertions(+), 15 deletions(-) diff --git a/artiq/coredevice/dds.py b/artiq/coredevice/dds.py index 6de0fbb0a..890ff9e96 100644 --- a/artiq/coredevice/dds.py +++ b/artiq/coredevice/dds.py @@ -10,10 +10,30 @@ PHASE_MODE_ABSOLUTE = 1 PHASE_MODE_TRACKING = 2 +class DDSBus(AutoDB): + """Core device Direct Digital Synthesis (DDS) bus batching driver. + + Manages batching of DDS commands on a DDS shared bus.""" + class DBKeys: + core = Device() + + @kernel + def batch_enter(self): + """Starts a DDS command batch. All DDS commands are buffered + after this call, until ``batch_exit`` is called.""" + syscall("dds_batch_enter", time_to_cycles(now())) + + @kernel + def batch_exit(self): + """Ends a DDS command batch. All buffered DDS commands are issued + on the bus, and FUD is pulsed at the time the batch started.""" + syscall("dds_batch_exit") + + class DDS(AutoDB): """Core device Direct Digital Synthesis (DDS) driver. - Controls DDS devices managed directly by the core device's runtime. + Controls one DDS channel managed directly by the core device's runtime. :param dds_sysclk: DDS system frequency, used for computing the frequency tuning words. @@ -43,7 +63,7 @@ class DDS(AutoDB): @kernel def init(self): - """Resets and initializes the DDS.""" + """Resets and initializes the DDS channel.""" syscall("dds_init", time_to_cycles(now()), self.channel) @kernel diff --git a/examples/master/ddb.pyon b/examples/master/ddb.pyon index 618341244..7e7778f66 100644 --- a/examples/master/ddb.pyon +++ b/examples/master/ddb.pyon @@ -50,6 +50,12 @@ "arguments": {"channel": 18} }, + "dds_bus": { + "type": "local", + "module": "artiq.coredevice.dds", + "class": "DDSBus", + "arguments": {} + }, "dds0": { "type": "local", "module": "artiq.coredevice.dds", @@ -123,6 +129,8 @@ }, "pmt": "pmt0", - "bd": "dds0", - "bdd": "dds1" + "bd_dds": "dds0", + "bd_sw": "ttl0", + "bdd_dds": "dds1", + "bdd_sw": "ttl1" } diff --git a/examples/master/repository/dds_test.py b/examples/master/repository/dds_test.py index 520faa5ce..2c6e8e1d0 100644 --- a/examples/master/repository/dds_test.py +++ b/examples/master/repository/dds_test.py @@ -6,6 +6,7 @@ class DDSTest(Experiment, AutoDB): class DBKeys: core = Device() + dds_bus = Device() dds0 = Device() dds1 = Device() dds2 = Device() @@ -16,9 +17,10 @@ class DDSTest(Experiment, AutoDB): @kernel def run(self): - # with dds_batch: - # self.dds1.set(120*MHz) - # self.dds2.set(200*MHz) + self.dds_bus.batch_enter() + self.dds1.set(120*MHz) + self.dds2.set(200*MHz) + self.dds_bus.batch_exit() for i in range(10000): if i & 0x200: diff --git a/examples/master/repository/photon_histogram.py b/examples/master/repository/photon_histogram.py index 84359269a..66ea3b5b7 100644 --- a/examples/master/repository/photon_histogram.py +++ b/examples/master/repository/photon_histogram.py @@ -6,8 +6,11 @@ class PhotonHistogram(Experiment, AutoDB): class DBKeys: core = Device() - bd = Device() - bdd = Device() + dds_bus = Device() + bd_dds = Device() + bd_sw = Device() + bdd_dds = Device() + bdd_sw = Device() pmt = Device() nbins = Argument(100) @@ -22,21 +25,37 @@ class PhotonHistogram(Experiment, AutoDB): hist = Result() total = Result() + @kernel + def program_cooling(self): + self.dds_bus.batch_enter() + self.bd_dds.set(200*MHz) + self.bdd_dds.set(300*MHz) + self.dds_bus.batch_exit() + @kernel def cool_detect(self): with parallel: - self.bd.pulse(200*MHz, 1*ms) - self.bdd.pulse(300*MHz, 1*ms) - self.bd.pulse(self.cool_f, 100*us) + self.bd_sw.pulse(1*ms) + self.bdd_sw.pulse(1*ms) + + self.bd_dds.set(self.cool_f) + self.bd_sw.pulse(100*us) + + self.bd_dds.set(self.detect_f) with parallel: - self.bd.pulse(self.detect_f, self.detect_t) + self.bd_sw.pulse(self.detect_t) self.pmt.gate_rising(self.detect_t) - self.bd.on(200*MHz) - self.bdd.on(300*MHz) + + self.program_cooling() + self.bd_sw.on() + self.bdd_sw.on() + return self.pmt.count() @kernel def run(self): + self.program_cooling() + hist = [0 for _ in range(self.nbins)] total = 0