Exemple #1
0
    def _pulserSetup(self, steps, forward=True, only=False):
        p = self.pulser.packet()
        p.enable(self.chMap.values(), only)

        #advance channnel
        p.select_channel(self.chMap['Adv'])
        p.width(U.Value(10, 'us'))
        p.delay(U.Value(10, 'us'))
        p.polarity(True)
        p.mode('Normal')
        p.output(False)

        #direction channel
        p.select_channel(self.chMap['Dir'])
        p.width(U.Value(1, 'ms'))
        p.delay(U.Value(0, 's'))
        p.polarity(forward)
        p.mode('Normal')
        p.output(False)

        #trigger burst with step count
        p.select_channel(0)
        p.mode('Burst', steps)

        yield p.send()
Exemple #2
0
 def _prepPulser(self):
     p = self.pulser.packet()
     
     #start channel settings
     p.select_channel(self.chMap['Start'])
     p.state(True)
     p.width(U.Value(10, 'us'))
     p.delay(U.Value(0, 's'))
     p.polarity(True)
     p.output(False)
     p.mode('Single')
      
     #mcs advance settings
     p.select_channel(self.chMap['MCSAdv'])
     p.state(True)
     p.width(U.Value(10, 'us'))
     p.delay(U.Value(0, 's'))
     p.polarity(True)
     p.output(False)
     p.mode('DutyCycle', ratio2dutycycle(self.ratio))
     
     #convert dwell time/MCS channel to dwell per advance
     dwell = self.params['Dwell Time'] * ADV_PER_CH / self.params['MCS Ratio']
     
     #configure global pulse settings
     p.select_channel(0)
     p.trigger_period(dwell)
     p.mode('Burst', self._scanSteps())
      
     yield p.send()  
Exemple #3
0
 def _prepMCS(self):
     p = self.mcs.packet()
     p.sweeps(self.params['Passes'])
     p.pass_length(self.params['Pass Length'])
     p.acquisition_mode('RepSum')
     p.discriminator_edge('Rising')
     p.discriminator_level(U.Value(1.0, 'V'))
     p.input_impedance(U.Value(50, 'Ohm'))
     p.voltage_ramp([U.Value(0.0, 'V')])
     p.dwell(U.Value(1.0, 'V'))
     p.external_trigger(False)
     yield p.send() 
def move(pulser, advs, dwell=U.Value(50, 'ms'), moveChsOnly=False):
    setMove(pulser, advs, dwell, moveChsOnly)
    print 'Setting move with {0} {1}'.format(advs, dwell)
    pulser.start()
    print 'Pulser started'
    while pulser.run_state():
        sleep(dwell['s'] / 2)
def str2ramp(string):
    elems = string.split(' ')
    N = int(elems[0])
    include = [1, 3] if N == 2 else [1, 2, 3]
    fn = lambda x: U.Value(float(elems[x]), 'V')
    ramp = tuple([fn(x) for x in include])
    return ramp
    def test_output_query_adjustable(self, dev):
        dev.query.side_effect = ['ADJ', '2.0000']
        resp = yield dev.output(1)

        dev.query.assert_any_call(':PULSE1:OUTPUT:MODE?')
        dev.query.assert_any_call(':PULSE1:OUTPUT:AMPL?')
        assert resp == (True, U.Value(2.0, 'V'))
Exemple #7
0
    def test_move_now_sets_trigger_and_starts(self, srv, pls, mocker):
        DWELL = U.Value(1, 's')

        srv.dwell = DWELL
        yield srv._moveSetup(10, True, True)

        pls.packet().trigger_period.assert_called_with(DWELL)
        pls.packet().start.assert_called_with()
Exemple #8
0
    def _pulserChannelInitialSetup(self):
        p = self.pulser.packet()

        #adv channel
        p.select_channel(self.chs['Advance'])
        p.width(U.Value(1, 'ms'))
        p.delay(U.Value(0, 's'))
        p.polarity(True)
        p.output(False)
        p.mode('Normal')

        #direction channel
        p.select_channel(self.chs['Direction'])
        p.width(U.Value(1, 'ms'))
        p.delay(U.Value(0, 's'))
        p.mode('Normal')
        p.output(False)

        yield p.send()
Exemple #9
0
 def testArithmetic(self):
     m = units.Unit('m')
     kg = units.Unit('kg')
     
     self.assertEquals(units.Value(5.0, None)*m, 5.0*m)
     
     # addition
     self.assertEquals(1.0*kg + 0.0, 1.0*kg)
     
     self.assertNotEquals(1.0*kg, None)
Exemple #10
0
 def query(self, line):
     yield self._portLock.acquire()
     p = self.server.packet()
     resp = yield p.read()\
                   .write_line(line)\
                   .pause(U.Value(40.0, 'ms'))\
                   .read_line()\
                   .send()
     print 'RESPONSE: %s' % resp['read_line']
     returnValue(resp['read_line'])
    def _setupScan(self):
        start = int(self.ui.startInput.text)
        stop = int(self.ui.stopInput.text)
        dwell = float(self.ui.dwellInput.text)
        cPerBin = float(self.ui.binInput.text)

        self.scanner.packet()\
            .scan_range(start, stop)\
            .dwell(U.Value(dwell, 's'))\
            .channels_per_bin(cPerBin)\
            .send()
Exemple #12
0
def initializePulser(pulser, don, doff):
    p = pulser.packet()
    
    #TODO: Change to dynamic name
    p.select_device(0)
    
    p.select_channel(CH_MAP['MCS Start'])
    p.state(False)
    p.width(U.Value(10, 'us'))
    p.delay(U.Value(0.0, 's'))
    p.mode('Single')
    p.polarity(True)
    p.output(True, U.Value(2.0, 'V'))
    
    p.select_channel(CH_MAP['MCS Advance'])
    p.state(True)
    p.width(U.Value(10, 'us'))
    p.delay(U.Value(0, 'us'))
    p.mode('DutyCycle', (don, doff))
    p.polarity(True)
    p.output(True, U.Value(2.0, 'V'))
    
    p.select_channel(CH_MAP['Stepper Advance'])
    p.state(True)
    p.width(U.Value(10, 'us'))
    p.delay(U.Value(10, 'us'))
    p.mode('Normal')
    p.polarity(True)
    p.output(False)
    
    p.select_channel(CH_MAP['Stepper Direction'])
    p.state(True)
    p.width(U.Value(1, 'ms'))
    p.delay(U.Value(0.0, 's'))
    p.mode('Normal')
    p.polarity(True)
    p.output(False)
    
    p.send()
    print 'Channels initialized'
    print p
def test_external_dwell_threshold(srv, voltage, good):
    value = U.Value(voltage, 'V')

    if good:
        string, respVal = srv.dwell(None, value)

        assert respVal == value
        assert srv.params['Dwell'] == (False, value)
        assert string == 'External'
    else:
        with pytest.raises(Error):
            srv.dwell(None, value)
def test_internal_dwell_time(srv, time, good):
    value = U.Value(time, 's')

    if good:
        string, respVal = srv.dwell(None, value)

        assert respVal == value
        assert srv.params['Dwell'] == (True, value)
        assert string == 'Internal'
    else:
        with pytest.raises(Error):
            srv.dwell(None, value)
Exemple #15
0
    def all_ch_states(self):
        chns = self.chMap.keys()
        p = self.server.packet()
        p.read()  #clear buffer
        for n in chns:
            p.write(':PULSE%d:STATE?' % n)
            p.pause(U.Value(30, 'ms'))
            p.read(key=str(n))
        resp = yield p.send()

        parser = TYPE_MAP['bool'][1]
        returnValue([(n, parser(resp[str(n)])) for n in chns])
Exemple #16
0
    def output(self, ch, isAdjustable=None, adjVoltage=None):
        adjText = 'Adjustable' if isAdjustable else 'TTL'
        adj = yield self._setParam(':OUTPUT:MODE', adjText, 'output', ch)

        if adj is not None:
            isAdj = adj == 'Adjustable'
            if isAdj:
                volts = yield self._setParam(':OUTPUT:AMPL', adjVoltage,
                                             'voltage', ch)
            else:
                volts = U.Value(0.0, 'V')

            returnValue((isAdj, volts))
Exemple #17
0
    def _initializeChannels(self):
        p = self.pulser.packet()

        #step advance channel
        p.select_channel(self.chMap['Adv'])
        p.state(True)
        p.width(U.Value(10, 'us'))
        p.delay(U.Value(10, 'us'))
        p.mode('Normal')
        p.polarity(True)
        p.output(False)

        #direction channel
        p.select_channel(self.chMap['Dir'])
        p.state(True)
        p.width(U.Value(1, 'ms'))
        p.delay(U.Value(0.0, 's'))
        p.mode('Normal')
        p.polarity(True)
        p.output(False)

        yield p.send()
Exemple #18
0
def srv():
    server = ScanServer()
    server.pulser = mock.Mock()
    server.stepper = mock.Mock()

    #config settings
    server.chMap = {'Start': 1, 'MCSAdv': 2}
    server.ratio = 1.0
    server.sRange = ((10, 0), (100, 0))
    server.dwell = U.Value(1.0, 's')
    server.passes = 2
    server._running = False

    return server
    def query(self, line):
        yield self._portLock.acquire()
        p = self.server.packet()
        ret = yield p.write_line(line)\
                     .pause(U.Value(20.0, 'ms'))\
                     .read()\
                     .send()

        text = ret['read']
        while not self._queryGood(text, line):
            add = yield self.server.read()
            text = text + add

        self._portLock.release()
        returnValue(text.split('\r\n')[-2])
Exemple #20
0
    def readParameters(self):
        #duty cycle
        ratio = float(self.ui.chPerBin.text())
        chs = int(ratio * 8)
        self.dcyc = (1, chs - 1)

        #dwell time
        dwell = float(self.ui.dwellTime.text())
        self.dwell = U.Value(dwell, 's')

        #pulse advances
        self.advs = int(self.ui.channels.text()) * 8

        #sweeps
        self.sweeps = int(self.ui.passes.text())
def setMove(pulser, advs, period=U.Value(50, 'ms'), moveChsOnly=False):
    p = pulser.packet()

    #set move direction
    p.select_channel(CH_MAP['Stepper Direction'])
    p.polarity(advs > 0)

    if moveChsOnly:
        chns = [CH_MAP[c] for c in ['Stepper Advance', 'Stepper Direction']]
        p.enable(chns, True)

    #advances
    p.select_channel(0)
    p.mode('Burst', abs(advs))
    p.trigger_period(period)
    p.send()
    def set_move(self, settings=None):
        run = self.config if settings is None else settings
        pulses = self.config2pulse(run)

        p = self.pulser.packet()

        #configure master trigger settings
        p.select_channel(0)
        p.mode('Burst', abs(run.channels))
        p.trigger_period(U.Value(run.dwellTime, 's'))

        #set individual pulse channels
        for data in pulses.itervalues():
            self.write_packet_data(p, data)

        p.send()
    def writeScanInfo(self):
        startCh = int(self.ui.startChannelInput.text())
        startFrac = int(self.ui.startFractionInput.text())

        stopCh = int(self.ui.stopChannelInput.text())
        stopFrac = int(self.ui.stopFractionInput.text())

        dwell = float(self.ui.dwellTimeInput.text())
        passes = int(self.ui.passInput.text())
        ratio = float(self.ui.mcsBinInput.text())

        p = self.scanner.packet()
        p.scan_range(startCh, startFrac, stopCh, stopFrac)
        p.dwell_time(U.Value(dwell, 's'))
        p.passes(passes)
        p.mcs_ratio(ratio)
        p.send()
def setMove(pulser, advs, period=U.Value(50, 'ms'), moveChsOnly=False):
    p = pulser.packet()

    #set move direction
    p.select_channel(CH_MAP['Stepper Direction'])
    p.polarity(advs > 0)

    if moveChsOnly:
        moveChs = [CH_MAP[x] for x in MOVE_CHS]
        p.enable(moveChs, True)
        print 'Enabling only channels {0}'.format(moveChs)

    #advances
    p.select_channel(0)
    p.mode('Burst', abs(advs) + 8)
    p.trigger_period(period)

    #now set stepper channel to move only advs number of channels
    p.select_channel(CH_MAP['Stepper Advance'])
    p.mode('Burst', abs(advs))
    p.send()
Exemple #25
0
 def input_impedance(self, c, imped=None):
     '''Set/query input signal impedance
     
     None : Query current setting
     True : Input at 50 Ohm impedance
     False : Input at 1 kOhm impedance
     Value can also be actual impedance value
     
     Returns : Impedance value
     '''
     if imped is not None:
         if type(imped) is bool:
             val = imped
         else:
             if imped['Ohm'] not in [50, 1000]:
                 raise Error('Impedance must be 50, 1000 Ohms or boolean')
             else:
                 val = imped['Ohm'] == 50
         
         self.params['Impedance'] = val
         
     return U.Value(50 if self.params['Impedance'] else 1000, 'Ohm')
 def test_bad_dwell_time_raises(self, srv, dwell):
     time = U.Value(dwell, 's')
     with pytest.raises(Error):
         yield srv.dwell_time(None, time)
def settings_setup(srv):
    srv.dwell = U.Value(1, 's')
    srv.ratio = 1.0
#    pulser.trigger_period(U.Value(0.5, 's'))
#    pulser.start()


def move(pulser, advs, dwell=U.Value(50, 'ms'), moveChsOnly=False):
    setMove(pulser, advs, dwell)
    print 'Move set with {0}, {1}, {2}'.format(pulser, advs, dwell)
    pulser.start()
    while pulser.run_state():
        sleep(dwell['s'] / 2)


def scanPass(pulser, advs, dwell):

    #start with all channels enabled
    pulser.enable(CH_MAP.values())
    #run pass
    move(pulser, advs, dwell)

    move(pulser, -(advs + 8), moveChsOnly=True)
    move(pulser, 8, moveChsOnly=True)


if __name__ == '__main__':
    cxn = labrad.connect()
    pulser = cxn['BNC Serial Server']
    pulser.select_device(0)

    for i in range(2):
        scanPass(pulser, 20, U.Value(0.25, 's'))
def move(pulser, advs, dwell=U.Value(50, 'ms'), moveChsOnly=False):
    setMove(pulser, advs, dwell)
    print 'Move set with {0}, {1}, {2}'.format(pulser, advs, dwell)
    pulser.start()
    while pulser.run_state():
        sleep(dwell['s'] / 2)
Exemple #30
0
def main():

    # Loads config
    with open("config.yml", 'r') as ymlfile:
        cfg = yaml.load(ymlfile)

    measurement = cfg['measurement']
    measurement_settings = cfg[measurement]
    max_values = cfg['max_values']

    ## DacAdc settings

    dacadc_settings = cfg['dacadc_settings']
    timeout = dacadc_settings['timeout']
    dac1_ch = dacadc_settings['dac1_ch']
    dac2_ch = dacadc_settings['dac2_ch']
    adc1_ch = dacadc_settings['adc1_ch']
    adc2_ch = dacadc_settings['adc2_ch']
    delay_unit = dacadc_settings['delay_unit']
    t_factor = time_factor(delay_unit)

    # Meas parameters
    meas_parameters = cfg['meas_parameters']
    delay_meas = meas_parameters['delay']

    # Ramp settings to first point
    vgate2start_pnts = abs(
        int(meas_parameters['vgate_rng'][0] / max_values['vgate_step_size']))
    if vgate2start_pnts < 2: vgate2start_pnts = 3
    vgate2start_delay = abs(
        int(meas_parameters['vgate_rng'][0] /
            (vgate2start_pnts * max_values['vgate_rate']) * 1e6))
    if vgate2start_delay < 1: vgate2start_delay = 10

    vset2start_pnts = abs(
        int(meas_parameters['vset_rng'][0] / max_values['vset_step_size']))
    if vset2start_pnts < 2: vset2start_pnts = 3
    vset2start_delay = abs(
        int(meas_parameters['vset_rng'][0] /
            (vset2start_pnts * max_values['vset_rate']) * 1e6))
    if vset2start_delay < 1: vset2start_delay = 10

    # Ramp settings to next line
    # Vgate ramps back whole range
    vgate2next_pnts = abs(
        int((meas_parameters['vgate_rng'][1] - meas_parameters['vgate_rng'][0])
            / max_values['vgate_step_size']))
    if vgate2next_pnts < 2: vgate2next_pnts = 3
    vgate2next_delay = abs(
        int((meas_parameters['vgate_rng'][1] - meas_parameters['vgate_rng'][0])
            / (vgate2next_pnts * max_values['vgate_rate']) * 1e6))
    if vgate2next_delay < 1: vset2next_delay = 10

    # Vset ramps up to next line
    vset2next_pnts = abs(
        int((meas_parameters['vset_rng'][1] - meas_parameters['vset_rng'][0]) /
            meas_parameters['vset_pnts'] / max_values['vset_step_size']))
    if vset2next_pnts < 2: vset2next_pnts = 3
    vset2next_delay = abs(
        int((meas_parameters['vset_rng'][1] - meas_parameters['vset_rng'][0]) /
            meas_parameters['vset_pnts'] /
            (vset2next_pnts * max_values['vset_rate']) * 1e6))
    if vset2next_delay < 1: vset2next_delay = 10

    # Ramp settings to zero
    vgate2zero_pnts = abs(
        int(meas_parameters['vgate_rng'][1] / max_values['vgate_step_size']))
    if vgate2zero_pnts < 2: vgate2zero_pnts = 3
    vgate2zero_delay = abs(
        int(meas_parameters['vgate_rng'][1] /
            (vgate2zero_pnts * max_values['vgate_rate']) * 1e6))
    if vgate2zero_delay < 1: vgate2zero_delay = 10

    vset2zero_pnts = abs(
        int(meas_parameters['vset_rng'][1] / max_values['vset_step_size']))
    if vset2zero_pnts < 2: vset2zero_pnts = 3
    vset2zero_delay = abs(
        int(meas_parameters['vset_rng'][1] /
            (vset2zero_pnts * max_values['vset_rate']) * 1e6))
    if vset2zero_delay < 1: vset2zero_delay = 10

    # Safety check
    safety_check(meas_parameters, cfg['max_values'], t_factor)

    # Lockin settings
    lockin_settings = cfg['lockin_settings']
    tc_var = lockin_settings['tc']
    sens_var = lockin_settings['sensitivity']

    if delay_meas * t_factor <= 3 * tc_var:
        print("Warning: delay is less than 3x lockin time constant.")

    # Labrad connections and Instrument Configurations

    cxn = labrad.connect()
    reg = cxn.registry
    dv = cxn.data_vault
    dac_adc = cxn.dac_adc
    dac_adc.select_device()
    dac_adc.initialize()
    dac_adc.delay_unit(delay_unit)
    dac_adc.timeout(U.Value(timeout, 's'))
    dac_adc.read()
    dac_adc.read()

    # Create datavault data set
    create_file(dv, cfg)

    # Mesh parameters

    pxsize = (meas_parameters['vgate_pnts'], meas_parameters['vset_pnts'])
    extent = (meas_parameters['vgate_rng'][0], meas_parameters['vgate_rng'][1],
              meas_parameters['vset_rng'][0], meas_parameters['vset_rng'][1])
    num_x = pxsize[0]
    num_y = pxsize[1]
    print(extent, pxsize)

    # Start timer
    time.sleep(3)
    t0 = time.time()

    # Estimated time
    est_time = (num_x * num_y * delay_meas * t_factor +
                vgate2next_pnts * vgate2next_delay * 1e-6 * num_y) / 60.0
    dt = num_x * delay_meas * t_factor / 60.0
    print(
        "Will take a total of {} mins. With each line trace taking {} This deprecated for SET."
        .format(est_time, dt))

    m = mesh(offset=(0.0, -0.0),
             xrange=(extent[0], extent[1]),
             yrange=(extent[2], extent[3]),
             pxsize=pxsize)

    mdn = m  # for future implementation

    for i in range(num_y):

        data_x = np.zeros(num_x)
        data_y = np.zeros(num_x)

        vec_x = m[i, :][:, 0]
        vec_y = m[i, :][:, 1]

        # vec_x = (m[i, :][:, 0] - dacadc_settings['ch1_offset'])
        # vec_y = (m[i, :][:, 1] - dacadc_settings['ch2_offset'])

        # md and mn for future implementation
        md = mdn[i, :][:, 0]
        mn = mdn[i, :][:, 1]

        mask = np.logical_and(np.logical_and(vec_x <= X_MAX, vec_x >= X_MIN),
                              np.logical_and(vec_y <= Y_MAX, vec_y >= Y_MIN))

        if np.any(mask == True):
            start, stop = np.where(mask == True)[0][0], np.where(
                mask == True)[0][-1]

            start = start.item()
            stop = stop.item()

            num_points = stop - start + 1

        # Ramping to initial values
        if i == 0:
            dac_adc.delay_unit(0)
            d_read = dac_adc.ramp1(dac1_ch, 0, vec_x[start], vgate2start_pnts,
                                   vgate2start_delay)
            time.sleep(2)
        else:
            dac_adc.delay_unit(0)
            previous_vec_x = m[i - 1, :][:, 0]
            d_read = dac_adc.ramp1(dac1_ch, previous_vec_x[stop], vec_x[start],
                                   vgate2next_pnts, vgate2next_delay)

        if i == 0:
            dac_adc.delay_unit(0)
            d_read = dac_adc.ramp1(dac2_ch, 0, vec_y[start], vset2start_pnts,
                                   vset2start_delay)
            time.sleep(2)
        else:
            dac_adc.delay_unit(0)
            previous_vec_y = m[i - 1, :][:, 1]
            d_read = dac_adc.ramp1(dac2_ch, previous_vec_y[stop], vec_y[start],
                                   vset2next_pnts, vset2next_delay)

        dac_adc.delay_unit(delay_unit)

        print("{} of {}  --> Ramping. Points: {}".format(
            i + 1, num_y, num_points))
        d_read = dac_adc.buffer_ramp([dac1_ch, dac2_ch], [adc1_ch, adc2_ch],
                                     [vec_x[start], vec_y[start]],
                                     [vec_x[stop], vec_y[stop]], num_points,
                                     delay_meas, ADC_AVGSIZE)

        d_tmp = d_read

        data_x[start:stop + 1], data_y[start:stop + 1] = d_tmp

        #radius = np.sqrt(np.square(data_x) + np.square(data_y)) * sens_var
        radius = np.array(data_x)
        phase = np.array(data_y) * sens_var
        #phase = np.arctan2(data_y, data_x)

        # TODO rescale lock in sensitivity

        j = np.linspace(0, num_x - 1, num_x)
        ii = np.ones(num_x) * i
        t1 = np.ones(num_x) * time.time() - t0
        totdata = np.array(
            [j, ii, vec_x, vec_y, radius, phase, md, mn, data_x, data_y, t1])
        dv.add(totdata.T)

        # Ramp down to zero if last point
        if (i == num_y - 1):
            dac_adc.ramp1(dac1_ch, vec_x[stop], 0, 10000, 300)
            dac_adc.ramp1(dac2_ch, vec_x[stop], 0, 1000, 500)

    print("it took {} s. to write data".format(time.time() - t0))