+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
sleep(DELAY)
mv = mean(values)
print xi, mv
+ print tplot(mv)
return mv
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):
sleep(DELAY)
mv = mean(values)
print xi, mv
+ print tplot(mv)
return mv - mux_offset
dac.vina(1.25)
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))
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))
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)