From 39258a550429d3667fc9dfc4f41433760b6f2fed Mon Sep 17 00:00:00 2001 From: Frank Mori Hess Date: Mon, 28 Apr 2003 01:00:07 +0000 Subject: [PATCH] added more unipolar observables for ni boards, so unipolar calibrations can be done. --- comedi_calibrate/calib.h | 1 + comedi_calibrate/comedi_calibrate.c | 28 ++++++++++++-- comedi_calibrate/ni.c | 59 +++++++++++++++-------------- 3 files changed, 56 insertions(+), 32 deletions(-) diff --git a/comedi_calibrate/calib.h b/comedi_calibrate/calib.h index 90d4eb2..bdec910 100644 --- a/comedi_calibrate/calib.h +++ b/comedi_calibrate/calib.h @@ -137,6 +137,7 @@ int cb_actual_source_voltage( comedi_t *dev, unsigned int subdevice, int get_bipolar_lowgain(comedi_t *dev,int subdev); int get_bipolar_highgain(comedi_t *dev,int subdev); int get_unipolar_lowgain(comedi_t *dev,int subdev); +int get_unipolar_highgain(comedi_t *dev,int subdev); /* other */ diff --git a/comedi_calibrate/comedi_calibrate.c b/comedi_calibrate/comedi_calibrate.c index 8914680..eca9f51 100644 --- a/comedi_calibrate/comedi_calibrate.c +++ b/comedi_calibrate/comedi_calibrate.c @@ -300,9 +300,10 @@ void observe( calibration_setup_t *setup ) observable *obs; for( i = 0; i < setup->n_observables; i++){ + obs = &setup->observables[ i ]; + if( obs->observe_insn.n == 0 ) continue; preobserve( setup, i); DPRINT(0,"%s\n", setup->observables[i].name); - obs = &setup->observables[ i ]; if( obs->preobserve_insn.n != 0){ apply_appropriate_cal( setup, obs->preobserve_insn ); } @@ -933,12 +934,13 @@ int get_unipolar_lowgain(comedi_t *dev,int subdev) int ret = -1; int i; int n_ranges = comedi_get_n_ranges(dev,subdev,0); - double max = 0; + double max = 0.0; comedi_range *range; for(i=0;imin != 0)continue; + /* This method is better than a direct test, which might fail */ + if((range->min+range->max)<(range->max*0.99))continue; if(range->max>max){ ret = i; max=range->max; @@ -948,6 +950,26 @@ int get_unipolar_lowgain(comedi_t *dev,int subdev) return ret; } +int get_unipolar_highgain(comedi_t *dev,int subdev) +{ + int ret = -1; + int i; + int n_ranges = comedi_get_n_ranges(dev,subdev,0); + double max = HUGE_VAL; + comedi_range *range; + + for(i=0;imin+range->max)<(range->max*0.99))continue; + if(range->max < max){ + ret = i; + max=range->max; + } + } + + return ret; +} int read_eeprom( calibration_setup_t *setup, int addr) { diff --git a/comedi_calibrate/ni.c b/comedi_calibrate/ni.c index 6f4830d..9ebbd53 100644 --- a/comedi_calibrate/ni.c +++ b/comedi_calibrate/ni.c @@ -129,7 +129,9 @@ enum observables{ ni_zero_offset_low = 0, ni_zero_offset_high, ni_reference_low, - ni_unip_offset_low, + ni_unip_zero_offset_low, + ni_unip_zero_offset_high, + ni_unip_reference_low, ni_ao0_zero_offset, ni_ao0_reference, ni_ao1_zero_offset, @@ -193,12 +195,14 @@ static void ni_setup_observables( calibration_setup_t *setup ) int bipolar_lowgain; int bipolar_highgain; int unipolar_lowgain; + int unipolar_highgain; double voltage_reference; observable *o; bipolar_lowgain = get_bipolar_lowgain( setup->dev, setup->ad_subdev); bipolar_highgain = get_bipolar_highgain( setup->dev, setup->ad_subdev); unipolar_lowgain = get_unipolar_lowgain( setup->dev, setup->ad_subdev); + unipolar_highgain = get_unipolar_highgain( setup->dev, setup->ad_subdev); voltage_reference = 5.000; @@ -207,7 +211,7 @@ static void ni_setup_observables( calibration_setup_t *setup ) tmpl.n = 1; tmpl.subdev = setup->ad_subdev; - setup->n_observables = 0; + setup->n_observables = 10; /* 0 offset, low gain */ o = setup->observables + ni_zero_offset_low; @@ -217,7 +221,6 @@ static void ni_setup_observables( calibration_setup_t *setup ) | CR_ALT_SOURCE | CR_ALT_FILTER; o->reference_source = REF_GND_GND; o->target = 0; - setup->n_observables++; /* 0 offset, high gain */ o = setup->observables + ni_zero_offset_high; @@ -227,7 +230,6 @@ static void ni_setup_observables( calibration_setup_t *setup ) | CR_ALT_SOURCE | CR_ALT_FILTER; o->reference_source = REF_GND_GND; o->target = 0; - setup->n_observables++; /* voltage reference */ o = setup->observables + ni_reference_low; @@ -237,24 +239,18 @@ static void ni_setup_observables( calibration_setup_t *setup ) | CR_ALT_SOURCE | CR_ALT_FILTER; o->reference_source = REF_CALSRC_GND; o->target = voltage_reference; - setup->n_observables++; if(unipolar_lowgain>=0){ - /* unip/bip offset */ - o = setup->observables + ni_unip_offset_low; + o = setup->observables + ni_unip_zero_offset_low; o->name = "ai, unipolar zero offset, low gain"; o->observe_insn = tmpl; o->observe_insn.chanspec = CR_PACK(REF_GND_GND,unipolar_lowgain,AREF_OTHER) | CR_ALT_SOURCE | CR_ALT_FILTER; - o->reference_source = REF_GND_GND; o->target = 0.0; - setup->n_observables++; -#if 0 - /* unip gain */ - o = observables + ni_unip_reference_low; + o = setup->observables + ni_unip_reference_low; o->name = "ai, unipolar voltage reference, low gain"; o->observe_insn = tmpl; o->observe_insn.chanspec = @@ -262,9 +258,18 @@ static void ni_setup_observables( calibration_setup_t *setup ) | CR_ALT_SOURCE | CR_ALT_FILTER; o->reference_source = REF_CALSRC_GND; o->target = voltage_reference; - i++; -#endif - setup->n_observables = ni_unip_offset_low + 1; + } + + if(unipolar_highgain >= 0) + { + o = setup->observables + ni_unip_zero_offset_high; + o->name = "ai, unipolar zero offset, high gain"; + o->observe_insn = tmpl; + o->observe_insn.chanspec = + CR_PACK(REF_GND_GND,unipolar_highgain,AREF_OTHER) + | CR_ALT_SOURCE | CR_ALT_FILTER; + o->reference_source = REF_GND_GND; + o->target = 0.0; } if(setup->da_subdev>=0){ @@ -287,7 +292,6 @@ static void ni_setup_observables( calibration_setup_t *setup ) | CR_ALT_SOURCE | CR_ALT_FILTER; o->reference_source = REF_DAC0_GND; set_target( setup, ni_ao0_zero_offset,0.0); - setup->n_observables++; /* ao 0, gain */ o = setup->observables + ni_ao0_reference; @@ -302,7 +306,6 @@ static void ni_setup_observables( calibration_setup_t *setup ) o->reference_source = REF_DAC0_CALSRC; set_target( setup, ni_ao0_reference,5.0); o->target -= voltage_reference; - setup->n_observables++; /* ao 1, zero offset */ o = setup->observables + ni_ao1_zero_offset; @@ -316,7 +319,6 @@ static void ni_setup_observables( calibration_setup_t *setup ) | CR_ALT_SOURCE | CR_ALT_FILTER; o->reference_source = REF_DAC1_GND; set_target( setup, ni_ao1_zero_offset,0.0); - setup->n_observables++; /* ao 1, gain */ o = setup->observables + ni_ao1_reference; @@ -331,7 +333,6 @@ static void ni_setup_observables( calibration_setup_t *setup ) o->reference_source = REF_DAC1_CALSRC; set_target( setup, ni_ao1_reference,5.0); o->target -= voltage_reference; - setup->n_observables++; } } @@ -463,7 +464,7 @@ static int cal_ni_at_mio_16e_2(calibration_setup_t *setup) postgain_cal( setup, ni_zero_offset_low,ni_zero_offset_high,1); cal1( setup, ni_zero_offset_high,0); cal1( setup, ni_reference_low,3); - cal1( setup, ni_unip_offset_low,2); + cal1( setup, ni_unip_zero_offset_low,2); if(setup->do_output){ cal1( setup, ni_ao0_zero_offset,5); cal1( setup, ni_ao0_reference,6); @@ -555,7 +556,7 @@ static int cal_ni_pci_mio_16e_1(calibration_setup_t *setup) postgain_cal( setup, ni_zero_offset_low,ni_zero_offset_high,1); cal1( setup, ni_zero_offset_high,0); cal1( setup, ni_reference_low,3); - cal1( setup, ni_unip_offset_low,2); + cal1( setup, ni_unip_zero_offset_low,2); if(setup->do_output){ cal1( setup, ni_ao0_zero_offset,5); //cal1( setup, ni_ao0_zero_offset,4); /* linearity? */ @@ -641,7 +642,7 @@ static int cal_ni_at_mio_16e_10(calibration_setup_t *setup) cal1( setup, ni_zero_offset_high,10); cal1( setup, ni_zero_offset_high,0); cal1( setup, ni_reference_low,3); - cal1( setup, ni_unip_offset_low,2); + cal1( setup, ni_unip_zero_offset_low,2); if(setup->do_output){ cal1( setup, ni_ao0_zero_offset,5); // guess cal1( setup, ni_ao0_reference,6); // guess @@ -757,8 +758,8 @@ static int cal_ni_pci_6052e(calibration_setup_t *setup) cal_binary( setup, ni_reference_low,4); cal1_fine( setup, ni_reference_low,4); cal1( setup, ni_reference_low,5); - cal1( setup, ni_unip_offset_low,6); - cal1_fine( setup, ni_unip_offset_low,6); + cal1( setup, ni_unip_zero_offset_low,6); + cal1_fine( setup, ni_unip_zero_offset_low,6); if(setup->do_output){ cal1( setup, ni_ao0_zero_offset,12+11); cal1_fine( setup, ni_ao0_zero_offset,12+11); @@ -783,8 +784,8 @@ static int cal_ni_pci_mio_16e_4(calibration_setup_t *setup) cal_binary( setup, ni_reference_low,2); cal1_fine( setup, ni_reference_low,2); - cal1( setup, ni_unip_offset_low,7); - cal1_fine( setup, ni_unip_offset_low,7); + cal1( setup, ni_unip_zero_offset_low,7); + cal1_fine( setup, ni_unip_zero_offset_low,7); if(setup->do_output){ cal_binary( setup, ni_ao0_zero_offset,6); @@ -812,7 +813,7 @@ static int cal_ni_daqcard_ai_16e_4(calibration_setup_t *setup) cal_binary( setup, ni_reference_low,3); cal1_fine( setup, ni_reference_low,3); - cal1( setup, ni_unip_offset_low,2); + cal1( setup, ni_unip_zero_offset_low,2); return 0; } @@ -846,11 +847,11 @@ static int cal_ni_daqcard_6062e( calibration_setup_t *setup ) int i, retval; enum caldacs { - ADC_PREGAIN_OFFSET = 0, /* guess */ + ADC_PREGAIN_OFFSET = 0, DAC1_OFFSET = 1, ADC_GAIN = 2, DAC0_GAIN = 3, - ADC_POSTGAIN_OFFSET = 4, /* guess */ + ADC_POSTGAIN_OFFSET = 4, DAC1_GAIN = 5, DAC0_OFFSET = 6, }; -- 2.26.2