Ready to test chip 02
authorDan White <dan@whiteaudio.com>
Tue, 1 May 2012 15:33:25 +0000 (10:33 -0500)
committerDan White <dan@whiteaudio.com>
Tue, 1 May 2012 15:33:25 +0000 (10:33 -0500)
python-lib/mpsse-test.py

index 380de5875e42cd8648c9231076fee7af1fbb9cc4..e7335fd7b54d0e033a02052d4ee35a9dfa31e964 100755 (executable)
@@ -1,15 +1,19 @@
 #!/usr/bin/env python
 
-import struct
-from time import sleep
+from pylab import *
 
-from myhdl import intbv
+import IPython
 from myhdl import bin as b
+import numpy as np
+from time import sleep
 
 import usbio
 
-import IPython
-import numpy as np
+
+
+do_shell = True
+
+
 
 def bytes2str(self, c):
     r = c
@@ -40,7 +44,7 @@ i2c = usbio.I2C(interface=usbio.ftdi.INTERFACE_C, scl=0, sda=1,
 ##############################################################################
 # Analog bias
 # (bias generator also uses DAC_1 and DAC_3,
-#  need to make a wrapper class to do ibias.buf = 10 uA)
+#  need to make a wrapper class to do e.g. ibias.buf = 10 uA)
 #
 ibias = usbio.AD524x(i2c, 0)
 ibias.posA = 0
@@ -60,13 +64,9 @@ v430.alias('vb', 'vdd')
 
 # setup power supply defaults
 def psdefaults():
-    print "Setting atoi.avdd"
     vatoi.avdd = 2.5
-    print "Setting atoi.vdd"
     vatoi.vdd = 1.2
-    print "Setting 430.vdd"
     v430.vdd = 1.2
-    print "Setting 430.dvdd"
     v430.dvdd = 2.5
 
 psdefaults()
@@ -74,89 +74,110 @@ psdefaults()
 
 ##############################################################################
 # DAC
+# default mode is dac.INPUT_UPDATE_SINGLE
 #
 dac = usbio.DAC_atoi(spi0, 'dac')
 dac.swreset()
 
-# reference is tied to ADC also
+# reference is tied to ADC, do not power down
 dac.reference(dac.REF_FLEXIBLE_ALWAYS_ON)
 
 # CLR is tied high, explicitly ignore anyway
 dac.CCR(dac.IGNORE_CLR)
 
-# power up used channels
-bitfield = 0
-for i in (0, 1, 2, 3, 4):
-    bitfield += (1 << i)
+# power up all channels
+bitfield = 0xff
 dac.power(dac.POWER_ON, bitfield)
 
-# power up used channels
-bitfield = 0
-for i in (0, 1, 2, 3, 4):
-    bitfield += (1 << i)
-dac.power(dac.POWER_ON, bitfield)
-
-# others set 1k to gnd
-bitfield = 0
-for i in (5, 6, 7):
-    bitfield += (1 << i)
-dac.power(dac.POWER_OFF_1k, bitfield)
-
 # set initial output voltages
 # before tuning
+# channels 0 .. 4
 dac.vina(1.0)
 dac.vinb(1.0)
 dac.vcmi(1.0)
 dac.vbias_core(0.0)
 dac.vbias_buf(0.0)
 
+# zero others
+for i in range(5, 8):
+    dac.setv(i, 0.0)
+
 
 ##############################################################################
 # ADC
 # (TODO)
 #
 adc = usbio.ADS8201(spi0)
-adc.setRegister(adc.TRIGGER_SCR, 0x02)
-rv  = adc.getRegister(adc.TRIGGER_SCR)
-print 'receivd:', b(rv, 16)
 
-def sr(n):
-    adc.setRegister(adc.CHAN_SEL, n)
-    rv = adc.getRegister(adc.CHAN_SEL)
-    print 'receivd:', b(rv, 16)
 
 
 ##############################################################################
-# chain0 config registers
+# AtoI digital SPI config
+#
+# jumper on devboard accesses MISO for each chain
+chain = usbio.Chain(spi1, 'chain0_conf', length=48)
+mux = usbio.Mux(spi1, 'chain0_mux')
+
+# MISO is not available
+arb = usbio.Chain(spi1, 'chain1_conf', length=16)
+amux = usbio.Mux(spi1, 'chain1_mux')
+
+
+
+##############################################################################
+# chain config registers
+# (need an explicit foo.write() to send config
+#
+
+# Main Chain0
+for h in chain.h:
+    h.cal = 1
+    for ota in h.ota:
+        ota.se = 0
+        ota.cint = 1
+        ota.zero = 0
+        ota.fast = 1
+        ota.gain = 8
+        ota.offset = 0
+chain.write()
+
+mux.selA = 48
+mux.selB = 48
+for ota in mux.ota:
+    ota.mode = mux.CAL_CMP
+    ota.fast = 1
+    ota.gain = 8
+    ota.offset = 0
+mux.write()
+
+
+# Secondary Chain1
+for h in arb.h:
+    h.cal = 1
+    for ota in h.ota:
+        ota.se = 0
+        ota.cint = 1
+        ota.zero = 0
+        ota.fast = 1
+        ota.gain = 8
+        ota.offset = 0
+arb.write()
+
+amux.selA = 48
+amux.selB = 48
+for ota in amux.ota:
+    ota.mode = mux.CAL_CMP
+    ota.fast = 1
+    ota.gain = 8
+    ota.offset = 0
+amux.write()
+
+
+
+##############################################################################
+# drop into an IPython shell
 #
-if 1:
-    chain = usbio.Chain(spi1, 'chain0_conf', length=48)
-    mux = usbio.Mux(spi1, 'chain0_mux')
-
-    #calibration mode for all channels
-    for h in chain.h:
-        h.cal = 1
-        for ota in h.ota:
-            ota.se = 0
-            ota.cint = 1
-            ota.zero = 0
-            ota.fast = 1
-            ota.gain = 8
-            ota.offset = 0
-
-    cfg = ''.join(map(chr, chain.bytes))
-
-    spi1.SetCS('chain0_conf')
-    out = spi1.Exchange(cfg)
-    print
-    print ''.join(map(lambda x: '%02x' % ord(x), cfg))
-    print
-    print ''.join(map(lambda x: '%02x' % ord(x), out))
-
-    out = spi1.Exchange(cfg)
-    print
-    print ''.join(map(lambda x: '%02x' % ord(x), out))
-
-IPython.embed()
+if do_shell:
+    IPython.embed()