From 9822b88d9b0a5ee33caad8b9b5461d472ac7acb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20J=C3=B6rdens?= Date: Fri, 29 May 2020 11:13:26 +0200 Subject: [PATCH] ad9910: fix asf range (#1450) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * ad9910: fix asf range The ASF is a 14-bit word. The highest possible value is 0x3fff, not 0x3ffe. `int(round(1.0 * 0x3fff)) == 0x3fff`. I don't remember and understand why this was 0x3ffe since the beginning. 0x3fff was already used as a default in `set_mu()` Signed-off-by: Robert Jördens * RELEASE_NOTES: ad9910 asf scale change Co-authored-by: David Nadlinger --- RELEASE_NOTES.rst | 2 ++ artiq/coredevice/ad9910.py | 10 +++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/RELEASE_NOTES.rst b/RELEASE_NOTES.rst index 50fb0ec7f..503a6c675 100644 --- a/RELEASE_NOTES.rst +++ b/RELEASE_NOTES.rst @@ -13,6 +13,8 @@ Highlights: than the RTIO period * Coredevice SI to mu conversions now always return valid codes, or raise a `ValueError`. * Zotino now exposes `voltage_to_mu()` +* `ad9910`: The maximum amplitude scale factor is now `0x3fff` (was `0x3ffe` + before). * Applets now restart if they are running and a ccb call changes their spec Breaking changes: diff --git a/artiq/coredevice/ad9910.py b/artiq/coredevice/ad9910.py index 4f8f99569..cc6316791 100644 --- a/artiq/coredevice/ad9910.py +++ b/artiq/coredevice/ad9910.py @@ -539,9 +539,9 @@ class AD9910: def set_asf(self, asf): """Set the value stored to the AD9910's amplitude scale factor (ASF) register. - :param asf: Amplitude scale factor to be stored, range: 0 to 0x3ffe. + :param asf: Amplitude scale factor to be stored, range: 0 to 0x3fff. """ - self.write32(_AD9910_REG_ASF, asf<<2) + self.write32(_AD9910_REG_ASF, asf << 2) @kernel def set_pow(self, pow_): @@ -581,8 +581,8 @@ class AD9910: def amplitude_to_asf(self, amplitude): """Return 14-bit amplitude scale factor corresponding to given fractional amplitude.""" - code = int32(round(amplitude * 0x3ffe)) - if code < 0 or code > (1 << 14) - 1: + code = int32(round(amplitude * 0x3fff)) + if code < 0 or code > 0x3fff: raise ValueError("Invalid AD9910 fractional amplitude!") return code @@ -590,7 +590,7 @@ class AD9910: def asf_to_amplitude(self, asf): """Return amplitude as a fraction of full scale corresponding to given amplitude scale factor.""" - return asf / float(0x3ffe) + return asf / float(0x3fff) @portable(flags={"fast-math"}) def frequency_to_ram(self, frequency, ram):