def run_simple(self, bias, gateLim, avg = 6.0, field = 0.0, runs = 1,
                   cvResistor = 1.0, cvAmp = 1.0, gateAmp = 9.1788, 
                   measDelay = 0.1, gateDelay = 1.0, nplc = 1, nvmRange = 0.1):
        
        """ This runs the actual experiment. It can be called independently of the
            run() function. """
        
        tools.write_log('fixBias_swpGate', locals(), self.filename+'.log')
        
        source = keithleypair.FixedBias("GPIB::22", timeout = 60.0) #keithley object
        daqGate = nidaqmx.AnalogOutputTask() #DAQ output object
        daqGate.create_voltage_channel('Dev1/ao0', min_val = -10.0, max_val = 10.0)
        
        gateBuffer = tools.get_buffer_size(gateLim[0], gateLim[1], gateLim[2])
        gates = np.linspace(gateLim[0], gateLim[1], gateBuffer)
        
        #setup 6220/2182A
        source.general_setup()
        source.bias_setup(bias/cvResistor)
        source.voltmeter_channel_setup(nplc, nvmRange)
        source.single_point_setup(avg, measDelay)
        
        #check that everything is setup
        print "current source state: ", source.source_chk_op_evnt_reg()
        print "voltmeter state:      ", source.voltmeter_chk_meas_evnt_reg()
        
        source.write(":outp 1")
        time.sleep(2.0)
        
        data = np.zeros(gateBuffer)

        for run in range(runs):
            end = False
            for i, gate in enumerate(gates):
                daqGate.write([gate/gateAmp])
                time.sleep(gateDelay)
                data[i] = source.get_meas()
                data[i] = data[i]*cvAmp
                np.savetxt(self.file, [[gate, data[i], run+1]], fmt = '%+.6e', delimiter = '\t')
                self.file.flush(); os.fsync(self.file)
                if msvcrt.kbhit():
                    if ord(msvcrt.getch()) == 113:
                        end = True
                        print "Program ended by user.\n"
                        break
            if end: break
            gates = gates.reshape(-1)[::-1]     #sweep in the other direction
            data.fill(0.0)
            
        print 'Cleaning up...'
        source.write(":outp 0") #turn off current source
        source.close()
        daqGate.write([0.0]) #turn off gate
        del daqGate, source #delete DAQ object so it can be reused
        self.file.close()
    def run(
        self,
        bias,
        points=100,
        gateDelay=0.75,
        cvResistor=10.0,
        cvAmp=-1e-7,
        gateAmp=1.0,
        nplc=1,
        nvmRange=1.0,
        filename="roomTemp_cntTest_{0:.0f}".format(time.time()),
    ):

        """ This runs the actual experiment. It can be called independently of the
            run() function. """

        tools.write_log("gateTest_vBias_", locals(), filename + ".log.txt")
        file = open(filename + ".dat.txt", "a")

        self.end_run = False
        self.start_run = False

        source = keithleypair.FixedBias("GPIB::22", timeout=60.0)  # keithley object

        self.data = np.zeros((points, 4))

        # setup 6220/2182A
        source.general_setup()
        source.bias_setup(bias / cvResistor, analogFilt=True)
        source.voltmeter_channel_setup(nplc, nvmRange, digital_filter=False)
        source.bus_trig_setup(points)

        # check that everything is setup
        print "current source state: ", source.source_chk_op_evnt_reg()
        print "voltmeter state:      ", source.voltmeter_chk_meas_evnt_reg()

        # ramp up bias voltage
        if bias < 0:
            c = -1.0
        else:
            c = 1.0
        for i in range(-9, 0):
            outp = c * 2 * math.pow(10, i)
            if abs(outp) > abs(bias):
                source.write(":sour:curr {0:.15f}".format(bias / cvResistor))
                time.sleep(1.0)
                break
            else:
                source.write(":sour:curr {0:.15f}".format(outp / cvResistor))
                if i == -9:
                    source.write("outp 1")
                time.sleep(1.0)

        print "wait for stable current..."
        time.sleep(5.0)

        # run experiment
        print "GO!"
        start_time = time.time()
        for i in range(points):
            time.sleep(gateDelay)
            source.write_serial("*TRG")
            self.data[i, 0] = time.time() - start_time
            if (msvcrt.kbhit() and ord(msvcrt.getch()) == 113) or self.end_run:
                print "Program ended by user."
                break

        self.data[:, 1] = source.read_2182A_buffer()
        self.data[:, 2] = self.data[:, 1] * cvAmp
        self.data[:, 3] = bias / self.data[:, 2]
        np.savetxt(file, self.data, fmt="%+.6e", delimiter="\t")

        # ramp down bias voltage
        print "Turning off bias..."
        for i in range(0, 10):
            outp = c * 2 * math.pow(10, -i)
            if abs(outp) > abs(bias):
                continue
            else:
                source.write(":sour:curr {0:.15f}".format(outp / cvResistor))
                time.sleep(1.0)

        source.write(":outp 0")  # turn off current source
        source.close()  # close gpib instrument
        del source  # delete DAQ object so it can be reused
        file.close()
        print "Done."

        fig = plt.figure()
        ax = fig.add_subplot(111)
        ax.grid(True)
        title_text = plt.title("bias = {0:+.2e}V".format(bias))
        line, = ax.plot(self.data[:, 0], self.data[:, 2], "r-o")
        plt.xlabel("time (s)")
        plt.ylabel("current (A)")
        plt.show()

        self.end_run = True
    def run_simple(
        self,
        bias,
        avg=1.0,
        field=0.0,
        cvResistor=10.0,
        cvAmp=-1e-7,
        gateAmp=1.0,
        measDelay=0.1,
        gateDelay=0.75,
        nplc=1,
        nvmRange=1.0,
        filename="roomTemp_cntTest_{0:.0f}".format(time.time()),
    ):

        """ This runs the actual experiment. It can be called independently of the
            run() function. """

        tools.write_log("gateTest_vBias_", locals(), filename + ".log.txt")
        file = open(filename + ".dat.txt", "a")

        self.end_run = False
        self.start_run = False

        source = keithleypair.FixedBias("GPIB::22", timeout=60.0)  # keithley object
        daqGate = nidaqmx.AnalogOutputTask()  # DAQ output object
        daqGate.create_voltage_channel("Dev1/ao1", min_val=-10.0, max_val=10.0)

        gat = np.arange(0, 10.25, 0.25)
        gates = np.append(gat, [gat[::-1], -gat, -gat[::-1]])
        self.data = np.zeros((len(gates), 3))

        # setup 6220/2182A
        source.general_setup()
        source.bias_setup(bias / cvResistor, analogFilt=False)
        source.voltmeter_channel_setup(nplc, nvmRange, digital_filter=False)
        source.single_point_setup(avg, measDelay)

        # check that everything is setup
        print "current source state: ", source.source_chk_op_evnt_reg()
        print "voltmeter state:      ", source.voltmeter_chk_meas_evnt_reg()

        # ramp up bias voltage
        if bias < 0:
            c = -1.0
        else:
            c = 1.0
        for i in range(-9, 0):
            outp = c * 2 * math.pow(10, i)
            if abs(outp) > abs(bias):
                source.write(":sour:curr {0:.15f}".format(bias / cvResistor))
                time.sleep(1.0)
                break
            else:
                source.write(":sour:curr {0:.15f}".format(outp / cvResistor))
                if i == -9:
                    source.write("outp 1")
                time.sleep(1.0)

        print "wait for stable current..."
        time.sleep(5.0)

        # run experiment
        exitGate = 0.0
        print "GO!"
        for i, gate in enumerate(gates):
            daqGate.write(gate / gateAmp)
            time.sleep(gateDelay)
            self.data[i, 0] = gate
            self.data[i, 1] = source.get_meas() * cvAmp
            self.data[i, 2] = bias / self.data[i, 1]
            np.savetxt(file, [self.data[i]], fmt="%+.6e", delimiter="\t")
            if (msvcrt.kbhit() and ord(msvcrt.getch()) == 113) or self.end_run:
                exitGate = gate
                print "Program ended by user."
                break
            if i == 2:
                self.start_run = True

        # ramp down bias voltage
        print "Turning off bias..."
        for i in range(0, 10):
            outp = c * 2 * math.pow(10, -i)
            if abs(outp) > abs(bias):
                continue
            else:
                source.write(":sour:curr {0:.15f}".format(outp / cvResistor))
                time.sleep(1.0)

        # ramp down back gate
        print "Turning off gate..."
        while True:
            if abs(exitGate) < 1.0:
                break
            if exitGate < 0:
                exitGate += 1.0
            else:
                exitGate -= 1.0
            if abs(exitGate) < 1.0:
                break
            else:
                daqGate.write(exitGate / gateAmp)
                time.sleep(0.5)

        source.write(":outp 0")  # turn off current source
        source.close()  # close gpib instrument
        daqGate.write(0.0)  # turn off gate, should already be at 0
        daqGate.clear()
        del daqGate, source  # delete DAQ object so it can be reused
        file.close()
        print "Done."
Ejemplo n.º 4
0
    def run_simple(self, bias, samples = 1.0, gateDelay = 0.75, field = 0.0, 
                   biasDivider = 1e-3, cvAmp = -1e-6, gateAmp = 9.1788, 
                   filename = 'DAQIO_gateTest_{0:.0f}'.format(time.time())):
        
        """ This runs the actual experiment. It can be called independently of the
            run() function. """
        
        tools.write_log('DAQIO_gateTest', locals(), filename+'.log.txt')
        file = open(filename+'.dat.txt','a')
        self.end_run = False
        
        #setup output channels
        bias_channel = 'Dev1/ao0'
        bias_out = nidaqmx.AnalogOutputTask()
        bias_out.create_voltage_channel(bias_channel, min_val = -10.0, max_val = 10.0)
        
        gate_channel = 'Dev1/ao1'
        gate_out = nidaqmx.AnalogOutputTask()
        gate_out.create_voltage_channel(gate_channel, min_val = -10.0, max_val = 10.0)
        
        gat = np.arange(0,10.1,0.1)
        gates = np.append(gat, [gat[::-1], -gat, -gat[::-1]])
        self.data = np.zeros((len(gates), samples+3))
        sample_data = np.zeros((samples,1))
        
        #setup input channel
        input_channel = 'Dev1/ai0' #if using differential mode this should be the high side
        sample_rate = 5000
        itask = nidaqmx.AnalogInputTask()
        itask.create_voltage_channel(input_channel, terminal = 'diff', min_val = -10.0, max_val = 10.0)
        itask.configure_timing_sample_clock(rate = sample_rate, samples_per_channel = samples, 
                                            sample_mode = 'finite')
        itask.alter_state('commit')
        
        print 'bias turning on...'
        bias_out.write(bias/biasDivider)
        time.sleep(10.0)

        #run experiment
        exitGate = 0.0
        print 'GO!'
        for i, gate in enumerate(gates):
            itask.start()
            gate_out.write(gate/gateAmp)
            time.sleep(gateDelay)
            sample_data = itask.read()
            itask.wait_until_done()
            itask.stop()
            self.data[i,0] = gate
            self.data[i,1] = sample_data.mean()*cvAmp
            self.data[i,2] = bias/self.data[i,1]
            self.data[i,3:] = sample_data.transpose()
            np.savetxt(file, [self.data[i]], fmt = '%+.6e', delimiter = '\t')
            if (msvcrt.kbhit() and ord(msvcrt.getch()) == 113) or self.end_run:
                    exitGate = gate
                    print "Program ended by user."
                    break
                
        bias_out.write(0.0)
        bias_out.clear()
        gate_out.write(0.0) #turn off gate, should already be at 0
        gate_out.clear()
        del gate_out, bias_out #delete DAQ object so it can be reused
        file.close()
        print 'Done.'