From: Dan White Date: Sun, 1 Jul 2012 02:03:18 +0000 (-0500) Subject: interactive bisect can repeat a guess X-Git-Tag: calibrations~37 X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=09d097506be28360a8d87fe5ebcfd31c422618ab;p=430.git interactive bisect can repeat a guess --- diff --git a/python-lib/mpsse-test.py b/python-lib/mpsse-test.py index d292bcb..b61beb2 100755 --- a/python-lib/mpsse-test.py +++ b/python-lib/mpsse-test.py @@ -34,7 +34,7 @@ def str2hex(x): return ''.join(map(lambda h: '%02x' % ord(h), x)) -def bisect(fset, limits=[0.0, 1.0], dgmin=None): +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 the range by sending fset(guess) and asking to go (u)p or (d)own for the next step. Each stepsize is progressively halved and optionally limited to @@ -53,18 +53,25 @@ def bisect(fset, limits=[0.0, 1.0], dgmin=None): guess.append(g) fset(g) - a = raw_input('q, [u,k], [d,j] ? ').lower() + a = raw_input('q, a, [%s], [%s] ? ' % (up, down)).lower() if a == 'q': quit = True return guess[2:] - if a in 'dj': + if a in down: g = g - dg - elif a in 'uk': + elif a in up: g = g + dg + elif a in 'a': + #again, keep same guess, do not modify dg + continue else: print 'OOPS, expecting u or d only' + # limit values + g = min(g, xmax) + g = max(g, xmin) + dg = dg / 2 # for ints, step size stops at 1 if isinstance(xmin, int): @@ -77,9 +84,9 @@ def bisect(fset, limits=[0.0, 1.0], dgmin=None): ############################################################################## # Setup FTDI serial ports # -spi0 = usbio.AtoiSPI0(100e3) #port A +spi0 = usbio.AtoiSPI0(1000e3) #port A -spi1 = usbio.AtoiSPI1(100e3) #port B +spi1 = usbio.AtoiSPI1(1000e3) #port B spi1.context.pidle = spi1.context.pstop = 0xf8 spi1.Stop() @@ -231,10 +238,10 @@ print str2hex(bytes2str(chain.bytes)) mux.selA = 0 mux.selB = 0 for ota in mux.ota: - ota.mode = ota.MUX_CMP + ota.mode = ota.CAL_CMP ota.fast = 1 ota.gain = 8 - ota.offset = 0 + ota.offset = 52 mux.write() @@ -298,10 +305,12 @@ if 0: n = [] r = [] - nbits = 16 + nbits = 12 for i in range(2**nbits): x = 2**(16-nbits) * i dac.set(0, x) + dac.set(2, x) + dac.set(4, x) adc.read() #sham to trigger conversion sleep(160e-6) #ensure 160us conversion time delay n.append(x) @@ -310,7 +319,7 @@ if 0: if i % 256 == 0: print x, v - if 1: + if 0: figure() plot(n, r) xlabel('DAC code')