From 23fd6c4d2773879dd50d9303ecd70e797abc0627 Mon Sep 17 00:00:00 2001 From: Dan White Date: Sun, 22 Apr 2012 16:37:51 -0500 Subject: [PATCH] DAC class --- python-lib/usbio.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/python-lib/usbio.py b/python-lib/usbio.py index 69ebbea..b7eeb40 100644 --- a/python-lib/usbio.py +++ b/python-lib/usbio.py @@ -523,6 +523,44 @@ class DAC_Channel(object): def value(self): return self._value +class DAC_word(object): + """ + Container for (easily) constructing an appropriate 32-bit DAC8568 command. + """ + ALL_CHANNELS = 0xf + + def __init__(self): + self._word = intbv(0)[32:] + + @property + def word(self): + return self._word + + #prefix bits are 0xxx always + #def prefix(self, value): + # self._word[32:28] = intbv(value, max=2**4) + + def control(self, value): + self._word[28:24] = intbv(value, max=2**4) + + def address(self, value): + self._word[24:20] = intbv(value, max=2**4) + + def data(self, value): + self._word[20:4] = intbv(value, max=2**16) + + def feature(self, value): + self._word[4:0] = intbv(value, max=2**4) + + def LDAC(self, bitfield): + self.reset() + self.control(0x6) + self._word[8:0] = intbv(bitfield, max=2**8) + + def reset(self): + self._word = intbv(0)[32:] + + class DAC8568(object): CTL_WIDTH = 32 DAC_WIDTH = 16 @@ -536,6 +574,13 @@ class DAC8568(object): def __str__(self): return ''.join(map(chr, self.bytes())) + def updateall(self, value): + v = intbv(value, max=self.DAC_WIDTH) + d = intbv(0)[32:] + d[28:24] = 0x3 + d[24:20] = 0xf + d += (v << 4) + def bytes(self): """Return the control data as a byte sequence in MSB..LSB order.""" w = self.word -- 2.25.1