To a global config instance
authorDan White <dan@whiteaudio.com>
Thu, 18 Oct 2012 18:04:26 +0000 (13:04 -0500)
committerDan White <dan@whiteaudio.com>
Thu, 18 Oct 2012 18:04:26 +0000 (13:04 -0500)
python-lib/calibrate.py
python-lib/devboard.py

index 8ea42f33d421309e6710d5e4c7d35df747102511..a6e332e2a4563de0f0882bc481a884f4de8722be 100644 (file)
@@ -390,6 +390,11 @@ while True:
         print '-'*80
         print
 
+    #back to h[0] for consistency
+    mux.selA = 0
+    mux.selB = 0
+    mux.write()
+
     fname = '%s.npz' % (dt.datetime.now().strftime('%Y-%m-%d_%H%M%S'), )
     print '*** writing to %s ***' % fname
     savez(fname,
index 728581a5ac717daaeeeff130720fa0ac0ed5e75e..65f0e7a7ac8419ade548779e46806b8661b9d28f 100644 (file)
@@ -37,7 +37,6 @@ RG =  { 'Vdd_ns430':    10e3,
         'AVdd_atoi':    10e3 }
 
 
-
 def count2volt(c, warn=True):
     """Properly handle 14-b data from 12b ADC value.  Average bits
     originate from 12b samples, so max value is 0xfff0 NOT 0xfffc.
@@ -126,7 +125,7 @@ def dump_config():
     """Return a hierarchical dict of settings appropriate for passing to the
     individual constructors.
     """
-    s = {}
+    s = _config
     # configuration
     # chip SPI config
     s['chain'] = chain.dump_config()
@@ -154,6 +153,8 @@ def save_config(name=None):
     """Write current config to a file.
     """
     cfg = dump_config()
+    #update global run-time storage
+    _config.update(cfg)
     if name is None:
         name = 'config.%s.yaml' % cfg['date']
     yaml.dump(cfg, open(name, 'wb'))
@@ -163,6 +164,9 @@ def save_config(name=None):
 #
 # Module-level names.  Define here so they are found in the module scope
 #
+# devboard configuration
+_config = {}
+
 spi0 = None
 spi1 = None
 i2c = None
@@ -177,12 +181,20 @@ arb = None
 amux = None
 
 def init_devboard(name='devboard-defaults.yaml'):
+    """Initialize devboard <-> usbio with a known configuration.  `name` may be
+    a string filename, defaulting to 'devboard-defaults.yaml' or an integer
+    representing the file 'chip%02i.calibration.yaml'.
+    """
     global spi0, spi1, i2c
     global ibias, vatoi, v430
     global dac, adc
     global chain, mux
     global arb, amux
 
+    # try loading config for given chip ID
+    if isinstance(name, int):
+        name = 'chip%02i.calibration.yaml' % name
+
     try:
         load_config(name)
         return
@@ -268,6 +280,7 @@ def load_config(name):
     else:
         cfg = yaml.load(open(name, 'rb'))
 
+    _config.update(cfg)
     ##########################################################################
     # Setup FTDI serial ports
     spi0 = usbio.SPI(**cfg['spi0'])
@@ -328,6 +341,10 @@ def load_config(name):
     #arb = usbio.Chain(spi1, 'chain1_conf', length=16)
     #amux = usbio.Mux(spi1, 'chain1_mux')
 
+    #send values to chip
+    for f in (chain, mux, arb, amux):
+        f.write()
+
 
 
 # define power supply defaults