Ejemplo n.º 1
0
def main():
    logger.debug('Utility module number is ' + str(utils.utilnum))
    config = load_config(args.rcfile)
    global ch,fh # Need to modify console and file logger handlers
                 # with the config file, from inside main().  They
                 # thus must be made global.
    (ch,fh) = init_logger(config,ch,fh)
    cgr = utils.get_cgr(config)
    caldict = utils.load_cal(cgr, config['Calibration']['calfile'])
    eeprom_list = utils.get_eeprom_offlist(cgr)
    # Configure the inputs for 10x gain
    if (int(config['Inputs']['gain']) == 10):
        gainlist = utils.set_hw_gain(cgr,[1,1])
    else:
        gainlist = utils.set_hw_gain(cgr,[0,0])
    meanvolts = get_input_means(cgr, gainlist, caldict)
    logger.debug('Channel A mean is ' + '{:0.3f}'.format(meanvolts[0]) + ' V')
    logger.debug('Channel B mean is ' + '{:0.3f}'.format(meanvolts[1]) + ' V')
    # Configure the trigger:
    #   Trigger on channel A
    #   Trigger at channel A's mean voltage
    #   Trigger on the rising edge
    #   Capture 512 points after trigger
    trigdict = utils.get_trig_dict(0,
                                   meanvolts[0],
                                   0,
                                   512
    )
    utils.set_trig_level(cgr, caldict, gainlist, trigdict)
    utils.set_trig_samples(cgr,trigdict)
    waveplot = wave_plot_init()
    magplot = magnitude_plot_init()
    realplot = real_plot_init()
    capplot = capacitance_plot_init()
    freqlist = get_sweep_list(config)
    drive_frequency_list = []
    impedance_list = []
    for progfreq in freqlist:
        # The actual frequency will be determined by the hardware
        actfreq = utils.set_sine_frequency(cgr, float(progfreq))
        drive_frequency_list.append(actfreq)
        logger.debug('Requested ' + '{:0.2f}'.format(float(progfreq)) +
                     ' Hz, set ' + '{:0.2f}'.format(actfreq) + ' Hz')
        if (progfreq == freqlist[0]):
            # Only set amplitude once
            actamp = utils.set_output_amplitude(cgr, float(config['Sweep']['amplitude']))
            logger.debug('Requested ' + '{:0.2f}'.format(float(config['Sweep']['amplitude'])) +
                         ' Vp, set ' + '{:0.2f}'.format(actamp) + ' Vp')
        actrate = set_sample_rate(cgr, config, actfreq, trigdict)
        logger.debug('Sample rate set to ' + '{:0.2f}'.format(actrate) +
                     ' Hz, for an acquisition time of ' + '{:0.2f}'.format(1024/actrate * 1000) +
                     ' milliseconds'
                     )
        for capturenum in range(int(config['Sweep']['averages'])):
            if trigdict['trigsrc'] == 3:
                # Internal trigger
                tracedata = utils.get_uncal_forced_data(cgr,ctrl_reg)
            elif trigdict['trigsrc'] < 3:
                # Trigger on a voltage present at some input
                tracedata = utils.get_uncal_triggered_data(cgr,trigdict)
            logger.info('Acquiring trace ' + str(capturenum + 1) + ' of ' +
                        str(int(config['Sweep']['averages']))     
            )
            if capturenum == 0:
                sumdata = tracedata
            else:
                sumdata = add(sumdata,tracedata)
            avgdata = divide(sumdata,float(capturenum +1))
            # Apply calibration
            voltdata = utils.get_cal_data(caldict,gainlist,avgdata)
            if (int(config['Inputs']['gain']) == 10):
                # Divide by 10 for 10x hardware gain with no probe
                voltdata = divide(voltdata,10)
            timedata = utils.get_timelist(actrate)
        sine_vectors = get_sine_vectors(actfreq, timedata, voltdata)
        logger.debug('Channel A amplitude is ' +
                     '{:0.3f}'.format(2*vector_length(sine_vectors[0])) +
                     ' Vp'
        )
        logger.debug('Channel B amplitude is ' +
                     '{:0.3f}'.format(2*vector_length(sine_vectors[1])) +
                     ' Vp'
        )     
        logger.debug('Channel A phase shift is ' +
                     '{:0.3f}'.format(vector_angle(sine_vectors[0]) * 180/pi) +
                     ' degrees'
        )
        logger.debug('Channel B phase shift is ' +
                     '{:0.3f}'.format(vector_angle(sine_vectors[1]) * 180/pi) +
                     ' degrees'
        )
        plot_wave_data(waveplot, timedata, voltdata, trigdict, actfreq, sine_vectors)        
        impedance = get_z_vector(config, actfreq, timedata, voltdata)
        logger.debug('Impedance magnitude is ' +
                     '{:0.3f}'.format(vector_length(impedance)) +
                     ' Ohms'
        )
        logger.debug('Impedance angle is ' +
                     '{:0.3f}'.format(vector_angle(impedance) * 180/pi) +
                     ' degrees'
        )
        impedance_list.append(impedance)
        if (len(drive_frequency_list) > 1):
            plot_magnitude_data(magplot, drive_frequency_list, impedance_list)
            plot_real_data(realplot, drive_frequency_list, impedance_list)
            plot_capacitance_data(capplot, drive_frequency_list, impedance_list)
    # Set amplitude to zero to end the sweep
    utils.set_output_amplitude(cgr, 0.01)
    raw_input('Press any key to close plot and exit...')
Ejemplo n.º 2
0
def main():
    logger.debug('Utility module number is ' + str(utils.utilnum))
    config = load_config(args.rcfile)
    global ch,fh # Need to modify console and file logger handlers
                 # with the config file, from inside main().  They
                 # thus must be made global.
    (ch,fh) = init_logger(config,ch,fh)
    trigdict = utils.get_trig_dict( int(config['Trigger']['source']),
                                     float(config['Trigger']['level']),
                                     int(config['Trigger']['polarity']),
                                     int(config['Trigger']['points'])
    )
    cgr = utils.get_cgr(config)
    caldict = utils.load_cal(cgr, config['Calibration']['calfile'])
    eeprom_list = utils.get_eeprom_offlist(cgr)
    gainlist = utils.set_hw_gain(
        cgr, [int(config['Inputs']['Aprobe']),
              int(config['Inputs']['Bprobe'])
          ]
    )

    utils.set_trig_level(cgr, caldict, gainlist, trigdict)
    utils.set_trig_samples(cgr,trigdict)
    [ctrl_reg, fsamp_act] = utils.set_ctrl_reg(
        cgr, float(config['Acquire']['rate']), trigdict
    )
    if not (fsamp_act == float(config['Acquire']['rate'])):
        logger.warning(
            'Requested sample frequency ' + '{:0.3f} kHz '.format(
                float(config['Acquire']['rate'])/1000
            )
            + 'adjusted to ' + '{:0.3f} kHz '.format(
                float(fsamp_act)/1000
            )
        )

    # Wait for trigger, then return uncalibrated data
    gplot = plotinit() # Create plot object
    for capturenum in range(int(config['Acquire']['averages'])):
        if trigdict['trigsrc'] == 3:
            # Internal trigger
            tracedata = utils.get_uncal_forced_data(cgr,ctrl_reg)
        elif trigdict['trigsrc'] < 3:
            # Trigger on a voltage present at some input
            tracedata = utils.get_uncal_triggered_data(cgr,trigdict)
        logger.info('Acquiring trace ' + str(capturenum + 1) + ' of ' +
                    str(config['Acquire']['averages']))
        if capturenum == 0:
            sumdata = tracedata
        else:
            sumdata = add(sumdata,tracedata)
        avgdata = divide(sumdata,float(capturenum +1))
        # Apply calibration
        voltdata = utils.get_cal_data(
            caldict,gainlist,[avgdata[0],avgdata[1]]
        )
        timedata = utils.get_timelist(fsamp_act)
        logger.debug(
            'Plotting average of ' + str(capturenum + 1) + ' traces.'
        )
        plotdata(gplot, timedata, voltdata, trigdict)



    savedata(config, timedata, voltdata)
    raw_input('Press any key to close plot and exit...')