Linear vreg tuning law, use this one
authorDan White <dan@whiteaudio.com>
Mon, 30 Jan 2012 19:27:58 +0000 (13:27 -0600)
committerDan White <dan@whiteaudio.com>
Mon, 30 Jan 2012 19:27:58 +0000 (13:27 -0600)
sch-pcb/devboard/vreg2.py [new file with mode: 0644]

diff --git a/sch-pcb/devboard/vreg2.py b/sch-pcb/devboard/vreg2.py
new file mode 100644 (file)
index 0000000..0e41172
--- /dev/null
@@ -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
+
+
+