From: Dan White Date: Thu, 4 Apr 2013 20:41:18 +0000 (-0500) Subject: arb0 works!!! X-Git-Tag: bootrom-initial-submission~34 X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=b9622b42b62be4d7b1b03cd91fa2f3604b0e4781;p=430.git arb0 works!!! --- diff --git a/python-lib/arb.py b/python-lib/arb.py index d895b28..71b5562 100644 --- a/python-lib/arb.py +++ b/python-lib/arb.py @@ -1,18 +1,24 @@ #!/usr/bin/env python -import IPython from time import sleep +import IPython +from pylab import * + import devboard as dev dev.init_devboard(1) # requires devboard be already initialized -from calibrate import calibrate as cal +#import calibrate as cal +import calibrate +cal = calibrate.calibrate -#do_shell = True -do_shell = False +# ?are we already under an IPython shell? +in_ipython = IPython.core.interactiveshell.InteractiveShell.initialized() +# ?be interactive afterwards? +do_shell = True chain = dev.chain @@ -21,9 +27,109 @@ mux = dev.mux arb = dev.arb amux = dev.amux -a = arb.h[0] -m = amux.otaB +a0 = arb.h[0] + +vina = dev.dac.vina +vinb = dev.dac.vinb +vcmi = dev.dac.vcmi + +dac = dev.dac +adc = dev.adc + +#print vina() +#print vinb() +#print vcmi() + +#dev.i2c.NCO_CLK() +#dev.i2c.NCO_CLK() +#dev.i2c.NCO_CLK() + + + +############## +# ch2 +if 0: + print '********************' + print 'ch2' + amux.otaB.mode = amux.otaB.CAL_CMP + amux.otaB.fast = 1 + amux.otaB.gain = 15 + amux.selB = 0 + amux.write() + + for i in range(0, 128, 10): + print i + amux.otaB.offset = i + amux.write() + sleep(0.2) + + + +############# +# ch1 +if 0: + print '********************' + print 'ch1' + amux.selA = 1 + amux.write() + + + a0 = arb.h[0] + + a0.cal = 1 + + a0.otaA.se = 0 + a0.otaA.fast = 1 + a0.otaA.gain = 10 + a0.otaA.cint = 1 + + a0.otaB.se = a0.otaA.se + a0.otaB.fast = a0.otaA.fast + a0.otaB.gain = a0.otaA.gain + a0.otaB.cint = a0.otaA.cint + + arb.write() + + a0.otaA.zero = 1 + a0.otaB.zero = 1 + arb.write() + + a0.otaA.zero = 0 + a0.otaB.zero = 0 + arb.write() + + vcm = 1.25 + + + if 0: + for v in arange(vina(), vcm, 50e-3): + print v + vcmi(v) + vina(v) + vinb(v) + sleep(0.1) + + vcmi(vcm) + vina(vcm) + vinb(vcm) + #raw_input('** pause **') + + for vd in (-0.1, 0.0, 0.1): + print vd + vcmi(vcm) + vina(vcm + vd) + vinb(vcm - vd) + + for i in range(0, 128, 10): + print i + a0.otaA.offset = i + a0.otaB.offset = i + arb.write() + sleep(0.1) + vcmi(vcm) + vina(vcm) + vinb(vcm) @@ -32,6 +138,6 @@ m = amux.otaB ############################################################################## # drop into an IPython shell # -if do_shell: +if do_shell and not in_ipython: IPython.embed() diff --git a/python-lib/calibrate.py b/python-lib/calibrate.py index a0ba2a1..84fb306 100644 --- a/python-lib/calibrate.py +++ b/python-lib/calibrate.py @@ -195,6 +195,7 @@ def offset2signed(v, bits): return (v - 2**(bits-1)) >> 2 def mux_a_offset(x, c, verbose=True): + adc.mux(4) #xi = int(x[0]) xi = int(x) mux.otaA.offset = xi @@ -210,6 +211,7 @@ def mux_a_offset(x, c, verbose=True): return array((mv,)) def mux_b_offset(x, c, verbose=True): + adc.mux(5) xi = int(x) mux.otaB.offset = xi mux.write() @@ -332,6 +334,7 @@ def amux_a_offset(x, c, verbose=True): xi = int(x) amux.otaA.offset = xi amux.write() + adc.mux(6) sleep(MUX_CAL_DELAY) adc.read() values = [] @@ -346,6 +349,7 @@ def amux_b_offset(x, c, verbose=True): xi = int(x) amux.otaB.offset = xi amux.write() + adc.mux(7) sleep(MUX_CAL_DELAY) adc.read() values = [] @@ -437,21 +441,18 @@ def arb_offsets(values, converged, mux_offset, verbose=True): -dac.vina(1.25) -dac.vinb(1.25) -dac.vcmi(1.25) +# TODO: commented out, ensure ADC is init'ed in the right places +#adc.reset() +#adc.triggerMode(adc.MODE_IDLE) +#adc.average(16) +#adc.convst_spi(1) -adc.reset() -adc.triggerMode(adc.MODE_IDLE) -adc.average(16) -adc.convst_spi(1) +#adc.channelMode(4, adc.SE) #even channel only +#adc.channelGain(4, 1) +#adc.channelGain(5, 1) -adc.channelMode(4, adc.SE) #even channel only -adc.channelGain(4, 1) -adc.channelGain(5, 1) - -adc.triggerMode(adc.MODE_MANUAL_MANUAL) +#adc.triggerMode(adc.MODE_MANUAL_MANUAL) @@ -476,6 +477,19 @@ def calibrate(name, elements=None, verbose=True): # if name == 'chain': N_CHANNELS = 48 + + #setup adc + adc.reset() + adc.triggerMode(adc.MODE_IDLE) + + adc.average(16) + adc.convst_spi(1) + adc.channelMode(4, adc.SE) #even channel only + adc.channelGain(4, 1) + adc.channelGain(5, 1) + + adc.triggerMode(adc.MODE_MANUAL_MANUAL) + def func(values, converging): return chain_offsets( values, @@ -483,6 +497,11 @@ def calibrate(name, elements=None, verbose=True): (int(mux.otaA.offset), int(mux.otaB.offset)) ) + #setup mux to buffer + mux.otaA.mode = mux.otaA.MUX_BUF + mux.otaB.mode = mux.otaB.MUX_BUF + mux.write() + #setup initial guess, just use the current values x0 = zeros((2, N_CHANNELS), dtype=int) for i in range(N_CHANNELS): @@ -490,17 +509,34 @@ def calibrate(name, elements=None, verbose=True): x0[j,i] = chain.h[i].ota[j].offset offsets, stats = secant_opt(func, x0, limits, elements=elements, verbose=verbose) + # # Main pad buffer + mux # elif name == 'mux': + adc.reset() + adc.triggerMode(adc.MODE_IDLE) + + adc.average(16) + adc.convst_spi(1) + adc.channelMode(4, adc.SE) #even channel only + adc.channelGain(4, 1) + adc.channelGain(5, 1) + adc.mux(4) + + adc.triggerMode(adc.MODE_MANUAL_MANUAL) + #save mux state - old_mode = [mux.ota[i].mode for i in range(2)] + #old_mode = [mux.ota[i].mode for i in range(2)] mux.otaA.mode = mux.otaA.CAL_CMP mux.otaB.mode = mux.otaB.CAL_CMP + mux.otaA.fast = 1 + mux.otaB.fast = 1 + mux.otaA.gain = 15 + mux.otaB.gain = 15 mux.write() - adc.mux(4) + def func(values, converging): outA = mux_a_offset(values[0], converging[0], verbose) @@ -509,7 +545,7 @@ def calibrate(name, elements=None, verbose=True): out[0] = outA out[1] = outB return out - return array([outA, outB]) + #return array([outA, outB]) #setup initial guess, just use the current values x0 = zeros((2,), dtype=int) @@ -520,9 +556,10 @@ def calibrate(name, elements=None, verbose=True): elements=elements, verbose=verbose) #restore mux state - for i,mode in enumerate(old_mode): - mux.ota[i].mode = mode - mux.write() + #for i,mode in enumerate(old_mode): + #mux.ota[i].mode = mode + #mux.write() + # # Secondary arbitrary function, 16 channels # @@ -546,13 +583,22 @@ def calibrate(name, elements=None, verbose=True): # Secondary pad buffer + mux # elif name == 'amux': + adc.reset() + adc.triggerMode(adc.MODE_IDLE) + adc.average(16) + adc.convst_spi(1) + adc.channelMode(6, adc.SE) #even channel only + adc.channelGain(6, 1) + adc.channelGain(7, 1) + adc.mux(6) + adc.triggerMode(adc.MODE_MANUAL_MANUAL) + #save mux state old_mode = [amux.ota[i].mode for i in range(2)] amux.otaA.mode = amux.otaA.CAL_CMP amux.otaB.mode = amux.otaB.CAL_CMP amux.write() - adc.mux(6) def func(values, converging): outA = amux_a_offset(values[0], converging[0], verbose) @@ -587,101 +633,101 @@ def calibrate(name, elements=None, verbose=True): - -while False: - import datetime as dt - if 1: - mux.otaA.mode = mux.otaA.CAL_BUF - mux.otaA.fast = 1 - mux.otaA.gain = 15 - mux.write() - print - print 'Calibrating mux otaA' - adc.mux(4) - resA, tmp = secant_opt( - mux_a_offset, - zeros((1,), dtype=int), - [-128, 127], - ) - muxA_offset = mean([offset2signed(adc.read(), 16) for i in range(1000)]) - print '*** mux.otaA.offset =', muxA_offset, ' @', resA - else: - resA = 53 - muxA_offset = 0.0 - - - if 1: - mux.otaB.mode = mux.otaB.CAL_BUF - mux.otaB.fast = 1 - mux.otaB.gain = 15 - mux.write() - print - print 'Calibrating mux otaB' - adc.mux(5) - #resB = secant_opt(mux_b_offset, 0, [-128, 127]) - resB, tmp = secant_opt( - mux_b_offset, - zeros((1,), dtype=int), - [-128, 127], - ) - muxB_offset = mean([offset2signed(adc.read(), 16) for i in range(1000)]) - print '*** mux.otaB.offset =', muxB_offset, ' @', resB - else: - resB = 59 - muxB_offset = 0.0 +def do_the_deed(): + while True: + import datetime as dt + if 1: + mux.otaA.mode = mux.otaA.CAL_CMP + mux.otaA.fast = 1 + mux.otaA.gain = 15 + mux.write() + print + print 'Calibrating mux otaA' + adc.mux(4) + resA, tmp = secant_opt( + mux_a_offset, + zeros((1,), dtype=int), + [-128, 127], + ) + muxA_offset = mean([offset2signed(adc.read(), 16) for i in range(1000)]) + print '*** mux.otaA.offset =', muxA_offset, ' @', resA + else: + resA = 53 + muxA_offset = 0.0 - if 0: - offset_chain_a = [] - for n in range(48): + if 1: + mux.otaB.mode = mux.otaB.CAL_CMP + mux.otaB.fast = 1 + mux.otaB.gain = 15 + mux.write() print - print 'Calibrating chain %02i A' % n - adc.triggerMode(adc.MODE_IDLE) - adc.mux(4) - adc.triggerMode(adc.MODE_MANUAL_MANUAL) - mux.selA = n - mux.selB = n + print 'Calibrating mux otaB' + adc.mux(5) + #resB = secant_opt(mux_b_offset, 0, [-128, 127]) + resB, tmp = secant_opt( + mux_b_offset, + zeros((1,), dtype=int), + [-128, 127], + ) + muxB_offset = mean([offset2signed(adc.read(), 16) for i in range(1000)]) + print '*** mux.otaB.offset =', muxB_offset, ' @', resB + else: + resB = 59 + muxB_offset = 0.0 + + + if 0: + offset_chain_a = [] + for n in range(48): + print + print 'Calibrating chain %02i A' % n + adc.triggerMode(adc.MODE_IDLE) + adc.mux(4) + adc.triggerMode(adc.MODE_MANUAL_MANUAL) + mux.selA = n + mux.selB = n + mux.otaA.mode = mux.otaA.MUX_BUF + mux.otaB.mode = mux.otaB.MUX_BUF + mux.write() + nos = secant_opt(lambda x: chain_a_offset(x, n, muxA_offset), resA, (-128, 127)) + mean_os = mean([offset2signed(adc.read(), 16) for i in range(1000)]) + print '*** chain.h[%02i].otaA.offset =' % n, mean_os, ' @', nos + chain_outputs(n) + + if 1: mux.otaA.mode = mux.otaA.MUX_BUF mux.otaB.mode = mux.otaB.MUX_BUF mux.write() - nos = secant_opt(lambda x: chain_a_offset(x, n, muxA_offset), resA, (-128, 127)) - mean_os = mean([offset2signed(adc.read(), 16) for i in range(1000)]) - print '*** chain.h[%02i].otaA.offset =' % n, mean_os, ' @', nos - chain_outputs(n) - - if 1: - mux.otaA.mode = mux.otaA.MUX_BUF - mux.otaB.mode = mux.otaB.MUX_BUF - mux.write() - #def secant_opt(func, x0, limits, elements=None, x1scale=0.1, maxiter=50): + #def secant_opt(func, x0, limits, elements=None, x1scale=0.1, maxiter=50): - chain_os, stats = secant_opt( - lambda x,y: chain_offsets(x, y, (muxA_offset, muxB_offset)), - resA*ones((2,N_CHANNELS), dtype=int), - (-128, 127), - verbose=True, - ) + chain_os, stats = secant_opt( + lambda x,y: chain_offsets(x, y, (muxA_offset, muxB_offset)), + resA*ones((2,N_CHANNELS), dtype=int), + (-128, 127), + verbose=True, + ) - print '-'*80 - print 'offsets:', chain_os[:N_CHANNELS] - print 'N-evals:', stats['nevals'][:N_CHANNELS] - print '-'*80 - print + print '-'*80 + print 'offsets:', chain_os[:N_CHANNELS] + print 'N-evals:', stats['nevals'][:N_CHANNELS] + print '-'*80 + print - #back to h[0] for consistency - mux.selA = 0 - mux.selB = 0 - mux.write() + #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, - muxres=(resA, resB), - muxos=(muxA_offset, muxB_offset), - chaincal=chain_os, - **stats - ) - break + fname = '%s.npz' % (dt.datetime.now().strftime('%Y-%m-%d_%H%M%S'), ) + print '*** writing to %s ***' % fname + savez(fname, + muxres=(resA, resB), + muxos=(muxA_offset, muxB_offset), + chaincal=chain_os, + **stats + ) + break diff --git a/python-lib/chip01-calibration.yaml b/python-lib/chip01-calibration.yaml index a835582..5a15499 100644 --- a/python-lib/chip01-calibration.yaml +++ b/python-lib/chip01-calibration.yaml @@ -2,8 +2,8 @@ amux: csname: chain1_mux otaA: {fast: 0, gain: 0, mode: 2, offset: 0} otaB: {fast: 0, gain: 0, mode: 2, offset: 0} - selA: 48 - selB: 48 + selA: 16 + selB: 16 arb: csname: chain1_conf harmonics: @@ -279,8 +279,8 @@ mux: csname: chain0_mux otaA: {fast: 1, gain: 15, mode: 2, offset: 44} otaB: {fast: 1, gain: 15, mode: 2, offset: 81} - selA: 0 - selB: 0 + selA: 48 + selB: 48 spi0: cs: _idle: [-1, 200] diff --git a/python-lib/chip14-arb0-test.pdf b/python-lib/chip14-arb0-test.pdf new file mode 100644 index 0000000..1a40b32 Binary files /dev/null and b/python-lib/chip14-arb0-test.pdf differ diff --git a/python-lib/devboard.py b/python-lib/devboard.py index 8c234f7..176929a 100644 --- a/python-lib/devboard.py +++ b/python-lib/devboard.py @@ -354,18 +354,13 @@ def load_config(name, delay=0): cfg = yaml.load(open(name, 'rb')) _config.update(cfg) + ########################################################################## # Setup FTDI serial ports spi0 = usbio.SPI(**cfg['spi0']) spi1 = usbio.SPI(**cfg['spi1']) i2c = usbio.I2C(**cfg['i2c']) - sleep(delay) - - ########################################################################## - # Analog bias - # (bias generator also uses DAC_1 and DAC_3, - # need to make a wrapper class to do e.g. ibias.buf = 10 uA) - ibias = usbio.AD524x(i2c, **cfg['ibias']) + #sleep(delay) ########################################################################## # Power supplies @@ -396,6 +391,12 @@ def load_config(name, delay=0): #dac.vbias_core(000e-3) #dac.vbias_buf(000e-3) + ########################################################################## + # Analog bias + # (bias generator also uses DAC_1 and DAC_3, + # need to make a wrapper class to do e.g. ibias.buf = 10 uA) + ibias = usbio.AD524x(i2c, **cfg['ibias']) + ########################################################################## # ADC # (TODO: see 'ADC testing stuff' section below) diff --git a/python-lib/slope-arb.py b/python-lib/slope-arb.py index 75d4448..63e654f 100644 --- a/python-lib/slope-arb.py +++ b/python-lib/slope-arb.py @@ -1,3 +1,16 @@ + + + + +#vina = dev.dac.vina +#vinb = dev.dac.vinb +#vcmi = dev.dac.vcmi + +#arb = dev.arb +#a0 = arb.h[0] + + + while True: vcm = 1.25 @@ -13,44 +26,75 @@ while True: vd = [] tint = [] - for d in arange(-800e-3, 800e-3+1e-3, 10e-3): - print d*1e3 - vd.append(d) + #for i in range(80,130,10): + if 1: + #print '****' + #print '* offset=', i + + #a0.otaA.offset = i + #a0.otaB.offset = i - ti = 0.5 - #for ti in (0.4, 0.2, 0.1, 0.05, 0.025): - while True: - a0.otaA.zero=1; arb.write(); a0.otaA.zero=0; arb.write() - dev.adc.read() - v0 = dev.adc.read() * (2.5 / 2**16) + #a0.otaA.cint = 1 + #a0.otaB.cint = 1 - vina(vcm + d) - vinb(vcm - d) - sleep(ti) - vina(vcm) - vinb(vcm) + #a0.otaA.fast = 1 + #a0.otaB.fast = 1 - dev.adc.read() - v1 = dev.adc.read() * (2.5 / 2**16) + #a0.otaA.gain = 15 + #a0.otaB.gain = 15 + #arb.write() - vo = v1 - v0 + #d = -2.5 + ti = 1.0 + timax = 4.1 + #while d >= -2.5 and d <= 2.5: + for d in arange(-2500e-3, 2500e-3+1e-3, 10e-3): + print d*1e3 + vd.append(d) - print ti, vo - if abs(vo) < 1.1: - break + #for ti in (0.4, 0.2, 0.1, 0.05, 0.025): + while True: + a0.otaA.zero=1; arb.write(); a0.otaA.zero=0; arb.write() + dev.adc.read() + v0 = dev.adc.read() * (2.5 / 2**16) - ti *= 0.5 + vina(vcm + d) + vinb(vcm - d) + sleep(ti) + vina(vcm) + vinb(vcm) - tint.append(ti) - vout.append(vo) - - #sleep(0.1) + dev.adc.read() + v1 = dev.adc.read() * (2.5 / 2**16) + + + vo = v1 - v0 + + print ti, vo + + tiold = ti + if abs(vo) < 0.5: + ti *= 2.0 + elif abs(vo) > 1.1: + ti *= 0.5 + else: + break + + if ti > timax: + ti = tiold + break + + #ti *= 0.5 + + tint.append(ti) + vout.append(vo) + + #sleep(0.1) break -out0 = array(out0) -out1 = array(out1) +vout = array(vout) vd = array(vd) tint = array(tint) @@ -61,11 +105,13 @@ plot(vd, vout, 'o') subplot(223) plot(vd, tint, 'o') -ylim([0, 0.6]) +ylim([0, 1.2*tint.max()]) subplot(222) plot(vd, vout/tint, 'o') +suptitle('Vout*tint vs. vd\nChip #14, arb0') +