From 4993ceec35b662a70e27556db62d823dfeff0d57 Mon Sep 17 00:00:00 2001 From: Robert Jordens Date: Mon, 14 May 2018 08:41:19 +0000 Subject: [PATCH] sampler: unroll conversion for speed --- artiq/coredevice/sampler.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/artiq/coredevice/sampler.py b/artiq/coredevice/sampler.py index ce8817a4c..7ede3a21f 100644 --- a/artiq/coredevice/sampler.py +++ b/artiq/coredevice/sampler.py @@ -23,10 +23,16 @@ def adc_mu_to_volt(data, gain=0): :param gain: PGIA gain setting (0: 1, ..., 3: 1000) :return: Voltage in Volts """ - input_span = 20. - for i in range(gain): - input_span /= 10. - volt_per_lsb = input_span/(1 << 16) + if gain == 0: + volt_per_lsb = 20./(1 << 16) + elif gain == 1: + volt_per_lsb = 2./(1 << 16) + elif gain == 2: + volt_per_lsb = .2/(1 << 16) + elif gain == 3: + volt_per_lsb = .02/(1 << 16) + else: + raise ValueError("invalid gain") return data*volt_per_lsb