Hello,
We are trying to build an artiq program, which starts on an external trigger arriving each 100ms, and then executes our needed output triggers. This is done repeatedly in order to sync with other devices.
We started from the code suggested in https://forum.m-labs.hk/d/387-start-immediately-after-rising-edge-detected and made a few modifications.
However, we find that some of the external triggers the artiq should receive are not caught. This was confirmed by a scope and printing the exception in if trigger_mu>0... else..
.
This is not deterministic- we observed 3 types of behaviors (all in 10 attempts to run the code):
- The artiq misses trigger number 2 (specifically number 2).
- The artiq misses one or more triggers from the start of the 30 triggers.
- The expected behavior is achieved.
We would highly appreciate help in solving this bug and understanding the behavior of the Artiq.
This is the code we are using:
`from artiq.experiment import *
import numpy as np
class ArtiqTrial(EnvExperiment):
def build(self):
self.setattr_device("core")
self.setattr_device('ttl0')
self.setattr_device('ttl4')
self.t0_cycle = np.int64(1)
@kernel
def run(self):
self.core.reset()
self.ttl0.input()
self.ttl4.output()
delay(1*ms)
while self.ttl0.timestamp_mu(now_mu()) >= 0: # flush buffer
pass
delay(5.*us) # slack
for i in range(30):
delay(21*ms)
close_mu = self.ttl0.gate_rising(80*ms)
trigger_mu = self.ttl0.timestamp_mu(close_mu)
if trigger_mu > 0:
at_mu(trigger_mu + self.core.seconds_to_mu(5*us))
self.t0_cycle = now_mu()
delay(100*us)
#our pulse
at_mu(self.t0_cycle + self.core.seconds_to_mu(5*1e-6))
self.ttl4.on()
at_mu(self.t0_cycle + self.core.seconds_to_mu(10*1e-6))
self.ttl4.off()
else:
print(trigger_mu)
print(self.core.mu_to_seconds(close_mu))
`