From: Frank Mori Hess Date: Sun, 12 May 2002 03:07:20 +0000 (+0000) Subject: got rid of some global variables X-Git-Tag: r0_7_19~42 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=137fdba9885c7a0dce8b98b6a9532e901e63271b;p=comedilib.git got rid of some global variables --- diff --git a/comedi_calibrate/calib.h b/comedi_calibrate/calib.h index b85f9f1..eba7788 100644 --- a/comedi_calibrate/calib.h +++ b/comedi_calibrate/calib.h @@ -45,24 +45,17 @@ typedef struct{ double target; }observable; -typedef struct calibration_setup_struct calibration_setup; +typedef struct calibration_setup_struct calibration_setup_t; struct calibration_setup_struct { + comedi_t *dev; int status; - observable *observables; + observable observables[ N_OBSERVABLES ]; unsigned int n_observables; - caldac *caldacs; + caldac caldacs[ N_CALDACS ]; unsigned int n_caldacs; - int (*do_cal) ( calibration_setup *setup ); + int (*do_cal) ( calibration_setup_t *setup ); }; -extern caldac caldacs[N_CALDACS]; -extern int n_caldacs; - -extern observable observables[N_OBSERVABLES]; -extern int n_observables; - -extern comedi_t *dev; - extern int ad_subdev; extern int da_subdev; extern int eeprom_subdev; @@ -79,44 +72,43 @@ enum { STATUS_SOME, STATUS_DONE }; -extern int device_status; extern int do_output; /* high level */ -void observe(void); -void preobserve(int obs); -void observable_dependence(int obs); -void measure_observable(int obs); -void reset_caldacs( const calibration_setup *setup); +void observe( calibration_setup_t *setup ); +void preobserve( calibration_setup_t *setup, int obs); +void observable_dependence( calibration_setup_t *setup, int obs); +void measure_observable( calibration_setup_t *setup, int obs); +void reset_caldacs( calibration_setup_t *setup); /* drivers */ extern char ni_id[]; extern char cb_id[]; -int ni_setup( calibration_setup*, const char *device_name ); -int cb_setup( calibration_setup*, const char *device_name ); +int ni_setup( calibration_setup_t*, const char *device_name ); +int cb_setup( calibration_setup_t*, const char *device_name ); /* low level */ -void set_target(int obs,double target); -void update_caldac( caldac ); -void setup_caldacs(void); -void postgain_cal(int obs1, int obs2, int dac); -void cal1(int obs, int dac); -void cal1_fine(int obs, int dac); +void set_target( calibration_setup_t *setup, int obs,double target); +void update_caldac( calibration_setup_t *setup, unsigned int caldac_index ); +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); +void cal1_fine( calibration_setup_t *setup, int obs, int dac); /* misc and temp */ void channel_dependence(int adc,int range); void caldac_dependence(int caldac); void chan_cal(int adc,int caldac,int range,double target); -int read_eeprom(int addr); +int read_eeprom( calibration_setup_t *setup, int addr); -double read_chan(int adc,int range); -int read_chan2(char *s,int adc,int range); +double read_chan( calibration_setup_t *setup, int adc,int range); +int read_chan2( calibration_setup_t *setup, char *s,int adc,int range); void set_ao(comedi_t *dev,int subdev,int chan,int range,double value); void check_gain(int ad_chan,int range); double check_gain_chan(int ad_chan,int range,int cdac); @@ -166,8 +158,8 @@ typedef struct { int linear_fit_monotonic(linear_fit_t *l); double linear_fit_func_y(linear_fit_t *l,double x); double linear_fit_func_x(linear_fit_t *l,double y); -double check_gain_chan_x(linear_fit_t *l,unsigned int ad_chanspec,int cdac); -double check_gain_chan_fine(linear_fit_t *l,unsigned int ad_chanspec,int cdac); +double check_gain_chan_x( calibration_setup_t *setup, linear_fit_t *l,unsigned int ad_chanspec,int cdac); +double check_gain_chan_fine( calibration_setup_t *setup, linear_fit_t *l,unsigned int ad_chanspec,int cdac); void dump_curve(linear_fit_t *l); /* slowly varying measurements */ @@ -191,7 +183,7 @@ typedef struct{ double error; }new_sv_t; -int new_sv_measure(new_sv_t *sv); +int new_sv_measure(comedi_t *dev, new_sv_t *sv); int new_sv_init(new_sv_t *sv,comedi_t *dev,int subdev,int chan,int range,int aref); diff --git a/comedi_calibrate/cb.c b/comedi_calibrate/cb.c index 720cebc..f65b88c 100644 --- a/comedi_calibrate/cb.c +++ b/comedi_calibrate/cb.c @@ -39,23 +39,23 @@ char cb_id[] = "$Id$"; struct board_struct{ char *name; int status; - int (*setup)( calibration_setup *setup ); + int (*setup)( calibration_setup_t *setup ); }; int cb_setup_board(void); void cb_setup_observables(void); -int setup_cb_pci_64xx( calibration_setup *setup ); -int setup_cb_pci_60xx( calibration_setup *setup ); -int setup_cb_pci_4020( calibration_setup *setup ); +int setup_cb_pci_64xx( calibration_setup_t *setup ); +int setup_cb_pci_60xx( calibration_setup_t *setup ); +int setup_cb_pci_4020( calibration_setup_t *setup ); -int cal_cb_pci_64xx( calibration_setup *setup ); -int cal_cb_pci_60xx( calibration_setup *setup ); -int cal_cb_pci_4020( calibration_setup *setup ); +int cal_cb_pci_64xx( calibration_setup_t *setup ); +int cal_cb_pci_60xx( calibration_setup_t *setup ); +int cal_cb_pci_4020( calibration_setup_t *setup ); -int init_observables_64xx( calibration_setup *setup ); -int init_observables_60xx( calibration_setup *setup ); -int init_observables_4020( calibration_setup *setup ); +int init_observables_64xx( calibration_setup_t *setup ); +int init_observables_60xx( calibration_setup_t *setup ); +int init_observables_4020( calibration_setup_t *setup ); static struct board_struct boards[]={ { "pci-das6402/16", STATUS_DONE, setup_cb_pci_64xx }, @@ -82,7 +82,7 @@ enum { cb_ao1_reference, }; -int cb_setup( calibration_setup *setup, const char *device_name ) +int cb_setup( calibration_setup_t *setup, const char *device_name ) { unsigned int i; @@ -98,53 +98,99 @@ int cb_setup( calibration_setup *setup, const char *device_name ) return 0; } -int setup_cb_pci_64xx( calibration_setup *setup ) +int setup_cb_pci_64xx( calibration_setup_t *setup ) { + static const int caldac_subdev = 6; + static const int calpot_subdev = 7; + init_observables_64xx( setup ); + setup_caldacs( setup, caldac_subdev ); + setup_caldacs( setup, calpot_subdev ); setup->do_cal = cal_cb_pci_64xx; return 0; } -int setup_cb_pci_60xx( calibration_setup *setup ) +int setup_cb_pci_60xx( calibration_setup_t *setup ) { + static const int caldac_subdev = 6; + init_observables_60xx( setup ); + setup_caldacs( setup, caldac_subdev ); setup->do_cal = cal_cb_pci_60xx; return 0; } -int setup_cb_pci_4020( calibration_setup *setup ) +int setup_cb_pci_4020( calibration_setup_t *setup ) { + static const int caldac_subdev = 6; + init_observables_4020( setup ); + setup_caldacs( setup, caldac_subdev ); setup->do_cal = cal_cb_pci_60xx; return 0; } -int init_observables_64xx( calibration_setup *setup ) +int init_observables_64xx( calibration_setup_t *setup ) { return 0; } -int init_observables_60xx( calibration_setup *setup ) +int init_observables_60xx( calibration_setup_t *setup ) { + comedi_insn tmpl, po_tmpl; + observable *o; + static const int ai_subdev = 0; + lsampl_t cal_src_data[2]; + + memset( &po_tmpl, 0, sizeof(po_tmpl) ); + po_tmpl.insn = INSN_CONFIG; + po_tmpl.n = 2; + po_tmpl.subdev = ai_subdev; + po_tmpl.data = cal_src_data; + cal_src_data[0] = INSN_CONFIG_ALT_SOURCE; + + memset( &tmpl, 0, sizeof(tmpl) ); + tmpl.insn = INSN_READ; + tmpl.n = 1; + tmpl.subdev = ai_subdev; + + o = setup->observables + 0; + o->name = "ground calibration source, 10V bipolar range, ground reference"; + o->preobserve_insn = po_tmpl; + o->preobserve_insn.data[1] = 0; + o->observe_insn = tmpl; + o->observe_insn.chanspec = CR_PACK_FLAGS( 0, 0, AREF_GROUND, CR_ALT_SOURCE); + o->target = 0.0; + + o = setup->observables + 1; + o->name = "5V calibration source, 10V bipolar range, ground reference"; + o->preobserve_insn = po_tmpl; + o->preobserve_insn.data[1] = 2; + o->observe_insn = tmpl; + o->observe_insn.chanspec = CR_PACK_FLAGS( 0, 0, AREF_GROUND, CR_ALT_SOURCE); + o->target = 5.0; + + setup->n_observables = 2; + return 0; } -int init_observables_4020( calibration_setup *setup ) +int init_observables_4020( calibration_setup_t *setup ) { return 0; } -int cal_cb_pci_64xx( calibration_setup *setup ) +int cal_cb_pci_64xx( calibration_setup_t *setup ) { return 0; } -int cal_cb_pci_60xx( calibration_setup *setup ) +int cal_cb_pci_60xx( calibration_setup_t *setup ) { return 0; } -int cal_cb_pci_4020( calibration_setup *setup ) +int cal_cb_pci_4020( calibration_setup_t *setup ) { return 0; } diff --git a/comedi_calibrate/comedi_calibrate.c b/comedi_calibrate/comedi_calibrate.c index 76a3c39..23e1317 100644 --- a/comedi_calibrate/comedi_calibrate.c +++ b/comedi_calibrate/comedi_calibrate.c @@ -37,14 +37,6 @@ /* global variables */ -caldac caldacs[N_CALDACS]; -int n_caldacs; - -observable observables[N_OBSERVABLES]; -int n_observables; - -comedi_t *dev; - int ad_subdev; int da_subdev; int eeprom_subdev; @@ -61,7 +53,7 @@ int verbose = 0; struct board_struct{ char *name; char *id; - int (*setup)( calibration_setup *setup, const char *device_name ); + int (*init_setup)( calibration_setup_t *setup, const char *device_name ); }; struct board_struct drivers[] = { @@ -105,7 +97,8 @@ int main(int argc, char *argv[]) struct board_struct *this_board; int index; int device_status = STATUS_UNKNOWN; - calibration_setup setup; + calibration_setup_t setup; + comedi_t *dev; fn = "/dev/comedi0"; while (1) { @@ -162,7 +155,8 @@ int main(int argc, char *argv[]) ok: memset( &setup, 0, sizeof( setup ) ); - this_board->setup( &setup, devicename ); + setup.dev = dev; + this_board->init_setup( &setup, devicename ); device_status = setup.status; if(device_statusdev, setup->observables[obs].preobserve_insn.subdev, + CR_CHAN( setup->observables[obs].preobserve_insn.chanspec ), + CR_RANGE( setup->observables[obs].preobserve_insn.chanspec )); + maxdata = comedi_get_maxdata( setup->dev, setup->observables[obs].preobserve_insn.subdev, + CR_CHAN(setup->observables[obs].preobserve_insn.chanspec)); data = comedi_from_phys(target,range,maxdata); - observables[obs].preobserve_data = data; - observables[obs].target = comedi_to_phys(data,range,maxdata); + setup->observables[obs].preobserve_data = data; + setup->observables[obs].target = comedi_to_phys(data,range,maxdata); } -void observe(void) +void observe( calibration_setup_t *setup ) { int i; - for(i=0;in_observables; i++){ + preobserve( setup, i); + DPRINT(0,"%s\n", setup->observables[i].name); + measure_observable( setup, i); if(verbose>=1){ - observable_dependence(i); + observable_dependence( setup, i); } } } -void preobserve(int obs) +void preobserve( calibration_setup_t *setup, int obs) { - if(observables[obs].preobserve_insn.n!=0){ - comedi_do_insn(dev,&observables[obs].preobserve_insn); + if( setup->observables[obs].preobserve_insn.n != 0){ + comedi_do_insn( setup->dev, &setup->observables[obs].preobserve_insn); } } -void measure_observable(int obs) +void measure_observable( calibration_setup_t *setup, int obs) { char s[32]; int n; new_sv_t sv; - new_sv_init(&sv,dev, - observables[obs].observe_insn.subdev, - CR_CHAN(observables[obs].observe_insn.chanspec), - CR_RANGE(observables[obs].observe_insn.chanspec), - CR_AREF(observables[obs].observe_insn.chanspec)); + new_sv_init(&sv, setup->dev, + setup->observables[obs].observe_insn.subdev, + CR_CHAN( setup->observables[obs].observe_insn.chanspec), + CR_RANGE( setup->observables[obs].observe_insn.chanspec), + CR_AREF( setup->observables[obs].observe_insn.chanspec)); sv.order=7; // read internal calibration source and turn on dithering sv.cr_flags = CR_ALT_FILTER | CR_ALT_SOURCE; - n = new_sv_measure(&sv); + n = new_sv_measure(setup->dev, &sv); sci_sprint_alt(s,sv.average,sv.error); - DPRINT(0,"offset %s, target %g\n",s,observables[obs].target); + DPRINT(0,"offset %s, target %g\n",s, setup->observables[obs].target); } -void observable_dependence(int obs) +void observable_dependence(calibration_setup_t *setup, int obs) { int i; linear_fit_t l; - for(i=0;in_caldacs; i++){ + check_gain_chan_x( setup, &l, + setup->observables[obs].observe_insn.chanspec, i); } } -void postgain_cal(int obs1, int obs2, int dac) +void postgain_cal( calibration_setup_t *setup, int obs1, int obs2, int dac) { double offset1,offset2; linear_fit_t l; @@ -290,24 +284,24 @@ void postgain_cal(int obs1, int obs2, int dac) double gain; comedi_range *range1,*range2; - DPRINT(0,"postgain: %s; %s\n",observables[obs1].name, - observables[obs2].name); - preobserve(obs1); - check_gain_chan_x(&l,observables[obs1].observe_insn.chanspec,dac); - offset1=linear_fit_func_y(&l,caldacs[dac].current); + DPRINT(0,"postgain: %s; %s\n", setup->observables[obs1].name, + setup->observables[obs2].name); + preobserve(setup, obs1); + check_gain_chan_x( setup, &l, setup->observables[obs1].observe_insn.chanspec, dac); + offset1=linear_fit_func_y(&l, setup->caldacs[dac].current); DPRINT(2,"obs1: [%d] offset %g\n",obs1,offset1); - range1 = comedi_get_range(dev,observables[obs1].observe_insn.subdev, - CR_CHAN(observables[obs1].observe_insn.chanspec), - CR_RANGE(observables[obs1].observe_insn.chanspec)); + range1 = comedi_get_range(setup->dev, setup->observables[obs1].observe_insn.subdev, + CR_CHAN( setup->observables[obs1].observe_insn.chanspec), + CR_RANGE( setup->observables[obs1].observe_insn.chanspec)); slope1=l.slope; - preobserve(obs2); - check_gain_chan_x(&l,observables[obs2].observe_insn.chanspec,dac); - offset2=linear_fit_func_y(&l,caldacs[dac].current); + preobserve( setup, obs2); + check_gain_chan_x( setup, &l, setup->observables[obs2].observe_insn.chanspec,dac); + offset2=linear_fit_func_y(&l, setup->caldacs[dac].current); DPRINT(2,"obs2: [%d] offset %g\n",obs2,offset2); - range2 = comedi_get_range(dev,observables[obs2].observe_insn.subdev, - CR_CHAN(observables[obs2].observe_insn.chanspec), - CR_RANGE(observables[obs2].observe_insn.chanspec)); + range2 = comedi_get_range(setup->dev, setup->observables[obs2].observe_insn.subdev, + CR_CHAN( setup->observables[obs2].observe_insn.chanspec), + CR_RANGE( setup->observables[obs2].observe_insn.chanspec)); slope2=l.slope; gain = (range1->max-range1->min)/(range2->max-range2->min); @@ -318,59 +312,59 @@ void postgain_cal(int obs1, int obs2, int dac) DPRINT(3,"difference: %g\n",offset2-offset1); a = (offset1-offset2)/(slope1-slope2); - a=caldacs[dac].current-a; + a=setup->caldacs[dac].current-a; - caldacs[dac].current=rint(a); - update_caldac( caldacs[dac] ); + setup->caldacs[dac].current=rint(a); + update_caldac( setup, dac ); usleep(100000); DPRINT(0,"caldac[%d] set to %g (%g)\n",dac,rint(a),a); if(verbose>=2){ - preobserve(obs1); - measure_observable(obs1); - preobserve(obs2); - measure_observable(obs2); + preobserve( setup, obs1); + measure_observable( setup, obs1); + preobserve( setup, obs2); + measure_observable( setup, obs2); } } -void cal1(int obs, int dac) +void cal1( calibration_setup_t *setup, int obs, int dac) { linear_fit_t l; double a; - DPRINT(0,"linear: %s\n",observables[obs].name); - preobserve(obs); - check_gain_chan_x(&l,observables[obs].observe_insn.chanspec,dac); - a=linear_fit_func_x(&l,observables[obs].target); + DPRINT(0,"linear: %s\n", setup->observables[obs].name); + preobserve( setup, obs); + check_gain_chan_x( setup, &l, setup->observables[obs].observe_insn.chanspec,dac); + a=linear_fit_func_x(&l, setup->observables[obs].target); - caldacs[dac].current=rint(a); - update_caldac( caldacs[dac] ); + setup->caldacs[dac].current=rint(a); + update_caldac( setup, dac ); usleep(100000); DPRINT(0,"caldac[%d] set to %g (%g)\n",dac,rint(a),a); if(verbose>=3){ - measure_observable(obs); + measure_observable( setup, obs); } } -void cal1_fine(int obs, int dac) +void cal1_fine( calibration_setup_t *setup, int obs, int dac ) { linear_fit_t l; double a; - DPRINT(0,"linear fine: %s\n",observables[obs].name); - preobserve(obs); - check_gain_chan_fine(&l,observables[obs].observe_insn.chanspec,dac); - a=linear_fit_func_x(&l,observables[obs].target); + DPRINT(0,"linear fine: %s\n", setup->observables[obs].name); + preobserve( setup, obs); + check_gain_chan_fine( setup, &l, setup->observables[obs].observe_insn.chanspec,dac); + a=linear_fit_func_x(&l,setup->observables[obs].target); - caldacs[dac].current=rint(a); - update_caldac( caldacs[dac] ); + setup->caldacs[dac].current=rint(a); + update_caldac( setup, dac ); usleep(100000); DPRINT(0,"caldac[%d] set to %g (%g)\n",dac,rint(a),a); if(verbose>=3){ - measure_observable(obs); + measure_observable( setup, obs); } } @@ -390,7 +384,7 @@ void chan_cal(int adc,int cdac,int range,double target) a=caldacs[cdac].current+(target-offset)/gain; caldacs[cdac].current=rint(a); - update_caldac(cdac); + update_caldac( setup, cdac); read_chan2(s,adc,range); DPRINT(1,"caldac[%d] set to %g, offset=%s\n",cdac,a,s); @@ -423,54 +417,63 @@ void caldac_dependence(int caldac) #endif -void setup_caldacs(void) +void setup_caldacs( calibration_setup_t *setup, int caldac_subdev ) { - int n_chan,i; + int n_chan, i; - if(caldac_subdev<0){ + if( caldac_subdev < 0 ){ printf("no calibration subdevice\n"); return; } - n_chan=comedi_get_n_channels(dev,caldac_subdev); + // XXX check subdevice type is really calibration + // XXX check we dont exceed max number of allowable caldacs - for(i=0;idev, caldac_subdev ); + + for(i = 0; i < n_chan; i++){ + setup->caldacs[ setup->n_caldacs + i ].subdev = caldac_subdev; + setup->caldacs[ setup->n_caldacs + i ].chan = i; + setup->caldacs[ setup->n_caldacs + i ].maxdata = comedi_get_maxdata( setup->dev, caldac_subdev, i); + setup->caldacs[ setup->n_caldacs + i ].current=0; } - n_caldacs=n_chan; + setup->n_caldacs += n_chan; } -void reset_caldacs( const calibration_setup *setup ) +void reset_caldacs( calibration_setup_t *setup ) { int i; for( i = 0; i < setup->n_caldacs; i++){ setup->caldacs[i].current = setup->caldacs[i].maxdata / 2; - update_caldac( setup->caldacs[i] ); + update_caldac( setup, i ); } } -void update_caldac( caldac dac ) +void update_caldac( calibration_setup_t *setup, unsigned int caldac_index ) { int ret; + caldac *dac = &setup->caldacs[ caldac_index ]; - DPRINT(4,"update %d %d %d\n", dac.subdev, dac.chan, dac.current); - if( dac.current < 0 ){ - DPRINT(1,"caldac set out of range (%d<0)\n", dac.current); - dac.current = 0; + if( caldac_index > setup->n_caldacs ) + { + fprintf( stderr, "invalid caldac index\n" ); + return; + } + DPRINT(4,"update %d %d %d\n", dac->subdev, dac->chan, dac->current); + if( dac->current < 0 ){ + DPRINT(1,"caldac set out of range (%d<0)\n", dac->current); + dac->current = 0; } - if( dac.current > dac.maxdata ){ + if( dac->current > dac->maxdata ){ DPRINT(1,"caldac set out of range (%d>%d)\n", - dac.current, dac.maxdata); - dac.current = dac.maxdata; + dac->current, dac->maxdata); + dac->current = dac->maxdata; } - ret = comedi_data_write(dev, dac.subdev, dac.chan, 0, 0, - dac.current); + ret = comedi_data_write( setup->dev, dac->subdev, dac->chan, 0, 0, + dac->current); if(ret < 0) perror("update_caldac()"); } @@ -495,7 +498,7 @@ double check_gain_chan(int ad_chan,int range,int cdac) #endif -double check_gain_chan_x(linear_fit_t *l,unsigned int ad_chanspec,int cdac) +double check_gain_chan_x( calibration_setup_t *setup, linear_fit_t *l,unsigned int ad_chanspec,int cdac) { int orig,i,n; int step; @@ -504,7 +507,7 @@ double check_gain_chan_x(linear_fit_t *l,unsigned int ad_chanspec,int cdac) int sum_err_count=0; char str[20]; - n=caldacs[cdac].maxdata+1; + n = setup->caldacs[cdac].maxdata+1; memset(l,0,sizeof(*l)); step=n/256; @@ -518,28 +521,28 @@ double check_gain_chan_x(linear_fit_t *l,unsigned int ad_chanspec,int cdac) exit(1); } - orig=caldacs[cdac].current; + orig = setup->caldacs[cdac].current; - new_sv_init(&sv,dev,0, + new_sv_init(&sv, setup->dev,0, CR_CHAN(ad_chanspec), CR_RANGE(ad_chanspec), CR_AREF(ad_chanspec)); // read internal calibration source and turn on dithering sv.cr_flags = CR_ALT_FILTER | CR_ALT_SOURCE; - caldacs[cdac].current=0; - update_caldac( caldacs[cdac] ); + setup->caldacs[cdac].current=0; + update_caldac( setup, cdac ); usleep(100000); - new_sv_measure(&sv); + new_sv_measure( setup->dev, &sv); sum_err=0; for(i=0;i*stepcaldacs[cdac].current=i*step; + update_caldac( setup, cdac ); //usleep(100000); - new_sv_measure(&sv); + new_sv_measure( setup->dev, &sv); l->y_data[i]=sv.average; if(!isnan(sv.average)){ @@ -549,8 +552,8 @@ double check_gain_chan_x(linear_fit_t *l,unsigned int ad_chanspec,int cdac) l->n++; } - caldacs[cdac].current=orig; - update_caldac( caldacs[cdac] ); + setup->caldacs[cdac].current=orig; + update_caldac( setup, cdac ); l->yerr=sum_err/sum_err_count; l->dx=step; @@ -573,7 +576,7 @@ double check_gain_chan_x(linear_fit_t *l,unsigned int ad_chanspec,int cdac) } -double check_gain_chan_fine(linear_fit_t *l,unsigned int ad_chanspec,int cdac) +double check_gain_chan_fine( calibration_setup_t *setup, linear_fit_t *l,unsigned int ad_chanspec,int cdac) { int orig,i,n; int step; @@ -596,28 +599,28 @@ double check_gain_chan_fine(linear_fit_t *l,unsigned int ad_chanspec,int cdac) exit(1); } - orig=caldacs[cdac].current; + orig = setup->caldacs[cdac].current; - new_sv_init(&sv,dev,0, + new_sv_init(&sv, setup->dev,0, CR_CHAN(ad_chanspec), CR_RANGE(ad_chanspec), CR_AREF(ad_chanspec)); // read internal calibration source and turn on dithering sv.cr_flags = CR_ALT_FILTER | CR_ALT_SOURCE; - caldacs[cdac].current=0; - update_caldac( caldacs[cdac] ); + setup->caldacs[cdac].current=0; + update_caldac( setup, cdac ); usleep(100000); - new_sv_measure(&sv); + new_sv_measure( setup->dev, &sv); sum_err=0; for(i=0;icaldacs[cdac].current=i+orig-fine_size; + update_caldac( setup, cdac ); usleep(100000); - new_sv_measure(&sv); + new_sv_measure( setup->dev, &sv); l->y_data[i]=sv.average; if(!isnan(sv.average)){ @@ -627,8 +630,8 @@ double check_gain_chan_fine(linear_fit_t *l,unsigned int ad_chanspec,int cdac) l->n++; } - caldacs[cdac].current=orig; - update_caldac( caldacs[cdac] ); + setup->caldacs[cdac].current=orig; + update_caldac( setup, cdac ); l->yerr=sum_err/sum_err_count; l->dx=1; @@ -717,26 +720,26 @@ int get_unipolar_lowgain(comedi_t *dev,int subdev) } -int read_eeprom(int addr) +int read_eeprom( calibration_setup_t *setup, int addr) { unsigned int data=0; - comedi_data_read(dev,eeprom_subdev,addr,0,0,&data); + comedi_data_read( setup->dev, eeprom_subdev, addr,0,0,&data); return data; } -double read_chan(int adc,int range) +double read_chan( calibration_setup_t *setup, int adc,int range) { int n; new_sv_t sv; char str[20]; - new_sv_init(&sv,dev,0,adc,range,AREF_OTHER); + new_sv_init(&sv, setup->dev, 0,adc,range,AREF_OTHER); sv.order=7; sv.cr_flags = CR_ALT_FILTER; - n=new_sv_measure(&sv); + n=new_sv_measure( setup->dev, &sv); sci_sprint_alt(str,sv.average,sv.error); printf("chan=%d ave=%s\n",adc,str); @@ -744,17 +747,17 @@ double read_chan(int adc,int range) return sv.average; } -int read_chan2(char *s,int adc,int range) +int read_chan2( calibration_setup_t *setup, char *s,int adc,int range) { int n; new_sv_t sv; - new_sv_init(&sv,dev,0,adc,range,AREF_OTHER); + new_sv_init(&sv, setup->dev,0,adc,range,AREF_OTHER); sv.order=7; // turn on dithering sv.cr_flags = CR_ALT_FILTER; - n=new_sv_measure(&sv); + n=new_sv_measure( setup->dev, &sv); return sci_sprint_alt(s,sv.average,sv.error); } @@ -793,7 +796,7 @@ int new_sv_init(new_sv_t *sv,comedi_t *dev,int subdev,int chan,int range,int are return 0; } -int new_sv_measure(new_sv_t *sv) +int new_sv_measure( comedi_t *dev, new_sv_t *sv) { lsampl_t *data; int n,i,ret; @@ -836,7 +839,7 @@ out: return ret; } -int new_sv_measure_order(new_sv_t *sv,int order) +int new_sv_measure_order( comedi_t *dev, new_sv_t *sv,int order) { lsampl_t *data; int n,i,ret; diff --git a/comedi_calibrate/ni.c b/comedi_calibrate/ni.c index 6de1817..f789f70 100644 --- a/comedi_calibrate/ni.c +++ b/comedi_calibrate/ni.c @@ -41,27 +41,27 @@ char ni_id[] = "$Id$"; struct board_struct{ char *name; int status; - int (*cal)( calibration_setup *setup); + int (*cal)( calibration_setup_t *setup); }; -int ni_setup_board( calibration_setup *setup , const char *device_name ); -void ni_setup_observables(void); - -int cal_ni_at_mio_16e_2(calibration_setup *setup); -int cal_ni_daqcard_ai_16xe_50(calibration_setup *setup); -int cal_ni_at_mio_16e_1(calibration_setup *setup); -int cal_ni_pci_mio_16e_1(calibration_setup *setup); -int cal_ni_pci_6025e(calibration_setup *setup); -int cal_ni_pci_6035e(calibration_setup *setup); -int cal_ni_pci_6071e(calibration_setup *setup); -int cal_ni_pxi_6071e(calibration_setup *setup); -int cal_ni_at_mio_16e_10(calibration_setup *setup); -int cal_ni_pci_mio_16xe_50(calibration_setup *setup); -int cal_ni_pci_6023e(calibration_setup *setup); -int cal_ni_pci_6024e(calibration_setup *setup); -int cal_ni_at_mio_16xe_50(calibration_setup *setup); -int cal_ni_pci_mio_16xe_10(calibration_setup *setup); -int cal_ni_pci_6052e(calibration_setup *setup); +int ni_setup_board( calibration_setup_t *setup , const char *device_name ); +void ni_setup_observables( calibration_setup_t *setup ); + +int cal_ni_at_mio_16e_2(calibration_setup_t *setup); +int cal_ni_daqcard_ai_16xe_50(calibration_setup_t *setup); +int cal_ni_at_mio_16e_1(calibration_setup_t *setup); +int cal_ni_pci_mio_16e_1(calibration_setup_t *setup); +int cal_ni_pci_6025e(calibration_setup_t *setup); +int cal_ni_pci_6035e(calibration_setup_t *setup); +int cal_ni_pci_6071e(calibration_setup_t *setup); +int cal_ni_pxi_6071e(calibration_setup_t *setup); +int cal_ni_at_mio_16e_10(calibration_setup_t *setup); +int cal_ni_pci_mio_16xe_50(calibration_setup_t *setup); +int cal_ni_pci_6023e(calibration_setup_t *setup); +int cal_ni_pci_6024e(calibration_setup_t *setup); +int cal_ni_at_mio_16xe_50(calibration_setup_t *setup); +int cal_ni_pci_mio_16xe_10(calibration_setup_t *setup); +int cal_ni_pci_6052e(calibration_setup_t *setup); static struct board_struct boards[]={ { "at-mio-16e-2", STATUS_DONE, cal_ni_at_mio_16e_2 }, @@ -117,20 +117,16 @@ enum { ni_ao1_reference, }; -int ni_setup( calibration_setup *setup , const char *device_name ) +int ni_setup( calibration_setup_t *setup , const char *device_name ) { ni_setup_board( setup, device_name ); - setup->observables = observables; - setup->n_observables = n_observables; - setup->caldacs = caldacs; - setup->n_caldacs = n_caldacs; - ni_setup_observables(); - setup_caldacs(); + ni_setup_observables( setup ); + setup_caldacs( setup, caldac_subdev ); return 0; } -int ni_setup_board( calibration_setup *setup, const char *device_name ) +int ni_setup_board( calibration_setup_t *setup, const char *device_name ) { int i; @@ -144,7 +140,7 @@ int ni_setup_board( calibration_setup *setup, const char *device_name ) return 0; } -void ni_setup_observables(void) +void ni_setup_observables( calibration_setup_t *setup ) { comedi_insn tmpl; int bipolar_lowgain; @@ -153,9 +149,9 @@ void ni_setup_observables(void) double voltage_reference; observable *o; - bipolar_lowgain = get_bipolar_lowgain(dev,ad_subdev); - bipolar_highgain = get_bipolar_highgain(dev,ad_subdev); - unipolar_lowgain = get_unipolar_lowgain(dev,ad_subdev); + bipolar_lowgain = get_bipolar_lowgain( setup->dev, ad_subdev); + bipolar_highgain = get_bipolar_highgain( setup->dev, ad_subdev); + unipolar_lowgain = get_unipolar_lowgain( setup->dev, ad_subdev); voltage_reference = 5.000; @@ -165,31 +161,31 @@ void ni_setup_observables(void) tmpl.subdev = ad_subdev; /* 0 offset, low gain */ - o = observables + ni_zero_offset_low; + o = setup->observables + ni_zero_offset_low; o->name = "ai, bipolar zero offset, low gain"; o->observe_insn = tmpl; o->observe_insn.chanspec = CR_PACK(0,bipolar_lowgain,AREF_OTHER); o->target = 0; /* 0 offset, high gain */ - o = observables + ni_zero_offset_high; + o = setup->observables + ni_zero_offset_high; o->name = "ai, bipolar zero offset, high gain"; o->observe_insn = tmpl; o->observe_insn.chanspec = CR_PACK(0,bipolar_highgain,AREF_OTHER); o->target = 0; /* voltage reference */ - o = observables + ni_reference_low; + o = setup->observables + ni_reference_low; o->name = "ai, bipolar voltage reference, low gain"; o->observe_insn = tmpl; o->observe_insn.chanspec = CR_PACK(5,bipolar_lowgain,AREF_OTHER); o->target = voltage_reference; - n_observables = ni_reference_low + 1; + setup->n_observables = ni_reference_low + 1; if(unipolar_lowgain>=0){ /* unip/bip offset */ - o = observables + ni_unip_offset_low; + o = setup->observables + ni_unip_offset_low; o->name = "ai, unipolar zero offset, low gain"; o->observe_insn = tmpl; o->observe_insn.chanspec = @@ -206,7 +202,7 @@ void ni_setup_observables(void) o->target = voltage_reference; i++; #endif - n_observables = ni_unip_offset_low + 1; + setup->n_observables = ni_unip_offset_low + 1; } if(da_subdev>=0){ @@ -218,7 +214,7 @@ void ni_setup_observables(void) po_tmpl.subdev = da_subdev; /* ao 0, zero offset */ - o = observables + ni_ao0_zero_offset; + o = setup->observables + ni_ao0_zero_offset; o->name = "ao 0, zero offset, low gain"; o->preobserve_insn = po_tmpl; o->preobserve_insn.chanspec = CR_PACK(0,0,0); @@ -226,10 +222,10 @@ void ni_setup_observables(void) o->observe_insn = tmpl; o->observe_insn.chanspec = CR_PACK(2,bipolar_lowgain,AREF_OTHER); - set_target(ni_ao0_zero_offset,0.0); + set_target( setup, ni_ao0_zero_offset,0.0); /* ao 0, gain */ - o = observables + ni_ao0_reference; + o = setup->observables + ni_ao0_reference; o->name = "ao 0, reference voltage, low gain"; o->preobserve_insn = po_tmpl; o->preobserve_insn.chanspec = CR_PACK(0,0,0); @@ -237,11 +233,11 @@ void ni_setup_observables(void) o->observe_insn = tmpl; o->observe_insn.chanspec = CR_PACK(6,bipolar_lowgain,AREF_OTHER); - set_target(ni_ao0_reference,5.0); + set_target( setup, ni_ao0_reference,5.0); o->target -= voltage_reference; /* ao 1, zero offset */ - o = observables + ni_ao1_zero_offset; + o = setup->observables + ni_ao1_zero_offset; o->name = "ao 1, zero offset, low gain"; o->preobserve_insn = po_tmpl; o->preobserve_insn.chanspec = CR_PACK(1,0,0); @@ -249,10 +245,10 @@ void ni_setup_observables(void) o->observe_insn = tmpl; o->observe_insn.chanspec = CR_PACK(3,bipolar_lowgain,AREF_OTHER); - set_target(ni_ao1_zero_offset,0.0); + set_target( setup, ni_ao1_zero_offset,0.0); /* ao 1, gain */ - o = observables + ni_ao1_reference; + o = setup->observables + ni_ao1_reference; o->name = "ao 1, reference voltage, low gain"; o->preobserve_insn = po_tmpl; o->preobserve_insn.chanspec = CR_PACK(1,0,0); @@ -260,24 +256,24 @@ void ni_setup_observables(void) o->observe_insn = tmpl; o->observe_insn.chanspec = CR_PACK(7,bipolar_lowgain,AREF_OTHER); - set_target(ni_ao1_reference,5.0); + set_target( setup, ni_ao1_reference,5.0); o->target -= voltage_reference; - n_observables = ni_ao1_reference + 1; + setup->n_observables = ni_ao1_reference + 1; } } -int cal_ni_at_mio_16e_2(calibration_setup *setup) +int cal_ni_at_mio_16e_2(calibration_setup_t *setup) { - postgain_cal(ni_zero_offset_low,ni_zero_offset_high,1); - cal1(ni_zero_offset_high,0); - cal1(ni_reference_low,3); - cal1(ni_unip_offset_low,2); + 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); if(do_output){ - cal1(ni_ao0_zero_offset,5); - cal1(ni_ao0_reference,6); - cal1(ni_ao1_zero_offset,8); - cal1(ni_ao1_reference,9); + cal1( setup, ni_ao0_zero_offset,5); + cal1( setup, ni_ao0_reference,6); + cal1( setup, ni_ao1_zero_offset,8); + cal1( setup, ni_ao1_reference,9); } return 0; } @@ -308,208 +304,197 @@ int cal_ni_at_mio_16e_2(calibration_setup *setup) * caldac[2] gain=7.8670(11)e-5 V/bit S_min=903.291 dof=254 * caldac[8] gain=2.7732(74)e-7 V/bit S_min=415.399 dof=254 */ -int cal_ni_daqcard_ai_16xe_50(calibration_setup *setup) +int cal_ni_daqcard_ai_16xe_50(calibration_setup_t *setup) { - postgain_cal(ni_zero_offset_low,ni_zero_offset_high,2); - cal1(ni_zero_offset_high,8); - cal1(ni_reference_low,0); - cal1_fine(ni_reference_low,0); - cal1(ni_reference_low,1); + postgain_cal( setup, ni_zero_offset_low,ni_zero_offset_high,2); + cal1( setup, ni_zero_offset_high,8); + cal1( setup, ni_reference_low,0); + cal1_fine( setup, ni_reference_low,0); + cal1( setup, ni_reference_low,1); return 0; } -int cal_ni_at_mio_16xe_50(calibration_setup *setup) +int cal_ni_at_mio_16xe_50(calibration_setup_t *setup) { - postgain_cal(ni_zero_offset_low,ni_zero_offset_high,2); - cal1(ni_zero_offset_high,8); - cal1(ni_reference_low,0); - cal1_fine(ni_reference_low,0); - cal1(ni_reference_low,1); + postgain_cal( setup, ni_zero_offset_low,ni_zero_offset_high,2); + cal1( setup, ni_zero_offset_high,8); + cal1( setup, ni_reference_low,0); + cal1_fine( setup, ni_reference_low,0); + cal1( setup, ni_reference_low,1); if(do_output){ - cal1(ni_ao0_zero_offset,6); - cal1(ni_ao0_reference,4); - cal1(ni_ao1_zero_offset,7); - cal1(ni_ao1_reference,5); + cal1( setup, ni_ao0_zero_offset,6); + cal1( setup, ni_ao0_reference,4); + cal1( setup, ni_ao1_zero_offset,7); + cal1( setup, ni_ao1_reference,5); } return 0; } -int cal_ni_pci_mio_16xe_10(calibration_setup *setup) +int cal_ni_pci_mio_16xe_10(calibration_setup_t *setup) { - postgain_cal(ni_zero_offset_low, ni_zero_offset_high, 2); - postgain_cal(ni_zero_offset_low, ni_zero_offset_high, 3); - cal1(ni_zero_offset_high, 8); - cal1(ni_reference_low, 0); - cal1(ni_reference_low, 1); + postgain_cal( setup, ni_zero_offset_low, ni_zero_offset_high, 2); + postgain_cal( setup, ni_zero_offset_low, ni_zero_offset_high, 3); + cal1( setup, ni_zero_offset_high, 8); + cal1( setup, ni_reference_low, 0); + cal1( setup, ni_reference_low, 1); if(do_output){ - cal1(ni_ao0_zero_offset,6); - cal1(ni_ao0_reference,4); - cal1(ni_ao1_zero_offset,7); - cal1(ni_ao1_reference,5); + cal1( setup, ni_ao0_zero_offset,6); + cal1( setup, ni_ao0_reference,4); + cal1( setup, ni_ao1_zero_offset,7); + cal1( setup, ni_ao1_reference,5); } return 0; } -int cal_ni_at_mio_16e_1(calibration_setup *setup) +int cal_ni_at_mio_16e_1(calibration_setup_t *setup) { - postgain_cal(ni_zero_offset_low,ni_zero_offset_high,1); - cal1(ni_zero_offset_high,0); - cal1(ni_reference_low,3); - cal1(ni_unip_offset_low,2); - if(do_output){ - cal1(ni_ao0_zero_offset,4); - //cal1(ni_ao0_zero_offset,5); /* nonlinearity? */ - cal1(ni_ao0_reference,6); - cal1(ni_ao1_zero_offset,7); - //cal1(ni_ao0_zero_offset,8); /* nonlinearity? */ - cal1(ni_ao1_reference,9); - } + return cal_ni_at_mio_16e_2( setup ); } -int cal_ni_pci_mio_16e_1(calibration_setup *setup) +int cal_ni_pci_mio_16e_1(calibration_setup_t *setup) { //cal_ni_at_mio_16e_2(); - postgain_cal(ni_zero_offset_low,ni_zero_offset_high,1); - cal1(ni_zero_offset_high,0); - cal1(ni_reference_low,3); - cal1(ni_unip_offset_low,2); + 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); if(do_output){ - cal1(ni_ao0_zero_offset,5); - //cal1(ni_ao0_zero_offset,4); /* linearity? */ - cal1(ni_ao0_reference,6); - cal1(ni_ao1_zero_offset,8); - //cal1(ni_ao1_zero_offset,7); /* linearity? */ - cal1(ni_ao1_reference,9); + cal1( setup, ni_ao0_zero_offset,5); + //cal1( setup, ni_ao0_zero_offset,4); /* linearity? */ + cal1( setup, ni_ao0_reference,6); + cal1( setup, ni_ao1_zero_offset,8); + //cal1( setup, ni_ao1_zero_offset,7); /* linearity? */ + cal1( setup, ni_ao1_reference,9); } return 0; } -int cal_ni_pci_6035e(calibration_setup *setup) +int cal_ni_pci_6035e(calibration_setup_t *setup) { // 6035e (old) - postgain_cal(ni_zero_offset_low,ni_zero_offset_high,1); - cal1(ni_zero_offset_high,0); - cal1(ni_reference_low,3); + 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); if(do_output){ // unknown } return 0; } -int cal_ni_pci_6071e(calibration_setup *setup) +int cal_ni_pci_6071e(calibration_setup_t *setup) { - postgain_cal(ni_zero_offset_low,ni_zero_offset_high,1); - cal1(ni_zero_offset_high,0); - cal1(ni_reference_low,3); - cal1_fine(ni_reference_low,3); + 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_fine( setup, ni_reference_low,3); if(do_output){ - cal1(ni_ao0_zero_offset,5); - //cal1(ni_ao0_zero_offset,4); /* linearity? */ - cal1(ni_ao0_reference,6); /* guess. Doesn't show up correctly in dump */ - cal1(ni_ao1_zero_offset,8); - //cal1(ni_ao1_zero_offset,7); /* linearity? */ - cal1(ni_ao1_reference,9); + cal1( setup, ni_ao0_zero_offset,5); + //cal1( setup, ni_ao0_zero_offset,4); /* linearity? */ + cal1( setup, ni_ao0_reference,6); /* guess. Doesn't show up correctly in dump */ + cal1( setup, ni_ao1_zero_offset,8); + //cal1( setup, ni_ao1_zero_offset,7); /* linearity? */ + cal1( setup, ni_ao1_reference,9); } return 0; } -int cal_ni_pxi_6071e(calibration_setup *setup) +int cal_ni_pxi_6071e(calibration_setup_t *setup) { // 6071e (old) - postgain_cal(ni_zero_offset_low,ni_zero_offset_high,1); - cal1(ni_zero_offset_high,0); - cal1(ni_reference_low,3); + 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); if(do_output){ // unknown } return 0; } -int cal_ni_at_mio_16e_10(calibration_setup *setup) +int cal_ni_at_mio_16e_10(calibration_setup_t *setup) { // 16e-10 (old) - postgain_cal(ni_zero_offset_low,ni_zero_offset_high,1); - cal1(ni_zero_offset_high,10); - cal1(ni_zero_offset_high,0); - cal1(ni_reference_low,3); - cal1(ni_unip_offset_low,2); + postgain_cal( setup, ni_zero_offset_low,ni_zero_offset_high,1); + 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); if(do_output){ - cal1(ni_ao0_zero_offset,5); // guess - cal1(ni_ao0_reference,6); // guess - cal1(ni_ao1_zero_offset,8); // guess - cal1(ni_ao1_reference,9); // guess + cal1( setup, ni_ao0_zero_offset,5); // guess + cal1( setup, ni_ao0_reference,6); // guess + cal1( setup, ni_ao1_zero_offset,8); // guess + cal1( setup, ni_ao1_reference,9); // guess } return 0; } -int cal_ni_pci_mio_16xe_50(calibration_setup *setup) +int cal_ni_pci_mio_16xe_50(calibration_setup_t *setup) { - postgain_cal(ni_zero_offset_low,ni_zero_offset_high,2); - cal1(ni_zero_offset_high,8); - cal1(ni_reference_low,0); - cal1_fine(ni_reference_low,0); - cal1(ni_reference_low,1); + postgain_cal( setup, ni_zero_offset_low,ni_zero_offset_high,2); + cal1( setup, ni_zero_offset_high,8); + cal1( setup, ni_reference_low,0); + cal1_fine( setup, ni_reference_low,0); + cal1( setup, ni_reference_low,1); if(do_output){ - cal1(ni_ao0_zero_offset,6); - cal1(ni_ao0_reference,4); - cal1(ni_ao1_zero_offset,7); - cal1(ni_ao1_reference,5); + cal1( setup, ni_ao0_zero_offset,6); + cal1( setup, ni_ao0_reference,4); + cal1( setup, ni_ao1_zero_offset,7); + cal1( setup, ni_ao1_reference,5); } return 0; } -int cal_ni_pci_6023e(calibration_setup *setup) +int cal_ni_pci_6023e(calibration_setup_t *setup) { /* There seems to be a bug in the driver that doesn't allow * access to caldac 10, and possibly others. */ - postgain_cal(ni_zero_offset_low,ni_zero_offset_high,1); - //cal1(ni_zero_offset_high,10); - //cal1(ni_zero_offset_high,0); - cal1(ni_reference_low,3); + postgain_cal( setup, ni_zero_offset_low,ni_zero_offset_high,1); + //cal1( setup, ni_zero_offset_high,10); + //cal1( setup, ni_zero_offset_high,0); + cal1( setup, ni_reference_low,3); return 0; } -int cal_ni_pci_6024e(calibration_setup *setup) +int cal_ni_pci_6024e(calibration_setup_t *setup) { /* There seems to be a bug in the driver that doesn't allow * access to caldac 10, and possibly others. */ - postgain_cal(ni_zero_offset_low,ni_zero_offset_high,1); - //cal1(ni_zero_offset_high,10); - //cal1(ni_zero_offset_high,0); - cal1(ni_reference_low,3); + postgain_cal( setup, ni_zero_offset_low,ni_zero_offset_high,1); + //cal1( setup, ni_zero_offset_high,10); + //cal1( setup, ni_zero_offset_high,0); + cal1( setup, ni_reference_low,3); if(do_output){ - cal1(ni_ao0_zero_offset,5); - //cal1(ni_ao0_zero_offset,4); // nonlinearity? - //cal1(ni_ao0_reference,6); - cal1(ni_ao1_zero_offset,8); - //cal1(ni_ao1_zero_offset,7); // nonlinearity? - //cal1(ni_ao1_reference,9); + cal1( setup, ni_ao0_zero_offset,5); + //cal1( setup, ni_ao0_zero_offset,4); // nonlinearity? + //cal1( setup, ni_ao0_reference,6); + cal1( setup, ni_ao1_zero_offset,8); + //cal1( setup, ni_ao1_zero_offset,7); // nonlinearity? + //cal1( setup, ni_ao1_reference,9); } return 0; } -int cal_ni_pci_6025e(calibration_setup *setup) +int cal_ni_pci_6025e(calibration_setup_t *setup) { - postgain_cal(ni_zero_offset_low,ni_zero_offset_high,4); // was 1 - //cal1(ni_zero_offset_high,XXX); // was 10 - cal1(ni_zero_offset_high,8); // was 0 - cal1(ni_reference_low,2); // was 3 + postgain_cal( setup, ni_zero_offset_low,ni_zero_offset_high,4); // was 1 + //cal1( setup, ni_zero_offset_high,XXX); // was 10 + cal1( setup, ni_zero_offset_high,8); // was 0 + cal1( setup, ni_reference_low,2); // was 3 if(do_output){ - cal1(ni_ao0_zero_offset,6); // was 5 - //cal1(ni_ao0_zero_offset,10); // nonlinearity was 4 - //cal1(ni_ao0_reference,XXX); // was 6 - cal1(ni_ao1_zero_offset,9); // was 8 - //cal1(ni_ao1_zero_offset,1); // nonlinearity was 7 - cal1(ni_ao1_reference,5); // was 9 + cal1( setup, ni_ao0_zero_offset,6); // was 5 + //cal1( setup, ni_ao0_zero_offset,10); // nonlinearity was 4 + //cal1( setup, ni_ao0_reference,XXX); // was 6 + cal1( setup, ni_ao1_zero_offset,9); // was 8 + //cal1( setup, ni_ao1_zero_offset,1); // nonlinearity was 7 + cal1( setup, ni_ao1_reference,5); // was 9 } return 0; } -int cal_ni_pci_6052e(calibration_setup *setup) +int cal_ni_pci_6052e(calibration_setup_t *setup) { /* * This board has noisy caldacs @@ -545,36 +530,36 @@ int cal_ni_pci_6052e(calibration_setup *setup) * */ - postgain_cal(ni_zero_offset_low,ni_zero_offset_high,2); - postgain_cal(ni_zero_offset_low,ni_zero_offset_high,3); - cal1(ni_zero_offset_high,0); - cal1(ni_zero_offset_high,1); - cal1(ni_reference_low,4); - cal1_fine(ni_reference_low,4); - cal1(ni_reference_low,5); - cal1(ni_unip_offset_low,6); - cal1_fine(ni_unip_offset_low,6); - //cal1(ni_unip_offset_low,7); + postgain_cal( setup, ni_zero_offset_low,ni_zero_offset_high,2); + postgain_cal( setup, ni_zero_offset_low,ni_zero_offset_high,3); + cal1( setup, ni_zero_offset_high,0); + cal1( setup, ni_zero_offset_high,1); + cal1( 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_offset_low,7); if(do_output){ - cal1(ni_ao0_zero_offset,12+11); - cal1(ni_ao0_reference,12+7); - cal1(ni_ao0_reference,12+3); - cal1(ni_ao1_zero_offset,12+1); - cal1(ni_ao1_reference,12+9); - cal1(ni_ao1_reference,12+5); + cal1( setup, ni_ao0_zero_offset,12+11); + cal1( setup, ni_ao0_reference,12+7); + cal1( setup, ni_ao0_reference,12+3); + cal1( setup, ni_ao1_zero_offset,12+1); + cal1( setup, ni_ao1_reference,12+9); + cal1( setup, ni_ao1_reference,12+5); } return 0; } -double ni_get_reference(int lsb_loc,int msb_loc) +double ni_get_reference( calibration_setup_t *setup, int lsb_loc,int msb_loc) { int lsb,msb; int uv; double ref; - lsb=read_eeprom(lsb_loc); - msb=read_eeprom(msb_loc); - printf("lsb=%d msb=%d\n",read_eeprom(425),read_eeprom(426)); + lsb=read_eeprom( setup, lsb_loc); + msb=read_eeprom( setup, msb_loc); + printf("lsb=%d msb=%d\n",read_eeprom( setup, 425),read_eeprom( setup, 426)); uv=lsb | (msb<<8); if(uv>=0x8000)uv-=0x10000;