add plotting to calibration
authorDan White <dan@whiteaudio.com>
Mon, 27 Aug 2012 18:56:10 +0000 (13:56 -0500)
committerDan White <dan@whiteaudio.com>
Mon, 27 Aug 2012 18:56:10 +0000 (13:56 -0500)
python-lib/calibrate.py

index 31ac82cc0677c59336161d9c5aa1023e1c0bdc24..c64d2200516bb1cc49e29737a956154e4151e30c 100644 (file)
@@ -1,5 +1,9 @@
 
 
+from termplotter import TermPlotter
+
+tplot = TermPlotter([-2**11, 2**11])
+
 
 def bisect(fset, limits=[0.0, 1.0], dgmin=None, up='uk', down='dj'):
     """Given a one-input function fset and list of limits, interactively bisect
@@ -64,6 +68,7 @@ def mux_a_offset(x):
         sleep(DELAY)
     mv = mean(values)
     print xi, mv
+    print tplot(mv)
     return mv
 
 def mux_b_offset(x):
@@ -77,6 +82,7 @@ def mux_b_offset(x):
         sleep(DELAY)
     mv = mean(values)
     print xi, mv
+    print tplot(mv)
     return mv
 
 def chain_a_offset(x, n, mux_offset):
@@ -95,6 +101,7 @@ def chain_a_offset(x, n, mux_offset):
         sleep(DELAY)
     mv = mean(values)
     print xi, mv
+    print tplot(mv)
     return mv - mux_offset
 
 dac.vina(1.25)
@@ -116,15 +123,16 @@ mux.write()
 adc.triggerMode(adc.MODE_MANUAL_MANUAL)
 
 
-from scipy.optimize import brentq
+#from scipy.optimize import brentq as fopt
+from scipy.optimize import bisect as fopt
 
 N_SAMPLES = 10
-DELAY = 0.01
+DELAY = 0.05
 
 print
 print 'Calibrating mux otaA'
 adc.mux(4)
-resA = brentq(mux_a_offset, -128, 127, xtol=0.01, disp=True)
+resA = fopt(mux_a_offset, -128, 127, xtol=0.01, disp=True)
 print resA
 muxA_offset = mean([offset2signed(adc.read(), 16) for i in range(1000)])
 print '*** mux.otaA.offset =', int(round(resA))
@@ -134,7 +142,7 @@ if 0:
     print
     print 'Calibrating mux otaB'
     adc.mux(5)
-    resB = brentq(mux_b_offset, -128, 127, xtol=0.01, disp=True)
+    resB = fopt(mux_b_offset, -128, 127, xtol=0.01, disp=True)
     print resB
     muxB_offset = mean([offset2signed(adc.read(), 16) for i in range(1000)])
     print '*** mux.otaB.offset =', int(round(resB))
@@ -150,7 +158,7 @@ for n in range(48):
     mux.otaA.mode = mux.otaA.MUX_BUF
     mux.otaB.mode = mux.otaB.MUX_BUF
     mux.write()
-    nos = brentq(lambda x: chain_a_offset(x, n, muxA_offset),
+    nos = fopt(lambda x: chain_a_offset(x, n, muxA_offset),
             -128, 127,
             xtol=0.01,
             disp=True)