Exemple #1
0
def get_input_means(handle, gainlist, caldict):
    """Returns the mean voltages [chA mean, chB mean]
    
    Arguments:
      handle -- Serial object for the CGR-101
      gainlist -- Gain configuration
      caldict -- A dictionary of (calibration factor names) : values
    """
    offsets = []
    trigdict = utils.get_trig_dict(3,0,0,512)
    [ctrl_reg, fsamp_act] = utils.set_ctrl_reg(handle, 1e5, trigdict)
    tracedata = utils.get_uncal_forced_data(handle,ctrl_reg)
    voltdata = utils.get_cal_data(caldict,gainlist,tracedata)
    offsets.append(mean(voltdata[0]))
    offsets.append(mean(voltdata[1]))
    return(offsets)
Exemple #2
0
def set_sample_rate(handle, config, drive_frequency, trigger_dictionary):
    """Returns the sample rate set to acquire multiple periods of the drive frequency

    We need to send the trigger dictionary along with the drive
    frequency because the two settings share the same register.

    Arguments:
      handle -- Serial object for the CGR scope
      config -- The configuration file object
      drive_frequency -- The drive frequency (Hz)
      trigger_dictionary -- Trigger settings

    """
    capture_points = 1024 # Points acquired after a trigger
    seconds_needed = int(config['Sweep']['cycles'])/drive_frequency
    target_rate = capture_points/seconds_needed
    [control_register_value, actual_samplerate] = utils.set_ctrl_reg(
        handle, target_rate, trigger_dictionary
    )
    return actual_samplerate
Exemple #3
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)
    # Trigger is hard coded to internal (auto trigger) for the
    # calibration code.
    trigdict = utils.get_trig_dict(3,0,0,0)
    cgr = utils.get_cgr(config) # Connect to the unit
    caldict = utils.load_cal(cgr, config['Calibration']['calfile'])
    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
            )
        )

    # Start the offset calibration
    caldict = get_offsets(cgr, ctrl_reg, gainlist, caldict, config)

    # Start the slope calibration
    caldict = get_slopes(cgr, ctrl_reg, gainlist, caldict, config)
    utils.write_cal(cgr, config['Calibration']['calfile'], caldict)
Exemple #4
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...')