Beispiel #1
0
def mag(value):

    # Check if SciPy is loaded
    slab.checkSciPy()

    ma = np.absolute(value)
    return ma
Beispiel #2
0
def transferCurveII(v1,v2,vi=0.1,r1=1.0,r2=1.0,wt=0.1,returnData=False):

    # Check if SciPy is loaded
    slab.checkSciPy()

    # Perform a DC Sweep
    x,y1,y2,y3,y4 = slab.dcSweep(1,v1,v2,vi,wt)
    # Set DAC to zero
    slab.writeChannel(1,0.0)  
    # Calculate current
    cin  = (x-y1) / r1
    cout = (slab.vdd - y2) / r2
    # Show curve
    slab.message(1,"Drawing curve")
    plt.figure(facecolor="white")   # White border
    pl.plot(cin,cout)
    pl.xlabel("Input (mA)")
    pl.ylabel("Output (mA)")
    pl.title("DC I(I) Transfer Curve")
    pl.grid()
    pl.show()   
    pl.close()
    
    if slab.plotReturnData or returnData:
        return cin,cout 
Beispiel #3
0
def phase(value):

    # Check if SciPy is loaded
    slab.checkSciPy()

    ph = np.angle(value, deg=True)
    return ph
Beispiel #4
0
def iDeviceCurve(vi1,vi2,vii,vo1,vo2,voi=0.1,ri=1.0,ro=1.0,wt=0.1):

    # Check if SciPy is loaded
    slab.checkSciPy()

    i_range=np.arange(vi1,vi2,vii)
    o_range=np.arange(vo1,vo2,voi)
    plt.figure(facecolor="white")   # White border
    for vi in i_range:
        avo = []
        aio = []
        slab.setVoltage(2,vi)
        slab.wait(wt)
        a0 = slab.readVoltage(1)
        i_in = (vi - a0) / ri
        for vs in o_range:
            slab.setVoltage(1,vs)
            slab.wait(wt)
            a1 = slab.readVoltage(2)
            a2 = slab.readVoltage(3)
            curr = (a1 - a2) / ro
            avo.append(a2)
            aio.append(curr)
        lbl = "{:.6f}".format(i_in) + ' mA'    
        pl.plot(avo,aio,label=lbl)   
    slab.message(1,"Drawing curves")
    pl.legend(loc='upper right')         
    pl.title("Io(Vo) Device Curves as function of Ii")
    pl.xlabel("Output Voltage(V)")
    pl.ylabel("Output Current(mA)")   
    pl.grid()    
    pl.show()   
    pl.close()    
Beispiel #5
0
def magPhase(value):

    # Check if SciPy is loaded
    slab.checkSciPy()

    ma = np.absolute(value)
    ph = np.angle(value, deg=True)
    return ma, ph
Beispiel #6
0
def logRange(start, end=0, ndec=0, ppd=10):
    # Check if SciPy is loaded
    slab.checkSciPy()

    stlog = np.log10(start)
    # We don't provide end
    if end == 0:
        if ndec == 0:
            raise slab.SlabEx('Need to provide end or decades')
        return 10**np.arange(stlog, stlog + ndec, 1.0 / ppd)
    # We provide end
    endlog = np.log10(end)
    return 10**np.arange(stlog, endlog, 1.0 / ppd)
Beispiel #7
0
def plotVI(x,y,r,title="V-I Plot",xl="Voltage(V)",yl="Current (mA)"):
    curr = (x-y)/r
    
    # Check if SciPy is loaded
    slab.checkSciPy()  
    
    plt.figure(facecolor="white")   # White border
    pl.plot(y,curr)
    pl.xlabel(xl)
    pl.ylabel(yl)
    pl.title(title)
    pl.grid()
    pl.show()    
    pl.close()
Beispiel #8
0
def plotFreq(f, v, labels=[]):

    # Check if SciPy is loaded
    slab.checkSciPy()

    # Draw plot
    plt.figure(facecolor="white")  # White border

    # Magnitude
    ax1 = pl.subplot(2, 1, 1)
    if isinstance(f[0], numbers.Number):
        pl.plot(f, np.absolute(v))
    else:
        if labels == []:
            for fv, gv in zip(f, v):
                pl.plot(fv, np.absolute(gv))
        else:
            for fv, gv, lab in zip(f, g, labels):
                pl.plot(fv, np.absolute(gv), label=lab)

    pl.xlabel('Frequency (Hz)')  # Set X label
    pl.ylabel('Magnitude')  # Set Y label
    pl.title('Frequency plot')  # Set title

    if labels != []:
        pl.legend(loc='best')
    pl.grid(True)

    # Phase
    ax2 = pl.subplot(2, 1, 2, sharex=ax1)
    if isinstance(f[0], numbers.Number):
        pl.plot(f, np.angle(v, deg=True))
    else:
        if labels == []:
            for fv, gv in zip(f, v):
                pl.plot(fv, np.angle(gv, deg=True))
        else:
            for fv, gv, lab in zip(f, v, labels):
                pl.plot(fv, np.angle(gv, deg=True), label=lab)

    pl.xlabel('Frequency (Hz)')  # Set X label
    pl.ylabel('Phase (deg)')  # Set Y label
    if labels != []:
        pl.legend(loc='best')
    pl.grid(True)

    pl.show()
    pl.close()
Beispiel #9
0
def curveVI(v1,v2,vi=0.1,r=1.0,wt=0.1,returnData=False):

    # Check if SciPy is loaded
    slab.checkSciPy() 

    # Perform a DC sweep
    x,y1,y2,y3,y4 = slab.dcSweep(1,v1,v2,vi,wt)
    # Set DAC 1 to zero
    slab.writeChannel(1,0.0)
    # Plot result
    slab.message(1,"Drawing curve")
    vd = y2
    id = (y1 - y2) / r
    slab.plot11(vd,id,"V-I plot","Voltage (V)","Current (mA)")     
    
    if slab.plotReturnData or returnData:
        return vd,id
Beispiel #10
0
def curveVV(v1,v2,vi=0.1,wt=0.1,adc2=False,returnData=False):

    # Check if SciPy is loaded
    slab.checkSciPy() 

    # Perform a DC sweep
    x,y1,y2,y3,y4 = slab.dcSweep(1,v1,v2,vi,wt)
    
    # Check ADC2 option
    if adc2:
        x = y2
    
    # Plot result
    slab.message(1,"Drawing curve")
    slab.plot11(x,y1,"V(V) Plot","Input (V)","Output(V)")
    
    if slab.plotReturnData or returnData:
        return x,y1
Beispiel #11
0
def curveVIbridge(v1max,v2max,vi=0.1,vmin=0.0,r=1.0,wt=0.1,returnData=False):

    # Check if SciPy is loaded
    slab.checkSciPy() 

    # Perform first DC sweep
    slab.message(1,"Positive curve")
    slab.setVoltage(2,vmin)                                 # Set DAC 2 to vmin
    xf,y1f,y2f,y3f,y4f = slab.dcSweep(1,vmin,v1max,vi,wt)   # Sweep DAC 1

    # Perform second DC sweep
    slab.message(1,"Negative curve")
    slab.setVoltage(1,vmin)                                 # Set DAC 1 to vmin
    xr,y1r,y2r,y3r,y4r = slab.dcSweep(2,vmin,v2max,vi,wt)   # Sweep DAC 2
    
    # Set DACs to vmin
    slab.setVoltage(1,vmin)
    slab.setVoltage(2,vmin)
    
    # Join the curves
    vd=[]
    id=[]
    lenr=len(xr)
    for i in range(0,lenr):
        pos = lenr - i - 1
        vd.append(y2r[pos]-y3r[pos])
        id.append((y1r[pos]-y2r[pos])/r)
    for i in range(0,len(xf)):
        vd.append(y2f[i]-y3f[i])
        id.append((y1f[i]-y2f[i])/r)
    
    plt.figure(facecolor="white")   # White border
    pl.plot(vd,id)      
    pl.xlabel("Voltage (V)")
    pl.ylabel("Current (mA)")
    pl.title("V-I plot in bridge mode")
    pl.grid()
    pl.show() 
    pl.close()
    
    if slab.plotReturnData or returnData:
        return vd,id        
Beispiel #12
0
def curveVVbridge(vp,vn,vi=0.1,vmin=0.0,wt=0.1,returnData=False):

    # Check if SciPy is loaded
    slab.checkSciPy() 

    # Perform the positive DC sweep
    slab.message(1,"Positive curve")
    slab.setVoltage(2,vmin)
    xp,y1p,y2p,y3p,y4p = slab.dcSweep(1,vmin,vp,vi,wt)
    # Perform the negative DC sweep
    slab.message(1,"Negative curve")
    slab.setVoltage(1,vmin)
    xn,y1n,y2n,y3n,y4n = slab.dcSweep(2,vmin,vn,vi,wt)
    
    # Join all measurements
    x=[]
    y=[]
    
    ln = len(xn)
    for i in range(0,ln):
        pos = ln-i-1
        xvalue = y1n[pos]-y2n[pos]
        yvalue = y3n[pos]-y4n[pos]
        x.append(xvalue)
        y.append(yvalue)
        
    lp = len(xp)    
    for i in range(0,lp):
        xvalue = y1p[i]-y2p[i]
        yvalue = y3p[i]-y4p[i]
        x.append(xvalue)
        y.append(yvalue) 
        
    x = np.array(x)
    y = np.array(y)    
    
    # Plot result
    slab.message(1,"Drawing curve")
    slab.plot11(x,y,"V(V) Bridge Plot","Input (V)","Output (V)")
    
    if slab.plotReturnData or returnData:
        return x,y 
Beispiel #13
0
def curveVIref(v1,v2,vi=0.1,r=1.0,vr=-1,wt=0.1,returnData=False):

    # Check if SciPy is loaded
    slab.checkSciPy() 

    # Perform a DC sweep
    x,y1,y2,y3,y4 = slab.dcSweep(1,v1,v2,vi,wt)
    # Set DAC 1 to Vdd/2
    slab.setVoltage(1,slab.vdd/2)
    # Plot result
    req =  r / 2
    if vr < 0:
        vr = slab.vdd / 2
    vd = y1 - y2
    id = (y2 - vr)/req
    slab.message(1,"Drawing curve")
    slab.plot11(vd,id,"V-I plot with reference","Voltage (V)","Current (mA)") 
    
    if slab.plotReturnData or returnData:
        return vd,id
Beispiel #14
0
def curveVVref(v1,v2,vi=0.1,wt=0.1,adc3=False,returnData=False):

    # Check if SciPy is loaded
    slab.checkSciPy()

    # Perform a DC sweep
    x,y1,y2,y3,y4 = slab.dcSweep(1,v1,v2,vi,wt)
    
    # Check ADC3 option
    if adc3:
        x = y3
    
    # Plot result
    slab.message(1,"Drawing curve")
    vi = x - y2
    vo = y1 - y2
    slab.plot11(vi,vo,"V(V) Plot with reference","Input (V)","Output(V)") 
    
    if slab.plotReturnData or returnData:
        return vi,vo
Beispiel #15
0
def bodeResponse(v1,
                 v2,
                 fmin,
                 fmax,
                 ppd=10,
                 channel=1,
                 npre=5,
                 maxfs=-1,
                 returnData=False):

    # Check if SciPy is loaded
    slab.checkSciPy()

    fvector = logRange(fmin, fmax, ppd=ppd)
    gvector = freqResponse(v1, v2, fvector, channel, npre, maxfs)

    # Remove the trim of phase data
    #_plotBodeTrimmed(fvector,gvector)
    plotBode(fvector, gvector)
    if slab.plotReturnData or returnData:
        return fvector, gvector
Beispiel #16
0
def curveVIbridgeOld(v1max,v2max,vi=0.1,r=1.0,wt=0.1,returnData=False):

    # Check if SciPy is loaded
    slab.checkSciPy() 

    # Perform first DC sweep
    slab.message(1,"Forward curve")
    slab.setVoltage(2,0.0)                            # Set DAC 2 to 0.0
    x,y1,y2,y3,y4 = slab.dcSweep(1,0.0,v1max,vi,wt)   # Sweep DAC 1

    # First plot
    vd = y2 - y3
    id = (y1 - y2)/r
    plt.figure(facecolor="white")   # White border
    pl.plot(vd,id)

    # Perform second DC sweep
    slab.message(1,"Backward curve")
    slab.setVoltage(1,0.0)                            # Set DAC 1 to 0.0
    x,y1,y2,y3,y4 = slab.dcSweep(2,0.0,v2max,vi,wt)   # Sweep DAC 2
    
    # Set DACs to zero
    slab.writeChannel(1,0.0)
    slab.writeChannel(2,0.0)
    
    # Second plot
    slab.message(1,"Drawing curve")
    vd = y2 - y3
    id = (y1 - y2)/r
    pl.plot(vd,id)
    
    pl.xlabel("Voltage (V)")
    pl.ylabel("Current (mA)")
    pl.title("V-I plot in bridge mode")
    pl.grid()
    pl.show() 
    pl.close()
    
    if slab.plotReturnData or returnData:
        return vd,id
Beispiel #17
0
def hystVVcurve(v1,v2,vi=0.1,wt=0.1,returnData=False):

    # Check if SciPy is loaded
    slab.checkSciPy()

    # Perform DC sweeps
    xf,y1f,y2f,y3f,y4f = slab.dcSweep(1,v1,v2,vi,wt)
    xr,y1r,y2r,y3r,y4r = slab.dcSweep(1,v2,v1,-vi,wt)
    # Plot result
    slab.message(1,"Drawing curves")
    plt.figure(facecolor="white")     # White border
    pl.plot(xf,y1f,label="Forward");
    pl.plot(xr,y1r,label="Back");
    pl.legend(loc='lower right')         
    pl.title("V(V) Hysteresis Curve")
    pl.xlabel("Input Voltage(V)")
    pl.ylabel("Output Voltage(V)")   
    pl.grid()    
    pl.show()   
    pl.close()

    if slab.plotReturnData or returnData:
        return xf,y1f,xr,y1r   
Beispiel #18
0
def sineGainAll(v1, v2, freq, npre=5, maxfs=-1):
    #global adc_delay

    # Check if SciPy is loaded
    slab.checkSciPy()

    # No sat warning yet
    satWarn = False

    # Load defaults
    if maxfs == -1:
        maxfs = slab.maxSFfresponse
    # Checks
    if not slab.opened:
        raise slab.SlabEx("Not connected to board")
    if v1 > v2:
        raise slab.SlabEx("Minimum value must be below maximum value")
    if maxfs > 1 / slab.min_sample:
        raise slab.SlabEx("Too high max sample frequency")
    if freq > maxfs / 4.0:
        raise slab.SlabEx("Frequency too high")

    # This command is silent
    prev_verbose = slab.setVerbose(0)

    # Create wave
    if maxfs > 200 * freq:
        npoints = 200
        nsamples = 200
    else:
        npoints = int(maxfs / freq)
        nsamples = int(200 / npoints) * npoints
        npre = int(npre * npoints / nsamples)

    # Create test wave
    amplitude = (v2 - v1) / 2.0
    slab.waveSine(v1, v2, npoints)
    st = slab.setWaveFrequency(freq)

    # Setup measurement
    slab.setTransientStorage(nsamples, 1)

    # Measure all channels
    list = []
    for channel in range(1, nadcs + 1):
        time, out = slab.singleWaveResponse(channel, npre, tinit=0.0)

        # Check peak values
        vmax = slab.highPeak(out)
        vmin = slab.lowPeak(out)
        if (vmax / slab.vref) > SAT_HIGH or (vmin / slab.vref) < SAT_LOW:
            satWarn = True

        # Find best fit
        angles = np.array(range(0, nsamples)) * 2.0 * np.pi / npoints
        # Initial guess
        mean0 = np.mean(out)
        amp0 = (vmax - vmin) / 2.0
        phase0 = 0
        # Function to optimize
        optimize_func = lambda x: x[0] * np.sin(angles + x[1]) + x[2] - out
        # Perform optimization
        amp, phase, mean = leastsq(optimize_func, [amp0, phase0, mean0])[0]

        # Warn if needed
        if satWarn:
            slab.warn("Saturated reading at ADC " + str(channel))

        # Gain to reported
        gain = amp * np.cos(phase) / amplitude + 1j * amp * np.sin(
            phase) / amplitude

        # Add to list
        list.append(gain)

    # Restore verbose level
    slab.setVerbose(prev_verbose)

    # Return the list
    return list
Beispiel #19
0
def dB(value):

    # Check if SciPy is loaded
    slab.checkSciPy()

    return 20 * np.log10(value)