forked from M-Labs/artiq
1
0
Fork 0

moninj: display voltage in DACWidget

This commit is contained in:
Simon Renblad 2024-06-06 15:25:46 +08:00
parent 9386a7a16f
commit 81a0db0ebf
1 changed files with 18 additions and 10 deletions

View File

@ -333,22 +333,24 @@ class _DDSWidget(QtWidgets.QFrame):
class _DACWidget(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) QtWidgets.QFrame.__init__(self)
self.spi_channel = spi_channel self.spi_channel = spi_channel
self.channel = channel self.channel = channel
self.cur_value = 0 self.cur_value = 0x8000;
self.title = title self.title = title
self.vref = vref
self.offset_dacs = offset_dacs
self.setFrameShape(QtWidgets.QFrame.Box) self.setFrameShape(QtWidgets.QFrame.Box)
self.setFrameShadow(QtWidgets.QFrame.Raised) self.setFrameShadow(QtWidgets.QFrame.Raised)
grid = QtWidgets.QGridLayout() grid = QtWidgets.QGridLayout()
grid.setContentsMargins(0, 0, 0, 0) grid.setContentsMargins(5, 5, 5, 5)
grid.setHorizontalSpacing(0) grid.setHorizontalSpacing(5)
grid.setVerticalSpacing(0) grid.setVerticalSpacing(5)
self.setLayout(grid) self.setLayout(grid)
label = QtWidgets.QLabel("{} ch{}".format(title, channel)) label = QtWidgets.QLabel("{}[{}]".format(title, channel))
label.setAlignment(QtCore.Qt.AlignCenter) label.setAlignment(QtCore.Qt.AlignCenter)
grid.addWidget(label, 1, 1) grid.addWidget(label, 1, 1)
@ -362,9 +364,13 @@ class _DACWidget(QtWidgets.QFrame):
self.refresh_display() 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): def refresh_display(self):
self.value.setText("<font size=\"4\">{:.3f}</font><font size=\"2\"> %</font>" self.value.setText("<font size=\"4\">{:+.3f} V</font>"
.format(self.cur_value * 100 / 2**16)) .format(self.mu_to_voltage(self.cur_value)))
def sort_key(self): def sort_key(self):
return (2, self.spi_channel, self.channel) return (2, self.spi_channel, self.channel)
@ -373,7 +379,7 @@ class _DACWidget(QtWidgets.QFrame):
return (self.title, self.channel) return (self.title, self.channel)
def to_model_path(self): 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") _WidgetDesc = namedtuple("_WidgetDesc", "uid comment cls arguments")
@ -426,9 +432,11 @@ def setup_from_ddb(ddb):
while isinstance(spi_device, str): while isinstance(spi_device, str):
spi_device = ddb[spi_device] spi_device = ddb[spi_device]
spi_channel = spi_device["arguments"]["channel"] 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): for channel in range(32):
widget = _WidgetDesc((k, channel), comment, _DACWidget, widget = _WidgetDesc((k, channel), comment, _DACWidget,
(spi_channel, channel, k)) (spi_channel, channel, k, vref, offset_dacs))
description.add(widget) description.add(widget)
elif v["type"] == "controller" and k == "core_moninj": elif v["type"] == "controller" and k == "core_moninj":
mi_addr = v["host"] mi_addr = v["host"]