From 81a0db0ebf2c9fae0b55d98e94bf08dea3b22b9f Mon Sep 17 00:00:00 2001 From: Simon Renblad Date: Thu, 6 Jun 2024 15:25:46 +0800 Subject: [PATCH] moninj: display voltage in DACWidget --- artiq/dashboard/moninj.py | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/artiq/dashboard/moninj.py b/artiq/dashboard/moninj.py index e83497289..fb7eed390 100644 --- a/artiq/dashboard/moninj.py +++ b/artiq/dashboard/moninj.py @@ -333,22 +333,24 @@ class _DDSWidget(QtWidgets.QFrame): class _DACWidget(QtWidgets.QFrame): - def __init__(self, dm, spi_channel, channel, title): + def __init__(self, dm, spi_channel, channel, title, vref, offset_dacs): QtWidgets.QFrame.__init__(self) self.spi_channel = spi_channel self.channel = channel - self.cur_value = 0 + self.cur_value = 0x8000; self.title = title + self.vref = vref + self.offset_dacs = offset_dacs self.setFrameShape(QtWidgets.QFrame.Box) self.setFrameShadow(QtWidgets.QFrame.Raised) grid = QtWidgets.QGridLayout() - grid.setContentsMargins(0, 0, 0, 0) - grid.setHorizontalSpacing(0) - grid.setVerticalSpacing(0) + grid.setContentsMargins(5, 5, 5, 5) + grid.setHorizontalSpacing(5) + grid.setVerticalSpacing(5) self.setLayout(grid) - label = QtWidgets.QLabel("{} ch{}".format(title, channel)) + label = QtWidgets.QLabel("{}[{}]".format(title, channel)) label.setAlignment(QtCore.Qt.AlignCenter) grid.addWidget(label, 1, 1) @@ -362,9 +364,13 @@ class _DACWidget(QtWidgets.QFrame): self.refresh_display() + def mu_to_voltage(self, code): + voltage = ((code - self.offset_dacs * 0x4) / (1 << 16)) * (4. * self.vref) + return voltage + def refresh_display(self): - self.value.setText("{:.3f} %" - .format(self.cur_value * 100 / 2**16)) + self.value.setText("{:+.3f} V" + .format(self.mu_to_voltage(self.cur_value))) def sort_key(self): return (2, self.spi_channel, self.channel) @@ -373,7 +379,7 @@ class _DACWidget(QtWidgets.QFrame): return (self.title, self.channel) def to_model_path(self): - return "dac/{} ch{}".format(self.title, self.channel) + return "dac/{}[{}]".format(self.title, self.channel) _WidgetDesc = namedtuple("_WidgetDesc", "uid comment cls arguments") @@ -426,9 +432,11 @@ def setup_from_ddb(ddb): while isinstance(spi_device, str): spi_device = ddb[spi_device] spi_channel = spi_device["arguments"]["channel"] + vref = v["arguments"].get("vref", 5.) + offset_dacs = v["arguments"].get("offset_dacs", 8192) for channel in range(32): widget = _WidgetDesc((k, channel), comment, _DACWidget, - (spi_channel, channel, k)) + (spi_channel, channel, k, vref, offset_dacs)) description.add(widget) elif v["type"] == "controller" and k == "core_moninj": mi_addr = v["host"]