From 5ff5c2421278b9f923ce6a47a403224156d3225e Mon Sep 17 00:00:00 2001 From: Frank Mori Hess Date: Mon, 5 May 2003 00:11:50 +0000 Subject: [PATCH] increased max number of observables for 611x boards, added postgain offset to generic calibration routines, used generic cal for mc pci-das1602/16 calibration. --- comedi_calibrate/cal_common.c | 92 ++++++++++++++++++++++++++--- comedi_calibrate/calib.h | 4 +- comedi_calibrate/cb.c | 69 +++++++++++++++++++++- comedi_calibrate/comedi_calibrate.c | 3 +- 4 files changed, 156 insertions(+), 12 deletions(-) diff --git a/comedi_calibrate/cal_common.c b/comedi_calibrate/cal_common.c index de93e57..0d85293 100644 --- a/comedi_calibrate/cal_common.c +++ b/comedi_calibrate/cal_common.c @@ -64,10 +64,8 @@ void generic_prep_adc_caldacs( calibration_setup_t *setup, reset_caldac( setup, layout->adc_gain( channel ) ); reset_caldac( setup, layout->adc_offset_fine( channel ) ); reset_caldac( setup, layout->adc_gain_fine( channel ) ); - // don't reset postgain offset here }else { - // need to preserve postgain offset? XXX retval = comedi_apply_calibration( setup->dev, setup->ad_subdev, channel, range, AREF_GROUND, setup->cal_save_file_path); if( retval < 0 ) @@ -77,7 +75,6 @@ void generic_prep_adc_caldacs( calibration_setup_t *setup, reset_caldac( setup, layout->adc_gain( channel ) ); reset_caldac( setup, layout->adc_offset_fine( channel ) ); reset_caldac( setup, layout->adc_gain_fine( channel ) ); - // don't reset postgain offset here } } } @@ -182,8 +179,6 @@ static void generic_do_dac_channel( calibration_setup_t *setup, const generic_la saved_calibration_t *saved_cals, unsigned int saved_cals_length, saved_calibration_t *current_cal, unsigned int channel, unsigned int range ) { - generic_prep_dac_caldacs( setup, layout, channel, range ); - generic_prep_adc_for_dac( setup, layout, saved_cals, saved_cals_length, layout->dac_ground_observable( setup, channel, range ) ); @@ -205,8 +200,6 @@ static void generic_do_dac_channel( calibration_setup_t *setup, const generic_la static void generic_do_adc_channel( calibration_setup_t *setup, const generic_layout_t *layout, saved_calibration_t *current_cal, unsigned int channel, unsigned int range ) { - generic_prep_adc_caldacs( setup, layout, channel, range ); - generic_do_relative( setup, current_cal, layout->adc_high_observable( setup, channel, range ), layout->adc_ground_observable( setup, channel, range ), layout->adc_gain( channel ) ); generic_do_cal( setup, current_cal, layout->adc_ground_observable( setup, channel, range ), @@ -222,6 +215,29 @@ static void generic_do_adc_channel( calibration_setup_t *setup, const generic_la sc_push_aref( current_cal, SC_ALL_AREFS ); } +static void generic_do_adc_postgain_offset( calibration_setup_t *setup, const generic_layout_t *layout, + saved_calibration_t *current_cal, unsigned int channel, int unipolar ) +{ + int lowgain, highgain; + + if( unipolar ) + { + lowgain = get_unipolar_lowgain( setup->dev, setup->ad_subdev ); + highgain = get_unipolar_highgain( setup->dev, setup->ad_subdev ); + }else + { + lowgain = get_bipolar_lowgain( setup->dev, setup->ad_subdev ); + highgain = get_bipolar_highgain( setup->dev, setup->ad_subdev ); + } + + generic_do_relative( setup, current_cal, layout->adc_ground_observable( setup, channel, lowgain ), + layout->adc_ground_observable( setup, channel, highgain ), layout->adc_postgain_offset( channel ) ); + + current_cal->subdevice = setup->ad_subdev; + sc_push_channel( current_cal, channel ); + sc_push_aref( current_cal, SC_ALL_AREFS ); +} + int generic_cal_by_channel_and_range( calibration_setup_t *setup, const generic_layout_t *layout ) { @@ -251,6 +267,10 @@ int generic_cal_by_channel_and_range( calibration_setup_t *setup, num_ai_calibrations = num_ai_ranges * num_ai_channels; num_calibrations = num_ai_calibrations + num_ao_ranges * num_ao_channels; + for( channel = 0; channel < num_ai_channels; channel++ ) + if( layout->adc_postgain_offset( channel ) >= 0 ) + num_calibrations += 2; + saved_cals = malloc( num_calibrations * sizeof( saved_calibration_t ) ); saved_cals = malloc( num_calibrations * sizeof( saved_calibration_t ) ); if( saved_cals == NULL ) return -1; @@ -259,8 +279,34 @@ int generic_cal_by_channel_and_range( calibration_setup_t *setup, for( channel = 0; channel < num_ai_channels; channel++ ) { + int postgain_bip, postgain_unip; + + if( layout->adc_postgain_offset( 0 ) >= 0 ) + { + /* bipolar postgain */ + generic_do_adc_postgain_offset( setup, layout, current_cal, channel, 0 ); + for( range = 0; range < num_ai_ranges; range++ ) + if( is_bipolar( setup->dev, setup->ad_subdev, channel, range ) ) + sc_push_range( current_cal, range ); + postgain_bip = setup->caldacs[ layout->adc_postgain_offset( channel ) ].current; + current_cal++; + /* unipolar postgain */ + generic_do_adc_postgain_offset( setup, layout, current_cal, channel, 1 ); + for( range = 0; range < num_ai_ranges; range++ ) + if( is_unipolar( setup->dev, setup->ad_subdev, channel, range ) ) + sc_push_range( current_cal, range ); + postgain_unip = setup->caldacs[ layout->adc_postgain_offset( channel ) ].current; + current_cal++; + }else + postgain_bip = postgain_unip = -1; + for( range = 0; range < num_ai_ranges; range++ ) { + generic_prep_adc_caldacs( setup, layout, channel, range ); + if( is_unipolar( setup->dev, setup->ad_subdev, channel, range ) ) + update_caldac( setup, layout->adc_postgain_offset( channel ), postgain_bip ); + else + update_caldac( setup, layout->adc_postgain_offset( channel ), postgain_unip ); generic_do_adc_channel( setup, layout, current_cal, channel, range ); current_cal++; } @@ -269,6 +315,7 @@ int generic_cal_by_channel_and_range( calibration_setup_t *setup, { for( range = 0; range < num_ao_ranges; range++ ) { + generic_prep_dac_caldacs( setup, layout, channel, range ); generic_do_dac_channel( setup, layout, saved_cals, num_ai_calibrations, current_cal, channel, range ); current_cal++; @@ -288,6 +335,7 @@ int generic_cal_by_range( calibration_setup_t *setup, int channel, range, num_ai_ranges, num_ao_ranges, num_ao_channels, retval, num_calibrations, i; saved_calibration_t *saved_cals, *current_cal; + int postgain_bip, postgain_unip; assert( comedi_range_is_chan_specific( setup->dev, setup->ad_subdev ) == 0 ); @@ -307,14 +355,41 @@ int generic_cal_by_range( calibration_setup_t *setup, num_ao_ranges = num_ao_channels = 0; num_calibrations = num_ai_ranges + num_ao_ranges * num_ao_channels; - + if( layout->adc_postgain_offset( 0 ) >= 0 ) + num_calibrations += 2; saved_cals = malloc( num_calibrations * sizeof( saved_calibration_t ) ); if( saved_cals == NULL ) return -1; current_cal = saved_cals; + if( layout->adc_postgain_offset( 0 ) >= 0 ) + { + /* bipolar postgain */ + generic_do_adc_postgain_offset( setup, layout, current_cal, 0, 0 ); + sc_push_channel( current_cal, SC_ALL_CHANNELS ); + for( range = 0; range < num_ai_ranges; range++ ) + if( is_bipolar( setup->dev, setup->ad_subdev, 0, range ) ) + sc_push_range( current_cal, range ); + postgain_bip = setup->caldacs[ layout->adc_postgain_offset( 0 ) ].current; + current_cal++; + /* unipolar postgain */ + generic_do_adc_postgain_offset( setup, layout, current_cal, 0, 1 ); + sc_push_channel( current_cal, SC_ALL_CHANNELS ); + for( range = 0; range < num_ai_ranges; range++ ) + if( is_unipolar( setup->dev, setup->ad_subdev, 0, range ) ) + sc_push_range( current_cal, range ); + postgain_unip = setup->caldacs[ layout->adc_postgain_offset( 0 ) ].current; + current_cal++; + }else + postgain_bip = postgain_unip = -1; + for( range = 0; range < num_ai_ranges; range++ ) { + generic_prep_adc_caldacs( setup, layout, 0, range ); + if( is_unipolar( setup->dev, setup->ad_subdev, 0, range ) ) + update_caldac( setup, layout->adc_postgain_offset( 0 ), postgain_bip ); + else + update_caldac( setup, layout->adc_postgain_offset( 0 ), postgain_unip ); generic_do_adc_channel( setup, layout, current_cal, 0, range ); sc_push_channel( current_cal, SC_ALL_CHANNELS ); current_cal++; @@ -323,6 +398,7 @@ int generic_cal_by_range( calibration_setup_t *setup, { for( range = 0; range < num_ao_ranges; range++ ) { + generic_prep_dac_caldacs( setup, layout, channel, range ); generic_do_dac_channel( setup, layout, saved_cals, num_ai_ranges, current_cal, channel, range ); current_cal++; diff --git a/comedi_calibrate/calib.h b/comedi_calibrate/calib.h index 07c793b..38efe55 100644 --- a/comedi_calibrate/calib.h +++ b/comedi_calibrate/calib.h @@ -27,7 +27,7 @@ #define DPRINT(level,fmt,args...) do{if(verbose>=level)printf(fmt, ## args);}while(0) #define N_CALDACS 64 -#define N_OBSERVABLES 32 +#define N_OBSERVABLES 64 #define PREOBSERVE_DATA_LEN 10 typedef struct{ @@ -109,7 +109,7 @@ int cb64_setup( calibration_setup_t*, const char *device_name ); /* low level */ void set_target( calibration_setup_t *setup, int obs,double target); -void update_caldac( calibration_setup_t *setup, unsigned int caldac_index, int value ); +void update_caldac( calibration_setup_t *setup, int caldac_index, int value ); void setup_caldacs( calibration_setup_t *setup, int caldac_subdev); void postgain_cal( calibration_setup_t *setup, int obs1, int obs2, int dac); void cal1( calibration_setup_t *setup, int obs, int dac); diff --git a/comedi_calibrate/cb.c b/comedi_calibrate/cb.c index 11f6296..39cd54f 100644 --- a/comedi_calibrate/cb.c +++ b/comedi_calibrate/cb.c @@ -127,7 +127,7 @@ static int setup_cb_pci_1602_16( calibration_setup_t *setup ) static const int calpot_subdev = 5; static const int dac08_subdev = 6; - init_observables_1602_16( setup ); + init_observables_1xxx( setup ); setup_caldacs( setup, caldac_subdev ); setup_caldacs( setup, calpot_subdev ); setup_caldacs( setup, dac08_subdev ); @@ -474,6 +474,72 @@ static int cal_cb_pci_1xxx( calibration_setup_t *setup ) return generic_cal_by_range( setup, &layout ); } +enum cal_knobs_1602_16 +{ + DAC0_GAIN_FINE_1602_16 = 0, + DAC0_GAIN_COARSE_1602_16 = 1, + DAC0_OFFSET_COARSE_1602_16 = 2, + DAC1_OFFSET_COARSE_1602_16 = 3, + DAC1_GAIN_FINE_1602_16 = 4, + DAC1_GAIN_COARSE_1602_16 = 5, + DAC0_OFFSET_FINE_1602_16 = 6, + DAC1_OFFSET_FINE_1602_16 = 7, + ADC_GAIN_1602_16 = 8, + ADC_POSTGAIN_OFFSET_1602_16 = 9, + ADC_PREGAIN_OFFSET_1602_16 = 10, +}; +static int dac_gain_coarse_1602_16( unsigned int channel ) +{ + if( channel ) return DAC1_GAIN_COARSE_1602_16; + else return DAC0_GAIN_COARSE_1602_16; +} +static int dac_gain_fine_1602_16( unsigned int channel ) +{ + if( channel ) return DAC1_GAIN_FINE_1602_16; + else return DAC0_GAIN_FINE_1602_16; +} +static int dac_offset_coarse_1602_16( unsigned int channel ) +{ + if( channel ) return DAC1_OFFSET_COARSE_1602_16; + else return DAC0_OFFSET_COARSE_1602_16; +} +static int dac_offset_fine_1602_16( unsigned int channel ) +{ + if( channel ) return DAC1_OFFSET_FINE_1602_16; + else return DAC0_OFFSET_FINE_1602_16; +} +static int adc_gain_1602_16( unsigned int channel ) +{ + return ADC_GAIN_1602_16; +} +static int adc_pregain_offset_1602_16( unsigned int channel ) +{ + return ADC_PREGAIN_OFFSET_1602_16; +} +static int adc_postgain_offset_1602_16( unsigned int channel ) +{ + return ADC_POSTGAIN_OFFSET_1602_16; +} +static int cal_cb_pci_1602_16( calibration_setup_t *setup ) +{ + generic_layout_t layout; + + init_generic_layout( &layout ); + layout.adc_gain = adc_gain_1602_16; + layout.adc_offset = adc_pregain_offset_1602_16; + layout.adc_postgain_offset = adc_postgain_offset_1602_16; + layout.dac_gain = dac_gain_coarse_1602_16; + layout.dac_gain_fine = dac_gain_fine_1602_16; + layout.dac_offset = dac_offset_coarse_1602_16; + layout.dac_offset_fine = dac_offset_fine_1602_16; + layout.adc_high_observable = ai_high_observable_1xxx; + layout.adc_ground_observable = ai_ground_observable_1xxx; + layout.dac_high_observable = ao_high_observable_1xxx; + layout.dac_ground_observable = ao_ground_observable_1xxx; + return generic_cal_by_range( setup, &layout ); +} + +#if 0 static int cal_cb_pci_1602_16( calibration_setup_t *setup ) { enum cal_knobs_1602_16 @@ -497,6 +563,7 @@ static int cal_cb_pci_1602_16( calibration_setup_t *setup ) return 0; } +#endif // converts calibration source voltages from two 16 bit eeprom values to a floating point value static float eeprom16_to_source( uint16_t *data ) diff --git a/comedi_calibrate/comedi_calibrate.c b/comedi_calibrate/comedi_calibrate.c index 1fd2289..e4714dd 100644 --- a/comedi_calibrate/comedi_calibrate.c +++ b/comedi_calibrate/comedi_calibrate.c @@ -810,12 +810,13 @@ void reset_caldacs( calibration_setup_t *setup ) } } -void update_caldac( calibration_setup_t *setup, unsigned int caldac_index, +void update_caldac( calibration_setup_t *setup, int caldac_index, int value ) { int ret; caldac_t *dac; + if( caldac_index < 0 ) return; if( caldac_index > setup->n_caldacs ) { fprintf( stderr, "invalid caldac index\n" ); -- 2.26.2