Keeping the gate open for the whole experiment is an option, but I have run into several issues:
A new trigger pulse might arrive before the sequence is finished. In this case, timestamp_mu()
returns a value pointing to the past and the at_mu()
command will fail. This can again be avoided by calling timestamp_mu()
in a loop until it returns a valid timestamp, but I don't find this a particularly nice solution:
from artiq.experiment import *
class LineTrigger(EnvExperiment):
def build(self):
self.setattr_device("core")
self.setattr_device("ttl2")
self.setattr_device("ttl9")
@kernel
def run(self):
self.core.reset()
t_gate = self.ttl2.gate_rising(10*s)
t_pulse_end = 0
while True:
t_trig = self.ttl2.timestamp_mu(t_gate)
if t_trig > 0:
if t_trig < t_pulse_end:
continue
at_mu(t_trig)
else:
break
delay(10*us)
self.ttl9.pulse(21*ms)
delay(10*us)
t_pulse_end = now_mu()
Another issue is that the overall length of the experiment (and thus the required gate time) might not be clear from the beginning.
Also having the gate open on ttl2
somehow broke my ttl_counters
in the following example:
from artiq.experiment import *
class LineTrigger(EnvExperiment):
def build(self):
self.setattr_device("core")
self.setattr_device("ttl2")
self.setattr_device("ttl9")
self.setattr_device("ttl_counter0")
self.setattr_device("ttl_counter1")
self.pmt_exposure_time = 1*ms
@kernel
def run(self):
self.core.reset()
t_gate = self.ttl2.gate_rising(10*s)
t_pulse_end = 0
while True:
t_trig = self.ttl2.timestamp_mu(t_gate)
if t_trig > 0:
if t_trig < t_pulse_end:
continue
at_mu(t_trig)
else:
break
delay(10*us)
self.ttl9.pulse(1*ms)
delay(10*us)
with parallel:
self.ttl_counter0.gate_rising(self.pmt_exposure_time)
self.ttl_counter1.gate_rising(self.pmt_exposure_time)
num_rising_edges0 = self.ttl_counter0.fetch_count()
num_rising_edges1 = self.ttl_counter1.fetch_count()
t_pulse_end = now_mu()
The program seems to get stuck on the fetch_count()
calls.
Probably the cleanest solution would be to have functions for manually closing the gates and for discarding unwanted events.