added is_unipolar() and is_bipolar() query functions, added very_low_target()
authorFrank Mori Hess <fmhess@speakeasy.net>
Wed, 30 Apr 2003 20:17:44 +0000 (20:17 +0000)
committerFrank Mori Hess <fmhess@speakeasy.net>
Wed, 30 Apr 2003 20:17:44 +0000 (20:17 +0000)
helper function for generating unipolar targets that are close but not zero.

comedi_calibrate/calib.h
comedi_calibrate/cb.c
comedi_calibrate/comedi_calibrate.c
comedi_calibrate/ni.c

index 5d1f85cb3ba00b0d0d60858b25d602c367d49e57..5de512ae1dd8550d99a68abd6fbb617b726ff782 100644 (file)
@@ -141,6 +141,12 @@ 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);
+double very_low_target( comedi_t *dev, unsigned int subdevice,
+       unsigned int channel, unsigned int range );
+int is_bipolar( comedi_t *dev, unsigned int subdevice,
+       unsigned int channel, unsigned int range );
+int is_unipolar( comedi_t *dev, unsigned int subdevice,
+       unsigned int channel, unsigned int range );
 
 /* other */
 
index ea76138f8abff09ded6f9ba2c7d010db16b088a3..78bd5a4a51b99484a9900b3da6f667a0be3e9662 100644 (file)
@@ -222,20 +222,12 @@ static unsigned int ao_high_observable_1xxx( calibration_setup_t *setup,
 }
 
 static double ai_low_target_1xxx( calibration_setup_t *setup,
-       unsigned int range_index )
+       unsigned int range )
 {
-       comedi_range *range;
-       int max_data;
-
-       range = comedi_get_range( setup->dev, setup->ad_subdev, 0, range_index );
-       assert( range != NULL );
-       max_data = comedi_get_maxdata( setup->dev, setup->ad_subdev, 0 );
-       assert( max_data != 0 );
-
-       if( range->min < -0.0001 )
+       if( is_bipolar( setup->dev, setup->ad_subdev, 0, range ) )
                return 0.0;
-       else    // return half a bit above zero for unipolar ranges
-               return comedi_to_phys( 1, range, max_data ) / 2.0;
+       else
+               return very_low_target( setup->dev, setup->ad_subdev, 0, range );
 }
 
 static int source_eeprom_addr_1xxx( calibration_setup_t *setup, unsigned int range_index )
index 63cbae66ecd190156c086cf76225388f6ffc9f6a..a378b8e97ea7b90dd143c90cccfb8391b49e8efa 100644 (file)
@@ -990,6 +990,34 @@ double check_gain_chan_fine( calibration_setup_t *setup, linear_fit_t *l,unsigne
 
 /* helpers */
 
+int is_unipolar( comedi_t *dev, unsigned int subdevice,
+       unsigned int channel, unsigned int range )
+{
+       comedi_range *range_ptr;
+
+       range_ptr = comedi_get_range( dev, subdevice, channel, range );
+       assert( range_ptr != NULL );
+       /* This method is better than a direct test, which might fail */
+       if( fabs( range_ptr->min ) < fabs( range_ptr->max * 0.001 ) )
+               return 1;
+       else
+               return 0;
+}
+
+int is_bipolar( comedi_t *dev, unsigned int subdevice,
+       unsigned int channel, unsigned int range )
+{
+       comedi_range *range_ptr;
+
+       range_ptr = comedi_get_range( dev, subdevice, channel, range );
+       assert( range_ptr != NULL );
+       /* This method is better than a direct test, which might fail */
+       if( fabs( range_ptr->max + range_ptr->min ) < fabs( range_ptr->max * 0.001 ) )
+               return 1;
+       else
+               return 0;
+}
+
 int get_bipolar_lowgain(comedi_t *dev,int subdev)
 {
        int ret = -1;
@@ -1000,8 +1028,7 @@ int get_bipolar_lowgain(comedi_t *dev,int subdev)
 
        for(i=0;i<n_ranges;i++){
                range = comedi_get_range(dev,subdev,0,i);
-               /* This method is better than a direct test, which might fail */
-               if((range->min+range->max)>(range->max*0.0001))continue;
+               if( is_bipolar( dev, subdev, 0, i ) == 0 ) continue;
                if(range->max>max){
                        ret = i;
                        max=range->max;
@@ -1022,7 +1049,7 @@ int get_bipolar_highgain(comedi_t *dev,int subdev)
        for(i=0;i<n_ranges;i++){
                range = comedi_get_range(dev,subdev,0,i);
                /* This method is better than a direct test, which might fail */
-               if((range->min+range->max)>(range->max*0.0001))continue;
+               if( is_unipolar( dev, subdev, 0, i ) == 0 ) continue;
                if(range->max<min){
                        ret = i;
                        min=range->max;
@@ -1398,4 +1425,17 @@ int sci_sprint_alt(char *s,double x,double y)
        return sprintf(s,"%0.*f(%2.0f)e%d",sigfigs-1,mantissa,error,maxsig);
 }
 
+double very_low_target( comedi_t *dev, unsigned int subdevice,
+       unsigned int channel, unsigned int range )
+{
+       comedi_range *range_ptr;
+       int max_data;
+
+       range_ptr = comedi_get_range( dev, subdevice, channel, range );
+       assert( range_ptr != NULL );
+       max_data = comedi_get_maxdata( dev, subdevice, 0 );
+       assert( max_data > 0 );
+
+       return comedi_to_phys( 1, range_ptr, max_data ) / 2.0;
+}
 
index fb5d86952b649e68490b9c188c2167f85a8adf72..031b76ac9a332e51fb1d10f817c69d1cdea578d7 100644 (file)
@@ -100,7 +100,7 @@ static struct board_struct boards[]={
        { "DAQCard-ai-16e-4", STATUS_DONE, cal_ni_daqcard_ai_16e_4, ni_setup_observables, 0x1b5, 0x1b6 },
        { "pci-6110", STATUS_DONE, cal_ni_pci_611x, ni_setup_observables_611x, 0x1d4, 0x1d5 },
        { "pci-6111", STATUS_DONE, cal_ni_pci_611x, ni_setup_observables_611x, 0x1d4, 0x1d5 },
-       { "DAQCard-6062E", STATUS_SOME, cal_ni_daqcard_6062e, ni_setup_observables, 0x1a9, 0x1aa },
+       { "DAQCard-6062E", STATUS_DONE, cal_ni_daqcard_6062e, ni_setup_observables, 0x1a9, 0x1aa },
        { "DAQCard-6024E", STATUS_UNKNOWN, NULL, ni_setup_observables, -1, -1 },
        { "at-mio-16de-10", STATUS_UNKNOWN, NULL, ni_setup_observables, 0x1a7, 0x1a8 },
        { "at-mio-16xe-10", STATUS_UNKNOWN, NULL, ni_setup_observables, 0x1b7, 0x1b8 },
@@ -283,14 +283,6 @@ static void ni_setup_observables( calibration_setup_t *setup )
        o->target = voltage_reference;
 
        if(unipolar_lowgain>=0){
-               comedi_range *range;
-               int max_data;
-
-               range = comedi_get_range( setup->dev, setup->ad_subdev, 0, unipolar_lowgain );
-                       assert( range != NULL );
-               max_data = comedi_get_maxdata( setup->dev, setup->ad_subdev, 0 );
-               assert( max_data > 0 );
-
                o = setup->observables + ni_unip_zero_offset_low;
                o->name = "ai, unipolar zero offset, low gain";
                o->observe_insn = tmpl;
@@ -298,7 +290,7 @@ static void ni_setup_observables( calibration_setup_t *setup )
                        CR_PACK(REF_GND_GND,unipolar_lowgain,AREF_OTHER)
                        | CR_ALT_SOURCE | CR_ALT_FILTER;
                o->reference_source = REF_GND_GND;
-               o->target = comedi_to_phys( 1, range, max_data ) / 2.0;
+               o->target = very_low_target( setup->dev, setup->ad_subdev, 0, unipolar_lowgain );
 
                o = setup->observables + ni_unip_reference_low;
                o->name = "ai, unipolar voltage reference, low gain";
@@ -312,14 +304,6 @@ static void ni_setup_observables( calibration_setup_t *setup )
 
        if(unipolar_highgain >= 0)
        {
-               comedi_range *range;
-               int max_data;
-
-               range = comedi_get_range( setup->dev, setup->ad_subdev, 0, unipolar_highgain );
-                       assert( range != NULL );
-               max_data = comedi_get_maxdata( setup->dev, setup->ad_subdev, 0 );
-               assert( max_data > 0 );
-
                o = setup->observables + ni_unip_zero_offset_high;
                o->name = "ai, unipolar zero offset, high gain";
                o->observe_insn = tmpl;
@@ -327,7 +311,7 @@ static void ni_setup_observables( calibration_setup_t *setup )
                        CR_PACK(REF_GND_GND,unipolar_highgain,AREF_OTHER)
                        | CR_ALT_SOURCE | CR_ALT_FILTER;
                o->reference_source = REF_GND_GND;
-               o->target = comedi_to_phys( 1, range, max_data ) / 2.0;
+               o->target = very_low_target( setup->dev, setup->ad_subdev, 0, unipolar_highgain );
        }
 
        if(setup->da_subdev>=0){