From 34f48f57cc4a464984d0e9e25026f391fc19d0df Mon Sep 17 00:00:00 2001 From: David Nadlinger Date: Thu, 20 Jun 2019 17:38:48 +0100 Subject: [PATCH] coredevice/suservo: Fix {get,set}_y_mu() scaling Previously, Channel.set_y(1) would set the output to -1 instead. --- artiq/coredevice/suservo.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/artiq/coredevice/suservo.py b/artiq/coredevice/suservo.py index 2011bba2d..4c41d1a90 100644 --- a/artiq/coredevice/suservo.py +++ b/artiq/coredevice/suservo.py @@ -6,6 +6,7 @@ from artiq.coredevice import urukul, sampler COEFF_WIDTH = 18 +Y_FULL_SCALE_MU = (1 << (COEFF_WIDTH - 1)) - 1 COEFF_DEPTH = 10 + 1 WE = 1 << COEFF_DEPTH + 1 STATE_SEL = 1 << COEFF_DEPTH @@ -18,7 +19,7 @@ COEFF_SHIFT = 11 @portable def y_mu_to_full_scale(y): """Convert servo Y data from machine units to units of full scale.""" - return y*(1./(1 << COEFF_WIDTH - 1)) + return y / Y_FULL_SCALE_MU @portable @@ -508,4 +509,6 @@ class Channel: :param profile: Profile number (0-31) :param y: IIR state in units of full scale """ - self.set_y_mu(profile, int(round((1 << COEFF_WIDTH - 1)*y))) + y_mu = int(round(y * Y_FULL_SCALE_MU)) + self.set_y_mu(profile, y_mu) + return y_mu