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
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):
##############################################################################
# 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()
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()
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)
if i % 256 == 0:
print x, v
- if 1:
+ if 0:
figure()
plot(n, r)
xlabel('DAC code')