From: Dan White Date: Tue, 17 Apr 2012 19:30:24 +0000 (-0500) Subject: dac is SPI1 mode X-Git-Tag: calibrations~107 X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=174c212fbe4bf327c9edb4b5a42dc27fd1a662eb;p=430.git dac is SPI1 mode --- diff --git a/python-lib/mpsse-test.py b/python-lib/mpsse-test.py index 953c4ab..0e33bf9 100644 --- a/python-lib/mpsse-test.py +++ b/python-lib/mpsse-test.py @@ -3,6 +3,7 @@ import time import struct +from myhdl import intbv from myhdl import bin as b import mpsse @@ -13,7 +14,7 @@ import usbio class AtoiSPI0(mpsse.MPSSE): def __init__(self, freq): super(AtoiSPI0, self).__init__() - self.Open(0x0403, 0x6011, mpsse.SPI0, int(freq), + self.Open(0x0403, 0x6011, mpsse.SPI1, int(freq), interface=mpsse.IFACE_A) self.SetCS('flash') @@ -24,13 +25,13 @@ class AtoiSPI0(mpsse.MPSSE): self.context.pstart = 0x00 elif name == 'dac': self.context.pidle = self.context.pstop = 0x08 - self.context.pstart = 0x10 + self.context.pstart = 0x18 elif name == 'adc': self.context.pidle = self.context.pstop = 0x08 - self.context.pstart = 0x20 + self.context.pstart = 0x28 elif name == 'convst': self.context.pidle = self.context.pstop = 0x08 - self.context.pstart = 0x30 + self.context.pstart = 0x38 else: raise Exception, 'Unknown CS name: %s' % name @@ -77,7 +78,31 @@ class AtoiI2C(mpsse.MPSSE): return r -spi = AtoiSPI0(1e5) + +def int2str(value, width): + if (width % 8) != 0: + raise Exception, 'width must be multiple of 8' + v = intbv(value, max=2**width) + b = [v[i:i-8] for i in range(width, 0, -8)] + return ''.join(map(chr, b)) + + + + +def dacval(value): + v = intbv(0)[32:] + v[28:24] = 0x3 + v[24:20] = 0xf + v += (value << 4) + return int2str(v, 32) + + +def w(v): + spi.Start() + spi.Write(v) + spi.Stop() + +spi = AtoiSPI0(1e4) spi.SetLoopback(0) @@ -89,3 +114,21 @@ vatoi = usbio.AD524x(i2c, 2) v430 = usbio.AD524x(i2c, 3) + + +#turn on internal reference always +spi.SetCS('dac') + +int_ref_always_on = intbv(0)[32:] +int_ref_always_on[27] = 1 +int_ref_always_on[24] = 1 +int_ref_always_on[19] = 1 +int_ref_always_on[13] = 1 +w(int2str(int_ref_always_on, 32)) + +all_dacs_on = intbv(0)[32:] +all_dacs_on[26] = 1 +all_dacs_on[8:] = 0xff +w(int2str(all_dacs_on, 32)) + +w(dacval(2**15)) diff --git a/python-lib/usbio.py b/python-lib/usbio.py index 283a698..235d297 100644 --- a/python-lib/usbio.py +++ b/python-lib/usbio.py @@ -505,6 +505,35 @@ class AD524x(object): +class DAC_Channel(object): + def __init__(self, defaults): + self._value = defaults['value'] + + @property + def value(self): + return self._value + +class DAC8568(object): + CTL_WIDTH = 32 + DAC_WIDTH = 16 + POR_VALUE = 2**(DAC_WIDTH - 1) + + def __init__(self, spibus, cs='dac'): + self.bus = spibus + self.cs = 'dac' + self._word = intbv(0)[self.CTL_WIDTH:] + + @property + def bytes(self): + """Return the control data as a byte sequence in MSB..LSB order.""" + w = self.word + b = [w[i:i-8] for i in range(self.CTL_WIDTH, 0, -8)] + return tuple(b) + + def send(self): + self.bus.SetCS('dac') + + class I2C(object): def write(self, data): """Send i2c command data to slave."""