From 2771f0a2daa2a7cc347f6dacfb897bb0da3ed30e Mon Sep 17 00:00:00 2001 From: Dan White Date: Mon, 30 Jan 2012 13:27:58 -0600 Subject: [PATCH] Linear vreg tuning law, use this one --- sch-pcb/devboard/vreg2.py | 157 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 157 insertions(+) create mode 100644 sch-pcb/devboard/vreg2.py diff --git a/sch-pcb/devboard/vreg2.py b/sch-pcb/devboard/vreg2.py new file mode 100644 index 0000000..0e41172 --- /dev/null +++ b/sch-pcb/devboard/vreg2.py @@ -0,0 +1,157 @@ +#!/usr/bin/env python + +from pylab import * +from scipy import optimize as opt + +from wag import engstr as es + +close('all') + +mpl.rcParams['backend'] = 'pdf' +mpl.rcParams['font.size'] = 8 +mpl.rcParams['font.style'] = 'Times New Roman' +mpl.rcParams['font.serif'] = 'Times New Roman' +#mpl.rcParams['text.usetex'] = True + + +def rvals(Vrange, Rpot): + Vmax = max(Vrange) + Vmin = min(Vrange) + x = Vmax/Vref - 1 + y = Vmin/Vref - 1 + print x, y + if y == 0.0: + R1 = 0.0 + R2 = Rpot/x + else: + R1 = Rpot / (x/y - 1) + R2 = R1/y + return [R1, R2] + +def vout(n, r1, r2, Rpot=1.0, Vref=0.5, Rshunt=None, Rtop=None): + ra = (n*Rpot+r1) + rb = (r2) + return Vref*(1 + ra/rb) + + + +def parallel(x,y): + return x*y/(x+y) + + + + + +# +# 1.2 nominal supply +# +if 1: + Rpot = 100e3 + Vref = 0.5 + Vmin = 0.5 + Vmax = 1.8 + Vini = Vmin + (Vmax-Vmin)/2 + #Vmax = 2*(Vini-Vref) + Vref + assert(Vmin >= Vref) + + r1, r2 = rvals([Vmin, Vmax], Rpot) + + print es(r1), es(r2) + + n = arange(0, 1, 1/256.0) + + def dolimits(): + yticks(arange(Vref, Vmax+1, 0.2)) + ylim([0.5, 2.0]) + xticks(arange(0, 1.1, 0.2)) + + #no shunt, calculated values + #figure() + figure(figsize=(6, 4)) + suptitle('1.2 V supply\n(Vout) -R1- (W) - (B/FB) - R2 - (GND)') + subplot(121) + plot(n, vout(n, r1, r2, Rpot, Vref)) + dolimits() + text(0.05, 1.91, 'R1=%s' % es(r1)) + text(0.05, 1.85, 'R2=%s' % es(r2)) + #title('r1=%s\nr2=%s' % (es(r1), es(r2))) + + subplot(122) + r1fix = r1 + r2fix = 38.3e3 + plot(n, vout(n, r1, r2fix, Rpot, Vref)) + plot(n, (Vmax-Vmin)*n+Vmin) + plot(0.5, 1.2, 'or') + plot(0.5, Vini, 'og') + dolimits() + xlabel('discretized') + text(0.05, 1.91, 'R1=%s' % es(r1fix)) + text(0.05, 1.85, 'R2=%s' % es(r2fix)) + + savefig('rdac-1v2-series.pdf') + + #fit a polynomial to the discretized function + vo = vout(n, r1, r2fix, Rpot, Vref) + p = np.polyfit(n, vo, 2) + print '2nd order polynomial fit to Vout vs n:' + print p + + + +# +# 2.5 nominal supply +# +if 1: + Rpot = 100e3 + Vref = 0.5 + Vmin = 1.9 + Vmax = 2.7 + Vini = Vmin + (Vmax-Vmin)/2 + #Vmax = 2*(Vini-Vref) + Vref + assert(Vmin >= Vref) + + r1, r2 = rvals([Vmin, Vmax], Rpot) + + print es(r1), es(r2) + + n = arange(0, 1, 1/256.0) + + def dolimits(): + yticks(arange(Vref, Vmax+1, 0.2)) + ylim([0.5, 3.0]) + xticks(arange(0, 1.1, 0.2)) + + #no shunt, calculated values + figure(figsize=(6, 4)) + suptitle('2.5 V supply\n(Vout) -R1- (W) - (B/FB) - R2 - (GND)') + subplot(121) + plot(n, vout(n, r1, r2, Rpot, Vref)) + dolimits() + xlabel('Calculated') + text(0.05, 2.81, 'R1=%s' % es(r1)) + text(0.05, 2.71, 'R2=%s' % es(r2)) + + subplot(122) + #r1fix = r1 + #r2fix = r2 + r1fix = 180e3 + r2fix = 62.0e3 + plot(n, vout(n, r1, r2fix, Rpot, Vref)) + plot(n, (Vmax-Vmin)*n+Vmin) + plot(0.5, 2.5, 'or') + plot(0.5, Vini, 'og') + dolimits() + xlabel('Quantized') + text(0.05, 2.81, 'R1=%s' % es(r1fix)) + text(0.05, 2.71, 'R2=%s' % es(r2fix)) + + savefig('rdac-2v5-series.pdf') + + #fit a polynomial to the discretized function + vo = vout(n, r1, r2fix, Rpot, Vref) + p = np.polyfit(n, vo, 2) + print '2nd order polynomial fit to Vout vs n:' + print p + + + -- 2.25.1