make sure we aren't out-of-range when doing unipolar postgain offset
authorFrank Mori Hess <fmhess@speakeasy.net>
Fri, 6 Jun 2003 14:59:29 +0000 (14:59 +0000)
committerFrank Mori Hess <fmhess@speakeasy.net>
Fri, 6 Jun 2003 14:59:29 +0000 (14:59 +0000)
comedi_calibrate/cal_common.c
comedi_calibrate/calib.h
comedi_calibrate/comedi_calibrate.c

index 4d3ed603440a75ef8c11794c84489012a62e9d51..ad37ea02a2f071ac4637cf24585452b8f2440edd 100644 (file)
@@ -51,6 +51,13 @@ void generic_do_linearity( calibration_setup_t *setup,
        sc_push_caldac( saved_cal, setup->caldacs[ caldac ] );
 }
 
+void generic_peg( calibration_setup_t *setup,
+       comedi_calibration_setting_t *saved_cal, int observable, int caldac, int maximize )
+{
+       if( caldac < 0 || observable < 0 ) return;
+       peg_binary( setup, observable, caldac, maximize );
+}
+
 void generic_prep_adc_caldacs( calibration_setup_t *setup,
        const generic_layout_t *layout, unsigned int channel, unsigned int range )
 {
@@ -172,6 +179,14 @@ static void generic_do_adc_postgain_offset( calibration_setup_t *setup, const ge
        {
                lowgain = get_unipolar_lowgain( setup->dev, setup->ad_subdev );
                highgain = get_unipolar_highgain( setup->dev, setup->ad_subdev );
+
+               reset_caldac( setup, layout->adc_postgain_offset( channel ) );
+               /* need to make sure we aren't stuck on zero for unipolar,
+                * by setting pregain offset to maximum */
+               generic_peg( setup, current_cal, layout->adc_ground_observable( setup, channel, lowgain ),
+                       layout->adc_offset( channel ), 1 );
+               generic_peg( setup, current_cal, layout->adc_ground_observable( setup, channel, lowgain ),
+                       layout->adc_offset_fine( channel ), 1 );
        }else
        {
                lowgain = get_bipolar_lowgain( setup->dev, setup->ad_subdev );
index f7bb35a1909742265f518daf1ac06ccac814ed0a..e62294f49ff89c76b4c3a38f2f0f6fd90684b2dd 100644 (file)
@@ -121,6 +121,7 @@ void cal_binary( calibration_setup_t *setup, int obs, int dac);
 void cal_postgain_binary( calibration_setup_t *setup, int obs1, int obs2, int dac);
 void cal_relative_binary( calibration_setup_t *setup, int obs1, int obs2, int dac);
 void cal_linearity_binary( calibration_setup_t *setup, int obs1, int obs2, int obs3, int dac);
+void peg_binary( calibration_setup_t *setup, int obs, int dac, int maximize );
 
 /* misc and temp */
 
index a8716d838da7be9161a5b32c60b6d9e9f41421a0..a146bbea47bbf7338ebe899ae709c77f97ef55f8 100644 (file)
@@ -531,6 +531,52 @@ void cal1_fine( calibration_setup_t *setup, int obs, int dac )
        }
 }
 
+void peg_binary( calibration_setup_t *setup, int obs, int dac, int maximize )
+{
+       int x0, x1, x;
+       double y0, y1;
+       new_sv_t sv;
+       unsigned int chanspec = setup->observables[obs].observe_insn.chanspec;
+       int polarity;
+
+       DPRINT(0,"binary peg: %s\n", setup->observables[obs].name);
+       preobserve( setup, obs);
+
+       comedi_set_global_oor_behavior( COMEDI_OOR_NUMBER );
+
+       my_sv_init(&sv, setup, setup->ad_subdev, chanspec);
+
+       x0 = setup->caldacs[dac].maxdata;
+       update_caldac( setup, dac, x0 );
+       usleep(caldac_settle_usec);
+       new_sv_measure( setup->dev, &sv);
+       y0 = sv.average;
+
+       x1 = 0;
+       update_caldac( setup, dac, x1 );
+       usleep(caldac_settle_usec);
+       new_sv_measure( setup->dev, &sv);
+       y1 = sv.average;
+
+       if( (y0 - y1) > 0.0 ) polarity = 1;
+       else polarity = -1;
+
+       if( maximize )
+       {
+               if( polarity > 0 ) x = x0;
+               else x = x1;
+       }else
+       {
+               if( polarity > 0 ) x = x1;
+               else x = x0;
+       }
+       update_caldac( setup, dac, x );
+       DPRINT(0,"caldac[%d] set to %d\n",dac,x);
+       if(verbose>=3){
+               measure_observable( setup, obs);
+       }
+}
+
 void cal_binary( calibration_setup_t *setup, int obs, int dac)
 {
        int x0, x1, x2, x;