From 74adb391578ab850bd573a2cc75f66e8de29e82e Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Mon, 13 Oct 2014 17:05:35 +0800 Subject: [PATCH] devices/dds_core: add frequency_to_ftw and ftw_to_frequency --- artiq/devices/dds_core.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/artiq/devices/dds_core.py b/artiq/devices/dds_core.py index d320b7510..5b7fba720 100644 --- a/artiq/devices/dds_core.py +++ b/artiq/devices/dds_core.py @@ -25,6 +25,22 @@ class DDS(AutoContext): kernel_attr = "previous_frequency" + @portable + def frequency_to_ftw(self, frequency): + """Returns the frequency tuning word corresponding to the given + frequency. + + """ + return int(2**32*frequency/self.dds_sysclk) + + @portable + def ftw_to_frequency(self, ftw): + """Returns the frequency corresponding to the given frequency tuning + word. + + """ + return ftw*self.dds_sysclk/2**32 + @kernel def on(self, frequency): """Sets the DDS channel to the specified frequency and turns it on. @@ -47,7 +63,7 @@ class DDS(AutoContext): # the same time. fud_time = -1 syscall("dds_program", self.reg_channel, - int(2**32*frequency/self.dds_sysclk), + self.frequency_to_ftw(frequency), fud_time) self.previous_frequency = frequency self.sw.on()