def source_0v8(args, text): """SOURCE CHA/B 0v8. Connect channel A or B at 1 Mega load and enable ADC external reference Set channel A or B to source reference voltage and get samples Set again channel A or B to source reference voltage and measure sourced voltage with external ADC Optional is possible to generate plot images and display debug messages Compare voltage difference between measurement and reference to be in reference range then print PASS or FAIL message """ if args['restart_verification'] == 0: ioxp_adp5589.gpo_set_ac(['GPIO_8__1', 'GPIO_3__1', 'EN_1V2__1']) if args['restart_verification'] == 1: ioxp_adp5589.gpo_set_ac(['GPIO_7__1', 'GPIO_3__1', 'EN_1V2__1']) control_m1k.source(args['channel_index'], global_.Mode.SVMI, args['srs_0v8_setpoint'], global_.Mode.HI_Z, args['device']) control_m1k.get_samples_find_average(args['device']) control_m1k.source(args['channel_index'], global_.Mode.SVMI, args['srs_0v8_setpoint'], global_.Mode.HI_Z, args['device']) adc_meas = adc_ad7091r5.voltage_input(2, args['calibration_factors_vin2'], args['adc_samples']) if args['brake_script']: debug.add_break_point(text['orange'] + 'Measure sourced 0v8 with channel ' + args['channel_name'] + ' ... Press ENTER to continue... ' + text['default']) if args['create_plots']: debug.plot(str(args['device_id'] + '/Performance'), '5__P__CH_' + args['channel_name'] + '_source_0V8', global_.CHX_V_I[4], str(args['channel_index'] * 2)) if args['view_debug_messages']: print '\n', 'ADC measurement', adc_meas, \ 'tolerance', args['tolerance_voltage'] if abs(adc_meas[0] - args['srs_0v8_setpoint']) <= \ args['tolerance_voltage']: debug_message = text['green'] + 'Source ' + \ '{0:+.4f}'.format(args['srs_0v8_setpoint']) + \ ' [V] CH_' + args['channel_name'] + ' PASS' + text['default'] args['status'].append(True) args['status_values'].append('{0:.4f}'.format(adc_meas[0])) else: debug_message = text['red'] + 'Source ' + \ '{0:+.4f}'.format(args['srs_0v8_setpoint']) + \ ' [V] CH_' + args['channel_name'] + ' FAIL' + text['default'] args['status'].append(False) args['status_values'].append('{0:.4f}'.format(adc_meas[0])) if not args['enable_debug_mode']: print debug_message exit(1) if args['view_short_debug_messages']: print debug_message return args['status']
def check_adc(channel, ex_1v2_ref, adc_offset, adc_scale, adc_gain): """Check ADC calibration for selected channel.""" done = False while not done: adc_params = [ex_1v2_ref, adc_offset, adc_scale, adc_gain] adc = adc_ad7091r5.voltage_input(channel, adc_params, 1000) key = wait_key('\t ADC: {:<20} \r'.format(adc), 1) if key == '': done = True break return adc
def predetermine_resistance(polarity): """Calculate resistance besed on ADC measurements after calibration.""" ex_1v2_ref = eeprom_m24c02.read_write(0x08, '', 8, 'float') adc_offset_vin3 = int(eeprom_m24c02.read_write(0x50, '', 2, 'float')) adc_scale_vin3 = eeprom_m24c02.read_write(0x53, '', 6, 'float') adc_gain_vin3 = eeprom_m24c02.read_write(0x5A, '', 6, 'float') adc_params_3 = [ex_1v2_ref, adc_offset_vin3, adc_scale_vin3, adc_gain_vin3] adc_offset_vin2 = int(eeprom_m24c02.read_write(0x40, '', 2, 'float')) adc_scale_vin2 = eeprom_m24c02.read_write(0x43, '', 6, 'float') adc_gain_vin2 = eeprom_m24c02.read_write(0x4A, '', 6, 'float') adc_params_2 = [ex_1v2_ref, adc_offset_vin2, adc_scale_vin2, adc_gain_vin2] adc_offset_poz = int(eeprom_m24c02.read_write(0x70, '', 3, 'hex'), 16) adc_gain_poz = int(eeprom_m24c02.read_write(0x75, '', 3, 'hex'), 16) i_gain_poz = eeprom_m24c02.read_write(0x7A, '', 6, 'float') adc_offset_neg = int(eeprom_m24c02.read_write(0x80, '', 3, 'hex'), 16) adc_gain_neg = int(eeprom_m24c02.read_write(0x85, '', 3, 'hex'), 16) i_gain_neg = eeprom_m24c02.read_write(0x89, '', 7, 'float') if polarity == 'poz': ref_2v5_srs = adc_ad7091r5.voltage_input(3, adc_params_3, 1000)[0] chx_voltage_srs = adc_ad7091r5.voltage_input(2, adc_params_2, 1000)[0] current_chx_poz = adc_ad7091r5.current_value(adc_offset_poz, adc_gain_poz, i_gain_poz, 1000)[0] voltage = chx_voltage_srs + 0.022 - ref_2v5_srs resistance_srs = voltage / current_chx_poz print(resistance_srs) if polarity == 'neg': ref_2v5_snc = adc_ad7091r5.voltage_input(3, adc_params_3, 1000)[0] chx_voltage_snc = adc_ad7091r5.voltage_input(2, adc_params_2, 1000)[0] current_chx_neg = adc_ad7091r5.current_value(adc_offset_neg, adc_gain_neg, i_gain_neg, 1000)[0] voltage = chx_voltage_snc - 0.027 - ref_2v5_snc resistance_snc = voltage / current_chx_neg print(resistance_snc)
def voltage_measurement_2v5(args, text): """MEASURE CHA/B EXTERNAL REFERENCE 2V5. Disconnect channels from GND and 2V5 using internal M1K switches Connect channel A or B at 2V5 external reference Set both channels to high impedance mode and get samples Optional is possible to generate plot images and display debug messages Compare voltage difference between measurement and reference to be in reference range then print PASS or FAIL message """ control_m1k.set_switches_chs_2v5_gnd('open', 'open', 'open', 'open', args['device']) if args['restart_verification'] == 0: ioxp_adp5589.gpo_set_ac(['GPIO_8__1', 'GPIO_0__1', 'EN_1V2__1']) if args['restart_verification'] == 1: ioxp_adp5589.gpo_set_ac(['GPIO_7__1', 'GPIO_0__1', 'EN_1V2__1']) control_m1k.channels_in_hi_z() control_m1k.get_samples_find_average(args['device']) adc_meas = \ adc_ad7091r5.voltage_input( 2, args['calibration_factors_vin2'], args['adc_samples'])[0] if args['create_plots']: debug.plot(str(args['device_id'] + '/Performance'), '1__P__CH_' + args['channel_name'] + '_measure_2V5', global_.CHX_V_I[4], str(args['channel_index'] * 2)) if args['view_debug_messages']: print '\n', global_.CHX_V_I[args['channel_index'] * 2], '-', \ adc_meas, '=> abs():', \ abs(global_.CHX_V_I[args['channel_index'] * 2] - adc_meas), \ 'should be <=', adc_meas * args['tolerance_voltage'] if abs(global_.CHX_V_I[args['channel_index'] * 2] - adc_meas) <= \ adc_meas * args['tolerance_voltage']: debug_message = text['green'] + 'Measure ' + \ '{0:+.4f}'.format(adc_meas) + ' [V] CH_' + \ args['channel_name'] + ' PASS' + text['default'] args['status'].append(True) args['status_values'].append('{0:.4f}'.format(adc_meas)) else: debug_message = text['red'] + 'Measure ' + \ '{0:+.4f}'.format(adc_meas) + ' [V] CH_' + \ args['channel_name'] + ' FAIL' + text['default'] args['status'].append(False) args['status_values'].append('{0:.4f}'.format(adc_meas)) if not args['enable_debug_mode']: print debug_message exit(1) if args['view_short_debug_messages']: print debug_message return args['status']
def voltage_measurement_3v75(args, text): """MEASURE CHA/B EXTERNAL 3V75. Set DAC to generate reference voltage Set both channels to high impedance mode and get samples Optional is possible to generate plot images and display debug messages Compare voltage difference between measurement and reference to be in reference range then print PASS or FAIL message """ dac_ad5647r.set_output(args['dac_srs_3v75_cmd']) control_m1k.channels_in_hi_z() control_m1k.get_samples_find_average(args['device']) adc_meas = \ adc_ad7091r5.voltage_input( 2, args['calibration_factors_vin2'], args['adc_samples'])[0] if args['create_plots']: debug.plot(str(args['device_id'] + '/Performance'), '4__P__CH_' + args['channel_name'] + '_measure_3V75', global_.CHX_V_I[4], str(args['channel_index'] * 2)) if args['view_debug_messages']: print '\n', global_.CHX_V_I[args['channel_index'] * 2], '-', \ adc_meas, '=> abs():', \ abs(global_.CHX_V_I[args['channel_index'] * 2] - adc_meas), \ 'should be <=', adc_meas * args['tolerance_voltage'] if abs(global_.CHX_V_I[args['channel_index'] * 2] - adc_meas) <= \ adc_meas * args['tolerance_voltage']: debug_message = text['green'] + 'Measure ' + \ '{0:+.4f}'.format(adc_meas) + ' [V] CH_' + \ args['channel_name'] + ' PASS' + text['default'] args['status'].append(True) args['status_values'].append('{0:.4f}'.format(adc_meas)) else: debug_message = text['red'] + 'Measure ' + \ '{0:+.4f}'.format(adc_meas) + ' [V] CH_' + \ args['channel_name'] + ' FAIL' + text['default'] args['status'].append(False) args['status_values'].append('{0:.4f}'.format(adc_meas)) if not args['enable_debug_mode']: print debug_message exit(1) if args['view_short_debug_messages']: print debug_message return args['status']
def supply_output_2v5(min_lim, max_lim, calibration_factors_vin3, adc_samples, args): """Check M1K 2.5V reference. Compare M1K 2V5 with a min and a max value and return PASS or FAIL message """ m1k_2v5_rail = \ adc_ad7091r5.voltage_input(3, calibration_factors_vin3, adc_samples)[0] if m1k_2v5_rail >= min_lim and m1k_2v5_rail < max_lim: result = TEXT['green'] + '2V5 CHECK PASS' + TEXT['default'] args['status'].append(True) args['status_values'].append('{0:.4f}'.format(m1k_2v5_rail)) else: result = TEXT['red'] + '2V5 CHECK FAIL' + TEXT['default'] args['status'].append(False) args['status_values'].append('{0:.4f}'.format(m1k_2v5_rail)) if not args['enable_debug_mode']: print result exit(1) if args['view_short_debug_messages']: print result return args['status']