From 53a43ff0a711174a40ec6d05e513e285adbcf9b8 Mon Sep 17 00:00:00 2001 From: Frank Mori Hess Date: Fri, 6 Jun 2003 14:59:29 +0000 Subject: [PATCH] make sure we aren't out-of-range when doing unipolar postgain offset --- comedi_calibrate/cal_common.c | 15 ++++++++++ comedi_calibrate/calib.h | 1 + comedi_calibrate/comedi_calibrate.c | 46 +++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+) diff --git a/comedi_calibrate/cal_common.c b/comedi_calibrate/cal_common.c index 4d3ed60..ad37ea0 100644 --- a/comedi_calibrate/cal_common.c +++ b/comedi_calibrate/cal_common.c @@ -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 ); diff --git a/comedi_calibrate/calib.h b/comedi_calibrate/calib.h index f7bb35a..e62294f 100644 --- a/comedi_calibrate/calib.h +++ b/comedi_calibrate/calib.h @@ -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 */ diff --git a/comedi_calibrate/comedi_calibrate.c b/comedi_calibrate/comedi_calibrate.c index a8716d8..a146bbe 100644 --- a/comedi_calibrate/comedi_calibrate.c +++ b/comedi_calibrate/comedi_calibrate.c @@ -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; -- 2.26.2