def check_current_offset(args, text): """Check current offset.""" offset_status = None adc_meas_poz = adc_ad7091r5.current_value(args['adc_offset_poz'], args['adc_gain_poz'], args['i_gain_poz'], args['adc_samples'])[0] adc_meas_neg = adc_ad7091r5.current_value(args['adc_offset_neg'], args['adc_gain_neg'], args['i_gain_neg'], args['adc_samples'])[0] if (adc_meas_poz == 0.0) and (adc_meas_neg == 0.0): offset_status = text['green'] + 'Current offset OK' + \ text['default'] else: offset_status = text['red'] + 'Current offset detected' + \ text['default'] return offset_status + '\n'
def check_adc_csa(offset_i, adc_i_ref, i_ref): """Check ADC calibration for selected channel.""" done = False while not done: adc = adc_ad7091r5.current_value(offset_i, adc_i_ref, i_ref, 1000) key = wait_key('\t ADC: {:<20} \r'.format(adc), 1) if key == '': done = True break
def positive_current_measurement(args, text): """MEASURE POSITIVE CURRENT CHA/B. Connect channel A or B at Load and enable ADC external reference Set channel A or B to source voltage setpoint and get samples Set again channel A or B to source voltage setpoint and measure resulted current with external ADC and CSA Optional is possible to generate plot images and display debug messages Compare current 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_1__1', 'EN_1V2__1']) if args['restart_verification'] == 1: ioxp_adp5589.gpo_set_ac(['GPIO_7__1', 'GPIO_1__1', 'EN_1V2__1']) control_m1k.source(args['channel_index'], global_.Mode.SVMI, args['svmi_setpoint_poz'], global_.Mode.HI_Z, args['device']) control_m1k.get_samples_find_average(args['device']) control_m1k.source(args['channel_index'], global_.Mode.SVMI, args['svmi_setpoint_poz'], global_.Mode.HI_Z, args['device']) adc_meas = adc_ad7091r5.current_value(args['adc_offset_poz'], args['adc_gain_poz'], args['i_gain_poz'], args['adc_samples'])[0] if args['create_plots']: debug.plot( str(args['device_id'] + '/Performance'), '8__P__CH_' + args['channel_name'] + '_measure_positive_current', global_.CHX_V_I[4], str(args['channel_index'] * 2 + 1)) if args['view_debug_messages']: print '\n', global_.CHX_V_I[args['channel_index'] * 2 + 1], '-', \ adc_meas, '=> abs():', \ abs(global_.CHX_V_I[args['channel_index'] * 2 + 1] - adc_meas), \ 'should be <=', abs(adc_meas * args['tolerance_current']) if abs(global_.CHX_V_I[args['channel_index'] * 2 + 1] - adc_meas) <= \ abs(adc_meas * args['tolerance_current']): debug_message = text['green'] + 'Measure ' + \ '{0:+.4f}'.format(adc_meas) + ' [A] 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) + ' [A] 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 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 negative_current_source(args, text): """SOURCE NEGATIVE CURRENT CHA/B. Set channel A or B to source reference current and get samples Set again channel A or B to source reference current and measure resulted current with external ADC and CSA Optional is possible to generate plot images and display debug messages Compare current difference between measurement and reference to be in reference range then print PASS or FAIL message """ control_m1k.source(args['channel_index'], global_.Mode.SIMV, args['srs_i_setpoint_neg'], global_.Mode.HI_Z, args['device']) control_m1k.get_samples_find_average(args['device']) control_m1k.source(args['channel_index'], global_.Mode.SIMV, args['srs_i_setpoint_neg'], global_.Mode.HI_Z, args['device']) adc_meas = adc_ad7091r5.current_value(args['adc_offset_neg'], args['adc_gain_neg'], args['i_gain_neg'], args['adc_samples'])[0] if args['create_plots']: debug.plot( str(args['device_id'] + '/Performance'), '11__P__CH_' + args['channel_name'] + '_source_negative_current', global_.CHX_V_I[4], str(args['channel_index'] * 2 + 1)) if args['view_debug_messages']: print '\n', 'adc_meas', adc_meas if abs(adc_meas - args['srs_i_setpoint_neg']) <= \ abs(adc_meas * args['tolerance_current']): debug_message = text['green'] + 'Source ' + \ '{0:+.4f}'.format(args['srs_i_setpoint_neg']) + \ ' [A] 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'] + 'Source ' + \ '{0:+.4f}'.format(args['srs_i_setpoint_neg']) + \ ' [A] 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']