When I run a simple 'experiment' to set some DDS channels I would like to be able to shut the channels off by terminating the process which set the channels. I am currently doing this by running scheduler.check_pause()
in a loop and shutting down the DDS if check_pause()
evaluates to True:
from artiq.experiment import *
from artiq.language import units
class Urukul_Programmable(EnvExperiment):
"""Test Termination"""
def build(self): #This code runs on the host device
self.setattr_device("core")
self.setattr_device("scheduler")
self.setattr_device("urukul1_ch1")
@kernel
def run(self):
self.core.reset()
self.urukul1_ch1.cpld.init()
self.urukul1_ch1.init()
self.core.break_realtime()
self.urukul1_ch1.set(100 * units.MHz, amplitude = 1.0 * units.V)
self.urukul1_ch1.set_att(0 *units.dB)
self.urukul1_ch1.sw.on()
# Check to see if the scheduler wants to pause then wait for delay time
delay_time = 10.0 * units.ms
while True:
if self.scheduler.check_pause():
self.urukul1_ch1.sw.off()
break
else:
delay(delay_time)
When I run this code the DDS chanel is set to 100 MHz as expected, however, when I terminate the process in the dashboard it takes anywhere from 10-30 seconds before the DDS output actually shuts down.
If I put a print statement before self.urukul1_ch1.sw.off()
then it evaluates as soon as I terminate the process, but the DDS remains on for a random period.
I suspect there's something tricky going on with the time cursor.
I've tried inserting self.core.wait_until_mu(now_mu())
with various delays to take care of the RTIOUnderflow
. Even putting a try except block in a while loop to dynamically choose the correct delay, but to no avail.